Sync watched status with Plex Discover - #2435
Conversation
|
This is my first open-source contribution & Python isn't my primary language, so I'd really appreciate any feedback on code style or approach as I learn the project's patterns. Thanks for the tool, I've loved using it. |
|
|
I have not abandoned this, just very busy over the last few weeks. I should wrap up fixes soon. |
f9a7234 to
0e19e0e
Compare
|
I appreciate the feedback. Changes include:
|
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “Plex Discover (online)” sync path so Trakt watched history can be applied to Plex cloud/discover items even when they aren’t present in the user’s local Plex library, addressing the use case in #1142.
Changes:
- Introduces
Sync.sync_online()gated by newsync.plex_onlineconfig to mark Trakt-watched movies/episodes as watched in Plex Discover. - Adds
TraktWatchedCollection(lazy-loaded watched movies/episodes map) plus unit/integration test scaffolding. - Updates Discover search resolution to include year in the query and documents the new feature in the README / default config.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
plextraktsync/sync/Sync.py |
Adds a Plex Discover sync pass (sync_online) invoked when plex_online is enabled. |
plextraktsync/trakt/TraktWatchedCollection.py |
New lazy collection for watched Trakt movies/episodes keyed by Trakt ID. |
plextraktsync/media/MediaFactory.py |
Improves online search query by appending year when available. |
plextraktsync/config/SyncConfig.py |
Adds plex_online config accessor. |
plextraktsync/config.default.yml |
Documents and defaults sync.plex_online to false. |
README.md |
Documents Plex Discover watched-status syncing and how to enable it. |
tests/test_trakt_watched_collection.py |
Unit tests for TraktWatchedCollection using mocks. |
tests/test_trakt_watched_collection_integration.py |
Adds integration-test skeleton intended for local runs against real Trakt API. |
tests/conftest.py |
Adds a trakt_api fixture for integration testing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| watched_collection = TraktWatchedCollection(self.trakt) | ||
| except Exception as e: | ||
| logger.error(f"Failed to fetch watched collection from Trakt: {e}") | ||
| return |
| for media_type in ["movies", "episodes"]: | ||
| watched_items = watched_collection[media_type] | ||
| logger.info(f"Processing {len(watched_items)} watched {media_type}") |
| trakt_items = list(watched_items.values()) | ||
| async for m in self.walker.media_from_traktlist(trakt_items): |
| async def sync_online(self, dry_run: bool): | ||
| """ | ||
| Sync watched status from Trakt to Plex Discover (cloud items) | ||
| """ | ||
| logger = logging.getLogger(__name__) | ||
| logger.info("Syncing watched status with Plex Discover") |
There was a problem hiding this comment.
I did not feel particularly confident implementing ratings. My chosen fix here was to update the PR title.
| """ | ||
| A dictionary of: | ||
| ["movies", "episodes"] => { | ||
| trakt_id => TraktItem | ||
| } | ||
| """ |
| import pytest | ||
|
|
||
| from plextraktsync.trakt.TraktWatchedCollection import TraktWatchedCollection | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Requires real Trakt API") |
| assert isinstance(movies, dict) | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Requires real Trakt API") |
| ### Plex Discover Sync | ||
|
|
||
| By default, all libraries are processed. You can disable libraries by name by | ||
| changing `excluded-libraries` in `config.yml`. | ||
| PlexTraktSync can sync watched status for movies and TV episodes that are not in your local Plex library but are available in Plex Discover (Plex's cloud database). This allows you to maintain watched history for content you've deleted from your server or never added. | ||
|
|
||
| To enable this feature, set `plex_online: true` in the sync section of your config. Note that this only syncs watched status from Trakt to Plex (not the reverse), and requires "Sync Watch states and Ratings" to be enabled in your Plex account settings. |
753ded4 to
b64fe51
Compare
Add the online sync path for Trakt watched movies and episodes to Plex Discover. Includes per-media-type Trakt error handling and direct streaming of watched items to avoid early materialization.
- Add trakt_api fixture to conftest.py - Create unit tests with real-world sample API data - Use MagicMock for dependencies - Correction: remove invalid list iterator assertions from mocked tests
This commit updates the project documentation to include information about the new Plex Discover synchronization feature. It provides users with details on how the watched status sync works for cloud-based content and any relevant configuration options.
b64fe51 to
92508e8
Compare
|
All Copilot feedback integrated into the original three commits. |
|
Also, better rebase against current
I tried to do so from github ui, but it gave some errror. |
|
Once this is complete, will this allow our Plex profile be 1:1 with Trakt without having these items in our library? |
|
@ConwayJ18 besides previous feedback, CI is also failing. if there are general changes not related to current pr, submit them as separate pr. as for others who want to test, see from readme how to install code from PR. |

Overview
Implements synchronization of watched status for movies and TV episodes that exist in Plex Discover (cloud database) but not in the local Plex library. This addresses the long-standing feature request in #1142.
Changes
sync_online()method inSync.pythat fetches watched items from Trakt and marks them as watched in Plex Discoverplex_online: falsesetting in sync config to enable/disable the featureTraktWatchedCollectionwith multiple scenariosSupports
Requirements
Testing
Note on Testing:
The test suite requires Python 3.11-3.13 due to pytrakt compatibility. Local environment is Python 3.14.
All pre-commit hooks pass successfully. Maintainers can run the full test suite in CI/CD.
Fixes #1142