Trakt.py v4.4.0 – Project Cheat Sheet

This reference is based on the module structure developed in your project:
main.py
 ├─ setup_trakt()
 ├─ authenticate()
 ├─ search_show()
 ├─ get_show_progress()
 ├─ fetch_recent_history()
 └─ print_show_progress()
Every example below is written in the context of your project.

setup_trakt()

Purpose: Configure the Trakt client using your Client ID, Client Secret and token file.

authenticate()

Returns: Authenticated session ready for all later API calls.

fetch_recent_history(days)

response = Trakt["users/me/history"].get(
    "episodes",
    page=page,
    per_page=100,
    start_at=one_day_ago,
    parse=False
)

history = response.json()

Returns: A list of history dictionaries.

FieldDescription
show.titleTV show name
episode.seasonSeason number
episode.numberEpisode number
episode.titleEpisode title
watched_atDate watched

search_show(name)

show = search_show("One Punch Man")
show_id = show["ids"]["trakt"]

Returns: Dictionary containing full show metadata.

Trakt["shows"].progress_watched(show_id)

progress = get_show_progress(show_id)

Returns: WatchedProgress object (NOT a dictionary).

# Available members discovered during debugging

progress.aired
# Total aired episodes

progress.completed
# Number completed

progress.seasons
# Dictionary:
# {
#     1 : SeasonProgress,
#     2 : SeasonProgress,
# }

progress.last_episode
# Last watched episode object

progress.next_episode
# Next episode object (buggy in v4.4.0 when None)

# DO NOT call progress.to_dict()
# Some shows crash because of a library bug.

Season Loop

for season_number, season in progress.seasons.items():

    print(f"Season {season_number}: "
          f"{season.completed}/{season.aired}")

Reason: progress.seasons is a dictionary, so use .items().

Episode Loop

for episode_number, episode in season.episodes.items():

    status = "✓" if episode.completed else "✗"

    print(f"{status} Episode {episode_number}")

EpisodeProgress contains only:

episode.completed
episode.pk
episode.progress_timestamp
episode.progress_type

# No title
# No overview
# No runtime

Useful Introspection

type(obj)          # Object type

dir(obj)           # Methods & attributes

vars(obj)          # Attribute dictionary

help(Trakt["shows"].progress_watched)
# Shows method signature:
# progress_watched(id, hidden=False, specials=False,...)

help(Trakt["shows"].season)
# Returns a single season with episode metadata.

help(Trakt["shows"].seasons)
# Returns all seasons for a show.

Known v4.4.0 Bugs Found

Future Features