Skip to content

Sync watched status with Plex Discover - #2435

Open
ConwayJ18 wants to merge 3 commits into
Taxel:mainfrom
ConwayJ18:plex-discover-watched-sync
Open

Sync watched status with Plex Discover#2435
ConwayJ18 wants to merge 3 commits into
Taxel:mainfrom
ConwayJ18:plex-discover-watched-sync

Conversation

@ConwayJ18

Copy link
Copy Markdown

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

  • Core sync logic: New sync_online() method in Sync.py that fetches watched items from Trakt and marks them as watched in Plex Discover
  • TraktWatchedCollection class: Lazy-loading dictionary for managing watched movies and episodes from Trakt
  • Configuration: New plex_online: false setting in sync config to enable/disable the feature
  • Error handling: Robust exception handling for Trakt API failures
  • Tests: Full unit test coverage for TraktWatchedCollection with multiple scenarios
  • Documentation: Updated README with usage instructions and limitations

Supports

  • Movies watched on Trakt → Plex Discover
  • TV episodes watched on Trakt → Plex Discover
  • One-way sync only (Trakt → Plex) as per design

Requirements

  • Users must enable "Sync Watch states and Ratings" in their Plex account settings
  • Requires Plex API support for cloud items (already available)

Testing

  • All pre-commit hooks pass (ruff, formatting, validation)
  • Unit tests validate collection initialization, data retrieval, and error cases

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

@ConwayJ18

ConwayJ18 commented Apr 4, 2026

Copy link
Copy Markdown
Author

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.

@glensc

glensc commented Apr 5, 2026

Copy link
Copy Markdown
Collaborator
  1. your commits are mess. commit message says update docs, but also changes tests
  2. if the added tests use real trakt api, then they may fail in ci (sometimes they don't fail, which is confusing). may need to use skip on ci mark

@glensc

glensc commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

@ConwayJ18

@ConwayJ18

Copy link
Copy Markdown
Author

I have not abandoned this, just very busy over the last few weeks. I should wrap up fixes soon.

@ConwayJ18
ConwayJ18 force-pushed the plex-discover-watched-sync branch from f9a7234 to 0e19e0e Compare May 17, 2026 22:32
@ConwayJ18

ConwayJ18 commented May 17, 2026

Copy link
Copy Markdown
Author

I appreciate the feedback. Changes include:

  • Branch history cleaned up and force-pushed to fix issue with test change on documentation commit
  • TraktWatchedCollection now includes mocked unit tests
  • Original tests were converted to skipped integration test scaffolding for Trakt watched sync

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new sync.plex_online config 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.

Comment thread plextraktsync/sync/Sync.py Outdated
Comment on lines +68 to +72
try:
watched_collection = TraktWatchedCollection(self.trakt)
except Exception as e:
logger.error(f"Failed to fetch watched collection from Trakt: {e}")
return
Comment on lines +74 to +76
for media_type in ["movies", "episodes"]:
watched_items = watched_collection[media_type]
logger.info(f"Processing {len(watched_items)} watched {media_type}")
Comment thread plextraktsync/sync/Sync.py Outdated
Comment on lines +78 to +79
trakt_items = list(watched_items.values())
async for m in self.walker.media_from_traktlist(trakt_items):
Comment on lines +61 to +66
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")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not feel particularly confident implementing ratings. My chosen fix here was to update the PR title.

Comment on lines +12 to +17
"""
A dictionary of:
["movies", "episodes"] => {
trakt_id => TraktItem
}
"""
Comment on lines +11 to +16
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")
Comment thread README.md Outdated
Comment on lines +367 to +371
### 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.
@ConwayJ18 ConwayJ18 changed the title Sync watched status and ratings with Plex Discover Sync watched status with Plex Discover May 28, 2026
@ConwayJ18
ConwayJ18 marked this pull request as draft May 31, 2026 16:41
@ConwayJ18
ConwayJ18 force-pushed the plex-discover-watched-sync branch 3 times, most recently from 753ded4 to b64fe51 Compare May 31, 2026 17:07
ConwayJ18 added 3 commits May 31, 2026 12:10
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.
@ConwayJ18
ConwayJ18 force-pushed the plex-discover-watched-sync branch from b64fe51 to 92508e8 Compare May 31, 2026 17:11
@ConwayJ18
ConwayJ18 marked this pull request as ready for review May 31, 2026 17:15
@ConwayJ18

Copy link
Copy Markdown
Author

All Copilot feedback integrated into the original three commits.

@glensc

glensc commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Resolve Copilot discussions, please.

image

@glensc

glensc commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Also, better rebase against current main:

No conflicts with base branch
It’s 72 commits behind (base commit: 16f902f)

I tried to do so from github ui, but it gave some errror.

@JunaidDawood

Copy link
Copy Markdown

Once this is complete, will this allow our Plex profile be 1:1 with Trakt without having these items in our library?

@glensc

glensc commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

@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.

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.

Feature request: is it possible to sync the content from trakt to Plex even tho the content isn't available on plexserver

4 participants