/trakt.py

Python interface for the Trakt.tv API

Primary LanguagePythonMIT LicenseMIT

trakt.py

https://img.shields.io/pypi/v/trakt.py.svg?style=flat-square https://img.shields.io/codeclimate/github/fuzeman/trakt.py.svg?style=flat-square https://img.shields.io/coveralls/fuzeman/trakt.py.svg?style=flat-square

Python interface for the Trakt.tv API.

Install

pip install trakt.py

Examples

Configure the client

from trakt import Trakt


Trakt.configuration.defaults.client(
    id='<client-id>',
    secret='<client-secret>'
)

Scrobble an episode

show = {
    'title': 'Community',
    'year': 2009
}

episode = {
    'season': 5,
    'number': 13
}

# Send "start" event
Trakt['scrobble'].start(
    show=show,
    episode=episode,

    progress=1
)

# [...] (watching episode)

# Send "stop" event (scrobble)
Trakt['scrobble'].stop(
    show=show,
    episode=episode,

    progress=93
)

Add a movie to your collection

Trakt['sync/collection'].add({
    'movies': [
        {
            'title': "Twelve Monkeys",
            'year': 1995,

            'ids': {
                'imdb': "tt0114746"
            }
        }
    ]
})

Retrieve shows that a user has watched

# `watched` = {<key>: <Show>} dictionary
watched = Trakt['sync/watched'].movies()

for key, show in watched.items():
    print '%s (%s)' % (show.title, show.year)

Trakt API support

