Awesome Open Source
Awesome Open Source

Notice: This project is still in development, but development frequency is very low currently due to limited time and because I'm working on other projects which have a higher priority.

Example output (rendered in console with Spectre.Console)

Trakt.NET Twitter URL Twitter Follow

Formerly known as TraktApiSharp.

This is a .NET wrapper library for the Trakt.tv API.

Project Status NuGet Package License PRs Welcome

Installation

Install the latest release by running the following NuGet command

PM> Install-Package Trakt.NET

or with the NuGet Package Management in Visual Studio and search for "trakt".

Each release will also be published in Releases.

Features

Full Trakt.tv API Coverage // Authentication Support (OAuth 2.0 and Device) // Completely asynchronous // API Environments (Production and Sandbox) // Serialization Service // Language Service

Supported Platforms

.Net Core >= 1.0 // .Net Framework >= 4.5 // .NET >= 5 // Mono >= 4.6 // Xamarin.iOS >= 10.0 // Xamarin.Mac >= 3.0 // Xamarin.Android >= 7.0 // Windows UWP >= 10.0 // Windows >= 8.0 // Windows Phone >= 8.1


Discussions and Issues

Do you have a question or suggestion? Start a discussion

Or do you want to report a bug? Create an issue

Contributions are welcome

Do want to contribute? See how you can contribute

Documentation

Build Status

Branch Status Description Packages
develop develop-CI This branch tracks the current and possibly unstable development. https://github.com/henrikfroehling/Trakt.NET/packages

Basic Usage

Create a new Trakt.NET Client

// Client ID is sufficient for usage without OAuth
var client = new TraktClient("Your Trakt Client ID");

// Both Client ID and Client Secret are required, if you need to authenticate your application
var client = new TraktClient("Your Trakt Client ID", "Your Trakt Client Secret");

// Both Client ID and Access Token are required, if you want to use requests, that require authorization
var client = new TraktClient("Your Trakt Client ID")
{
    Authorization = TraktAuthorization.CreateWith("Trakt Access Token")
};

Use your existing tokens

var client = new TraktClient("Your Trakt Client ID");

// Only access token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token");

// Access Token and Refresh Token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token", "Your Refresh Token");

Serialize and deserialize authorization information

ITraktAuthorization authorization = client.Authorization;

// Get JSON string from current authorization
string json = await TraktSerializationService.SerializeAsync(authorization);

// Get TraktAuthorization from JSON string
ITraktAuthorization deserializedAuthorization = await TraktSerializationService.DeserializeAsync(json);

client.Authorization = deserializedAuthorization;

// authorization == deserializedAuthorization

Configure the client

client.ClientId = "Your Trakt Client ID";
client.ClientSecret = "Your Trakt Client Secret";

client.Configuration.ApiVersion = 2; // Set by default

// Set this to true, to use Trakt API staging environment
// This is disabled by default
client.Configuration.UseSandboxEnvironment = true;

// Force authorization for requests, where authorization is optional
// This is disabled by default
client.Configuration.ForceAuthorization = true;

Get the top 10 trending shows including full information

TraktPagedResponse<ITraktTrendingShow> trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo().SetFull(), null, 10);
// or
TraktPagedResponse<ITraktTrendingShow> trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo() { Full = true }, 1, 10);

if (trendingShowsTop10)
{
    foreach (ITraktTrendingShow trendingShow in trendingShowsTop10)
    {
        Console.WriteLine($"Show: {trendingShow.Title} / Watchers: {trendingShow.Watchers}");
    }
}

Example output (rendered in console with Spectre.Console)


Get the top 10 trending movies including full information

var extendedInfo = new TraktExtendedInfo() { Full = true };

TraktPagedResponse<ITraktTrendingMovie> trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, null, 10);
// or
TraktPagedResponse<ITraktTrendingMovie> trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, 1, 10);

if (trendingMoviesTop10)
{
    foreach (ITraktTrendingMovie trendingMovie in trendingMoviesTop10)
    {
        Console.WriteLine($"Movie: {trendingMovie.Title} / Watchers: {trendingMovie.Watchers}");
    }
}

Example output (rendered in console with Spectre.Console)


Get the show 'Game of Thrones'

TraktResponse<ITraktShow> gameOfThrones = await client.Shows.GetShowAsync("game-of-thrones", new TraktExtendedInfo().SetFull());

if (gameOfThrones)
{
    ITraktShow show = gameOfThrones.Value;
    Console.WriteLine($"Title: {show.Title} / Year: {show.Year}");
    Console.WriteLine(show.Overview);
}

Get the movie 'The Martian'

TraktResponse<ITraktMovie> theMartian = await client.Movies.GetMovieAsync("the-martian-2015", new TraktExtendedInfo().SetFull());

if (theMartian)
{
    ITraktMovie movie = theMartian.Value;
    Console.WriteLine($"Title: {movie.Title} / Year: {movie.Year}");
    Console.WriteLine(show.Overview);
}

License

The MIT License (MIT)

Copyright  2016 - 2021 Henrik Frhling et al.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Sharp (279,248
Api (22,255
Rest (4,145
Asp Net Core (3,722
Netcore (1,560
Windows 10 (1,398
Nuget (1,042
Xamarin Android (470
Tv (437
Xamarin Ios (330
Netframework (316
Related Projects