All Projects → vankasteelj → Trakt.tv

vankasteelj / Trakt.tv

A Trakt.tv API wrapper for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Trakt.tv

plaxt
Webhooks based Trakt.tv scrobbling for Plex
Stars: ✭ 20 (-81.98%)
Mutual labels:  trakt
Traktforvlc
Automatically trakt.tv what you're watching on VLC
Stars: ✭ 292 (+163.06%)
Mutual labels:  trakt
Nakamori
Nakamori is Kodi addon that use Shoko (known as Japanese Media Manager (JMM)) Server as back-end for metadata information.
Stars: ✭ 24 (-78.38%)
Mutual labels:  trakt
jellyfin-plugin-trakt
jellyfin.org
Stars: ✭ 69 (-37.84%)
Mutual labels:  trakt
movie-box
📺 Get your last watched movies and shows (+more) report from trakt.tv in a GitHub Gist.
Stars: ✭ 13 (-88.29%)
Mutual labels:  trakt
Tivi
Tivi is a work-in-progress TV show tracking Android app, which connects to Trakt.tv. It is still in its early stages of development and currently only contains two pieces of UI. It is under heavy development.
Stars: ✭ 4,696 (+4130.63%)
Mutual labels:  trakt
pachinko
modular pluggable media sorter
Stars: ✭ 27 (-75.68%)
Mutual labels:  trakt
Listrr
listrr.pro creates and maintains lists on trakt.tv completely automated based on your filters.
Stars: ✭ 77 (-30.63%)
Mutual labels:  trakt
tRakt-shiny
Using trakt to graph show data and such. The on-it's-way-out incarnation of trakt.jemu.name
Stars: ✭ 17 (-84.68%)
Mutual labels:  trakt
Trakt Tools
Command-line tools for Trakt.tv.
Stars: ✭ 16 (-85.59%)
Mutual labels:  trakt
Trakt-Userscripts
Userscripts to improve and add features to Trakt.tv
Stars: ✭ 39 (-64.86%)
Mutual labels:  trakt
Trakt2Letterboxd
Script to export your movies from Trakt to Letterboxd
Stars: ✭ 27 (-75.68%)
Mutual labels:  trakt
Sickgear
SickGear has proven the most reliable stable TV fork of the great Sick-Beard to fully automate TV enjoyment with innovation.
Stars: ✭ 452 (+307.21%)
Mutual labels:  trakt
trakttvstats
A chrome extension adding various improvements to trakt.tv
Stars: ✭ 23 (-79.28%)
Mutual labels:  trakt
Duckietv
A web application built with AngularJS to track your favorite tv-shows with semi-automagic torrent integration
Stars: ✭ 942 (+748.65%)
Mutual labels:  trakt
movie-api
[DEPRECATED] 🎬 Get info for movies and TV shows
Stars: ✭ 32 (-71.17%)
Mutual labels:  trakt
Traktflix
Trakt.tv + Netflix = ❤️
Stars: ✭ 331 (+198.2%)
Mutual labels:  trakt
Medusa
Automatic Video Library Manager for TV Shows. It watches for new episodes of your favorite shows, and when they are posted it does its magic.
Stars: ✭ 1,268 (+1042.34%)
Mutual labels:  trakt
Trakt Letterboxd Import
Import Letterboxd movie list (diary) into trakt.tv
Stars: ✭ 29 (-73.87%)
Mutual labels:  trakt
Popcorn Api
Popcorn Time is a multi-platform, free software BitTorrent client that includes an integrated media player. Compatible API Anime/Movies/Show Scrapper
Stars: ✭ 529 (+376.58%)
Mutual labels:  trakt

trakt.tv

Trakt.tv API wrapper for Node.js, featuring:

  • All Trakt.tv API v2 methods
  • Promises
  • Forget JSON: use Objects, Arrays and Strings directly
  • Enhanced protection against: CSRF (session riding) and XSS (content spoofing) attacks, using Crypto and Sanitizer
  • Plugin extension

For more information about the trakt.tv API, read http://docs.trakt.apiary.io/

Example usage

Setup

npm install trakt.tv

Initialize

const Trakt = require('trakt.tv');

let options = {
  client_id: <the_client_id>,
  client_secret: <the_client_secret>,
  redirect_uri: null,   // defaults to 'urn:ietf:wg:oauth:2.0:oob'
  api_url: null,        // defaults to 'https://api.trakt.tv'
  useragent: null,      // defaults to 'trakt.tv/<version>'
  pagination: true      // defaults to false, global pagination (see below)
};
const trakt = new Trakt(options);

Add debug: true to the options object to get debug logs of the requests executed in your console.

OAUTH

  1. Generate Auth URL
const traktAuthUrl = trakt.get_url();
  1. Authentication is done at that URL, it redirects to the provided uri with a code and a state

  2. Verify code (and optionally state for better security) from returned auth, and get a token in exchange

trakt.exchange_code('code', 'csrf token (state)').then(result => {
    // contains tokens & session information
    // API can now be used with authorized requests
});

Alternate OAUTH "device" method

trakt.get_codes().then(poll => {
    // poll.verification_url: url to visit in a browser
    // poll.user_code: the code the user needs to enter on trakt

    // verify if app was authorized
    return trakt.poll_access(poll);
}).catch(error => {
    // error.message == 'Expired' will be thrown if timeout is reached
});

Refresh token

trakt.refresh_token().then(results => {
    // results are auto-injected in the main module cache
});

Storing token over sessions

// get token, store it safely.
const token = trakt.export_token();

// injects back stored token on new session.
trakt.import_token(token).then(newTokens => {
    // Contains token, refreshed if needed (store it back)
});

Revoke token

trakt.revoke_token();

Actual API requests

See methods in methods.json or the docs.

trakt.calendars.all.shows({
    start_date: '2015-11-13',
    days: '7',
    extended: 'full'
}).then(shows => {
    // Contains Object{} response from API (show data)
});
trakt.search.text({
    query: 'tron',
    type: 'movie,person'
}).then(response => {
    // Contains Array[] response from API (search data)
});
trakt.search.id({
    id_type: 'imdb',
    id: 'tt0084827'
}).then(response => {
    // Contains Array[] response from API (imdb data)
});

Using pagination

You can extend your calls with pagination: true to get the extra pagination info from headers.

trakt.movies.popular({
    pagination: true
}).then(movies => {
    /**
    movies = Object {
        data: [<actual data from API>],
        pagination: {
            item-count: "80349",
            limit: "10",
            page: "1",
            page-count: "8035"
        }
    }
    **/
});

Note: this will contain data and pagination for all calls, even if no pagination is available (result.pagination will be false). it's typically for advanced use only

Load plugins

When calling new Trakt(), include desired plugins in an object (must be installed from npm):

const trakt = new Trakt({
    client_id: <the_client_id>,
    client_secret: <the_client_secret>,
    plugins: {  // load plugins
        images: require('trakt.tv-images')
    }
    options: {  // pass options to plugins
        images: {
            smallerImages: true
        }
    }
});

The plugin can be accessed with the key you specify. For example trakt.images.get().

Write plugins

See the documentation.

Notes

  • You can use 'me' as username if the user is authenticated.
  • Timestamps (such as token expires property) are Epoch in milliseconds.

LICENSE

The MIT License (MIT) - author: Jean van Kasteel [email protected]

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].