Trakt endpoint method trakt.py interface
calendars/my/shows GET Trakt['calendars/my/shows'].get()
calendars/my/shows/new GET Trakt['calendars/my/shows'].new()
calendars/my/shows/premieres GET Trakt['calendars/my/shows'].premieres()
calendars/my/movies GET Trakt['calendars/my/movies'].get()
calendars/my/dvd GET Trakt['calendars/my/dvd'].get()
calendars/all/shows GET Trakt['calendars/all/shows'].get()
calendars/all/shows/new GET Trakt['calendars/all/shows'].new()
calendars/all/shows/premiers GET Trakt['calendars/all/shows'].premiers()
calendars/all/movies GET Trakt['calendars/all/movies'].get()
calendars/all/dvd GET Trakt['calendars/all/dvd'].get()
checkin POST  
certifications/<type> GET  
comments POST  
comments/<id> GET  
comments/<id> (update) PUT  
comments/<id> (remove) DELETE  
comments/<id>/replies GET  
comments/<id>/replies (add) POST  
comments/<id>/item GET  
comments/<id>/likes GET  
comments/<id>/like POST  
comments/<id>/like (remove) DELETE  
comments/trending/<comment_type>/<type> GET  
comments/recent/<comment_type>/<type> GET  
comments/updates/<comment_type>/<type> GET  
countries/<type> GET  
genres/<type> GET  
languages/<type> GET  
lists/trending GET Trakt['lists'].trending()
lists/popular GET Trakt['lists'].popular()
lists/<id> GET  
lists/<id>/likes GET  
lists/<id>/items GET  
lists/<id>/comments GET  
movies/trending GET Trakt['movies'].trending()
movies/popular GET Trakt['movies'].popular()
movies/recommended GET Trakt['movies'].recommended()
movies/played GET  
movies/watched GET  
movies/collected GET  
movies/anticipated GET  
movies/boxoffice GET  
movies/updates GET  
movies/updates/id GET  
movies/id GET Trakt['movies'].get()
movies/id/aliases GET  
movies/id/releases GET  
movies/id/translations GET  
movies/id/comments GET  
movies/id/lists GET  
movies/id/people GET  
movies/id/ratings GET  
movies/id/related GET  
movies/id/stats GET  
movies/id/studios GET  
movies/id/watching GET  
networks GET  
people/updates GET  
people/updates/id GET  
people/<id> GET  
people/<id>/movies GET  
people/<id>/shows GET  
people/<id>/lists GET  
recommendations/movies GET  
recommendations/movies/<id> DELETE  
recommendations/shows GET  
recommendations/shows/<id> DELETE  
scrobble/start POST Trakt['scrobble'].start()
scrobble/pause POST Trakt['scrobble'].pause()
scrobble/stop POST Trakt['scrobble'].stop()
search/<type> GET Trakt['search'].query()
search/<id_type>/<id> GET Trakt['search'].lookup()
shows/trending GET Trakt['shows'].trending()
shows/popular GET Trakt['shows'].popular()
shows/recommended GET Trakt['shows'].recommended()
shows/played GET  
shows/watched GET  
shows/collected GET  
shows/anticipated GET  
shows/updates GET  
shows/updates/id GET  
shows/<id> GET Trakt['shows'].get()
shows/<id>/aliases GET  
shows/<id>/certifications GET  
shows/<id>/translations GET  
shows/<id>/comments GET  
shows/<id>/lists GET  
shows/<id>/progress/collection GET Trakt['shows'].progress_collection()
shows/<id>/progress/watched GET Trakt['shows'].progress_watched()
shows/<id>/progress/watched/reset GET  
shows/<id>/progress/watched/reset (undo) DELETE  
shows/<id>/people GET  
shows/<id>/ratings GET  
shows/<id>/related GET  
shows/<id>/stats GET  
shows/<id>/studios GET  
shows/<id>/watching GET  
shows/<id>/next_episode GET Trakt['shows'].next_episode()
shows/<id>/last_episode GET Trakt['shows'].last_episode()
shows/<id>/seasons GET Trakt['shows'].seasons()
shows/<id>/seasons/<season> GET Trakt['shows'].season()
shows/<id>/seasons/<season>/translations GET  
shows/<id>/seasons/<season>/comments GET  
shows/<id>/seasons/<season>/lists GET  
shows/<id>/seasons/<season>/people GET  
shows/<id>/seasons/<season>/ratings GET  
shows/<id>/seasons/<season>/stats GET  
shows/<id>/seasons/<season>/watching GET  
shows/<id>/seasons/<season>/episodes/episode GET Trakt['shows'].episode()
shows/<id>/seasons/<season>/episodes/<episode>/translations GET  
shows/<id>/seasons/<season>/episodes/<episode>/comments GET  
shows/<id>/seasons/<season>/episodes/<episode>/lists GET  
shows/<id>/seasons/<season>/episodes/<episode>/people GET  
shows/<id>/seasons/<season>/episodes/<episode>/ratings GET  
shows/<id>/seasons/<season>/episodes/<episode>/stats GET  
shows/<id>/seasons/<season>/episodes/<episode>/watching GET  
sync/last_activities GET Trakt['sync'].last_activities()
sync/playback GET Trakt['sync/playback'].get()
sync/playback/<id> DELETE Trakt['sync/playback'].delete()
sync/collection/<type> GET Trakt['sync/collection'].movies(), Trakt['sync/collection'].shows()
sync/collection POST Trakt['sync/collection'].add()
sync/collection/remove POST Trakt['sync/collection'].remove()
sync/watched/<type> GET Trakt['sync/watched'].movies(), Trakt['sync/watched'].shows()
sync/history GET Trakt['sync/history'].episodes(), Trakt['sync/history'].movies(), Trakt['sync/history'].seasons(), Trakt['sync/history'].shows()
sync/history (add) POST Trakt['sync/history'].add()
sync/history/remove POST Trakt['sync/history'].remove()
sync/ratings GET Trakt['sync/ratings'].add(), Trakt['sync/ratings'].episodes(), Trakt['sync/ratings'].movies(), Trakt['sync/ratings'].seasons(), Trakt['sync/ratings'].shows()
sync/ratings (add) POST Trakt['sync/ratings'].add()
sync/ratings/remove POST Trakt['sync/ratings'].remove()
sync/watchlist GET Trakt['sync/watchlist'].episodes(), Trakt['sync/watchlist'].movies(), Trakt['sync/watchlist'].seasons(), Trakt['sync/watchlist'].shows()
sync/watchlist (add) POST Trakt['sync/watchlist'].add()
sync/watchlist/remove POST Trakt['sync/watchlist'].remove()
sync/watchlist/reorder POST  
sync/recommendations GET  
sync/recommendations (add) POST  
sync/recommendations/remove POST  
sync/recommendations/reorder POST  
users/settings GET Trakt['users/settings'].get()
users/requests/following GET  
users/requests GET  
users/requests/<id> (approve) POST  
users/requests/<id> (deny) DELETE  
users/saved_filters GET  
users/hidden/<section> GET Trakt['users/hidden/<section>'].get()
users/hidden/<section> (add) POST Trakt['users/hidden/<section>'].add()
hidden/<section>/remove POST Trakt['users/hidden/<section>'].remove()
users/<id> GET Trakt['users/<id>'].profile()
users/<id>/likes GET Trakt['users'].likes() (only for logged-in user)
users/<id>/collection GET  
users/<id>/comments GET  
users/<id>/lists GET Trakt['users/<id>/lists'].get()
users/<id>/lists (create) POST Trakt['users/<id>/lists'].create()
users/<id>/lists/reorder POST  
users/<id>/lists/collaborations GET  
users/<id>/lists/<list_id> GET Trakt['users/<id>/lists/<list_id>'].get()
users/<id>/lists/<list_id> (update) PUT Trakt['users/<id>/lists/<list_id>'].update()
users/<id>/lists/<list_id> (delete) DELETE Trakt['users/<id>/lists/<list_id>'].delete()
users/<id>/lists/<list_id>/likes GET  
users/<id>/lists/<list_id>/like POST Trakt['users/<id>/lists/<list_id>'].like()
users/<id>/lists/<list_id>/like (unlike) DELETE Trakt['users/<id>/lists/<list_id>'].unlike()
users/<id>/lists/<list_id>/items GET Trakt['users/<id>/lists/<list_id>'].items()
users/<id>/lists/<list_id>/items (add) POST Trakt['users/<id>/lists/<list_id>'].add()
users/<id>/lists/<list_id>/items/remove POST Trakt['users/<id>/lists/<list_id>'].remove()
users/<id>/lists/<list_id>/items/reorder POST  
users/<id>/lists/<list_id>/comments GET  
users/<id>/follow POST Trakt['user/<id>'].follow()
users/<id>/follow (unfollow) DELETE Trakt['user/<id>'].unfollow()
users/<id>/followers GET  
users/<id>/following GET Trakt['users/<id>/following'].get()
users/<id>/friends GET Trakt['users/<id>/friends'].get()
users/<id>/history GET Trakt['users/<id>/history'].get(), Trakt['users/<id>/history'].movies(), Trakt['users/<id>/history'].seasons(), Trakt['users/<id>/history'].shows(), Trakt['users/<id>/history'].episodes()
users/<id>/ratings GET Trakt['users/<id>/ratings'].get(), Trakt['users/<id>/ratings'].all(), Trakt['users/<id>/ratings'].movies(), Trakt['users/<id>/ratings'].shows(), Trakt['users/<id>/ratings'].seasons(), Trakt['users/<id>/ratings'].episodes()
users/<id>/watchlist GET Trakt['users/<id>/watchlist'].get(), Trakt['users/<id>/watchlist'].movies(), Trakt['users/<id>/watchlist'].shows(), Trakt['users/<id>/watchlist'].seasons(), Trakt['users/<id>/watchlist'].episodes()
users/<id>/recommendations GET  
users/<id>/watching GET  
users/<id>/watched/<type> GET Trakt['users/<id>/watched'].get(), Trakt['users/<id>/watched'].movies(), Trakt['users/<id>/watched'].shows()
users/<id>/stats GET  

License

The MIT License (MIT)

Copyright (c) 2014 Dean Gardiner

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.