You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agents/plex_integration.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,9 @@ The system prioritizes **TMDB IDs** as the canonical source of truth. All Plex e
11
11
1.**Explicit TMDB ID**: Extracted directly from Plex GUIDs (e.g., `tmdb://123`).
12
12
2.**IMDB/TVDB Lookup**: If only IMDB (`tt123`) or TVDB (`789`) IDs are present, the system queries the TMDB `find` API to resolve the corresponding `tmdb_id`.
13
13
3.**Title Search Fallback**:
14
-
- If no external IDs are found (or they return 404s), the system performs a search against TMDB using the media title.
15
-
-**TV Shows**: Uses `grandparentTitle` (series title) or `title`. Match attempts to filter by year if available.
14
+
- For TV history entries, Plex item metadata and then show metadata from `grandparentRatingKey`/`grandparentKey` are checked before title search.
15
+
- If no deterministic IDs are found (or they return 404s), the system performs a search against TMDB using the media title.
16
+
-**TV Shows**: Uses `grandparentTitle` (series title) or `title` only after the Plex show-level lookup. Match attempts to filter by year if available.
16
17
-**Movies**: Uses `title` and `year`.
17
18
18
19
**GUID extraction & conflicts:**
@@ -42,7 +43,7 @@ Plex history import uses Plex's history endpoint as the canonical event stream.
42
43
- Sorted newest-first (`sort=viewedAt:desc`) and paged with `X-Plex-Container-Start`/`X-Plex-Container-Size`. `PLEX_HISTORY_PAGE_SIZE` controls page size; `PLEX_HISTORY_MAX_ITEMS` (0 = no cap) limits how far back we fetch. There is no time windowing, so re-importing overlapping ranges is expected.
43
44
44
45
**Fields we rely on:**
45
-
- IDs: `Guid`/`guid` entries with TMDB/IMDB/TVDB identifiers are required for deterministic resolution. Order is: resolve IDs from the history row (including title search when allowed); if missing, fetch `GET {server_uri}/library/metadata/{ratingKey}`to pull GUIDs (no title search in this step); if still missing, the movie/TV recorders may still fall back to title search when a title is available, otherwise the entry is skipped.
46
+
- IDs: `Guid`/`guid` entries with TMDB/IMDB/TVDB identifiers are required for deterministic resolution. For TV history, resolve IDs from the history row, fetch `GET {server_uri}/library/metadata/{ratingKey}`when needed, then inspect the Plex show at `grandparentRatingKey`/`grandparentKey` before allowing title search. Movies retain their existing title fallback when a title is available; otherwise the entry is skipped.
46
47
- Titles: `title` or `grandparentTitle` is required for title-search fallback; Plex-only GUIDs without a title are skipped.
47
48
- Timing: `viewedAt` or `lastViewedAt` (epoch seconds) is the authoritative `watched_at`. If missing, we fall back to import time; `viewCount`/`viewOffset` are ignored. Rows missing `viewedAt`/`lastViewedAt` are nondeterministic and can dedupe poorly across runs.
48
49
- TV structure: `parentIndex` (season) and `index` (episode) must be numeric. Missing numbers can cause the entry to be skipped or treated as a movie in show libraries.
0 commit comments