Skip to content

Request extended=progress and paginate the watched/collected getters#714

Merged
razzeee merged 1 commit into
razzeee:mainfrom
yitzhaq:fix-watched-episode-pull
Jul 14, 2026
Merged

Request extended=progress and paginate the watched/collected getters#714
razzeee merged 1 commit into
razzeee:mainfrom
yitzhaq:fix-watched-episode-pull

Conversation

@yitzhaq

@yitzhaq yitzhaq commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

Trakt's 2026 API change (enforced after 2026-06-30) broke the Trakt→Kodi watched-status pull: /sync/watched/shows no longer returns the season/episode breakdown unless extended=progress is sent, and all /sync endpoints are now force-paginated (100/page default).

The new REST client added _get_all_pages, but getShowsWatched calls a bare _get with no extended=progress (→ episode watched-state can't sync, #713), and getShowsWatched/getShowsCollected/getMoviesWatched don't page (→ silently truncated to the first 100 items).

Change

  • getShowsWatched: send extended=progress and page via _get_all_pages.
  • getShowsCollected, getMoviesWatched: route through _get_all_pages.
  • _get_all_pages: accept optional extra query params (merged per page).
  • Tests for the above.

Verification (live account, /sync/watched/shows page 1)

extended=progress shows w/ seasons episodes page-count
off 100 0 0 5
on 100 100 1235 5

extended=progress restores the breakdown; page-count=5 confirms pagination is required.

Note: rebased onto the REST-client rewrite (supersedes the earlier version of this PR, which targeted the pre-rewrite traktapi.py). Refs #713. Heads-up: on current main, a sync still can't complete end-to-end due to a separate object-contract regression (unrelated to pagination) — reported in #715. This PR fixes the pagination/extended half.

🤖 Generated with Claude Code

@yitzhaq yitzhaq force-pushed the fix-watched-episode-pull branch from b4998ef to b566d2c Compare July 9, 2026 12:34
@razzeee

razzeee commented Jul 10, 2026

Copy link
Copy Markdown
Owner

I've updated main in the mean time, still needs testing, before it can be released

@Zipster79

Copy link
Copy Markdown

Tested the updated main with my kodi but I just get 'Cannot connect to Trakt' when I try to reauthorize it

2026-07-10 16:22:41.369 T:8144 info : start trakt with arguments: {'action': 'auth_info'}
2026-07-10 16:23:29.755 T:14268 info : start trakt with arguments: {'action': 'auth_info'}

Trakt's 2026 API change (enforced after 2026-06-30) stopped returning the
season/episode breakdown from /sync/watched/shows unless extended=progress
is sent, and force-paginated all sync endpoints. The new REST client added
a pagination helper (_get_all_pages) but getShowsWatched neither requested
extended=progress nor paged, so episode watched-state cannot sync; and
getShowsCollected/getMoviesWatched still used a single _get, silently
truncating to the first 100 items.

- getShowsWatched: request extended=progress (restores the episode
  breakdown) and page through results via _get_all_pages.
- getShowsCollected, getMoviesWatched: route through _get_all_pages.
- _get_all_pages: accept optional extra query params (merged per page).
- tests: extended=progress + pagination on the getters, and the
  params-merge in _get_all_pages.

Verified against a live account: /sync/watched/shows returns 0 episodes
without extended=progress and the full season/episode breakdown with it;
X-Pagination-Page-Count > 1 confirms pagination is required.

Refs #713

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yitzhaq yitzhaq force-pushed the fix-watched-episode-pull branch from b566d2c to 2d2d3cb Compare July 10, 2026 18:29
@yitzhaq yitzhaq changed the title Fix dead episode watched-pull and sync truncation after Trakt API change Request extended=progress and paginate the watched/collected getters Jul 10, 2026
@yitzhaq

yitzhaq commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Two heads-ups for anyone testing main right now:

  1. "Can not connect to Trakt" from source (as @Zipster79 hit): the client keys in the repo are placeholders, only injected into a real build on a tagged release via scripts/inject_keys.py. Running main straight from git → deobfuscate() gets a string and returns "" → empty API key → the device-code call is rejected. Not an auth-logic bug; a release build authenticates fine.
  2. Even with real keys, a sync can't complete yet on main — it aborts with KeyError: 'watched' before episodes are reached (separate from this PR; filed as REST-client rewrite: sync aborts with KeyError: 'watched' (object contract not populated) #715). So the rewrite won't sync at present regardless of this PR.

This PR (now rebased onto the REST rewrite) fixes the extended=progress + pagination half, verified at the API level.

@nathanpw

nathanpw commented Jul 11, 2026

Copy link
Copy Markdown

Thank you for looking into this and providing fixes! I was able to test this and tv shows are being marked as watched! However, I ran into a different issue with movies, where the "watched" item doesn't exist anymore from trakt (I think it is now plays). I am not really sure what is going on here...

utilities.py around line 363 is expecting "watched" and errors out here.

            if movie_col2:  # match found
                if watched:  # are we looking for watched items
                    if movie_col2["watched"] == 0 and movie_col1["watched"] == 1:

but in tracktapi.py it is returning "plays"? There is no "watched".

def getMoviesWatched(self, movies: Dict) -> Dict:
    for item in self._get_all_pages(
        "/sync/watched/movies", authorized=True, timeout=90
    ):
        self._merge_object(
            movies, item, "movie", ("plays", "last_watched_at", "last_updated_at")
        )
    return movies

oh to get the authorization with trakt to work i replaced __client_id and __client_secret around line 203 of traktapi.py with the values from the old plugin I had installed in Kodi. Just below the following lines of code:

class traktAPI(object):
    # Placeholders for build-time injection

Anyhow, I hope that helps, I am not sure if I missed something or did something wrong. Thanks again!

I didn't test collections or other "features", I mainly use this to sync between Kodi instances and Trakt.

@robant85

Copy link
Copy Markdown

@razzeee are there additional testers needed for release? I'm happy to volunteer for testing compiled code if needed.

@razzeee razzeee merged commit a66eb5d into razzeee:main Jul 14, 2026
2 of 3 checks passed
@razzeee

razzeee commented Jul 14, 2026

Copy link
Copy Markdown
Owner

The more we test this, the earlier this can be released, unfortunatly, I'm struggling a bit for time right now

@yitzhaq yitzhaq deleted the fix-watched-episode-pull branch July 14, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants