-
Notifications
You must be signed in to change notification settings - Fork 132
Sync watched status and ratings with Plex Discover #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cd8e77c
c8d3da1
f1a1144
9d65e23
0b68aec
6fc42a5
9fa006b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,12 +68,34 @@ def sync(self, walker: Walker, dry_run=False): | |
| self.sync_watched(movie, dry_run=dry_run) | ||
| if not is_partial: | ||
| listutil.addPlexItemToLists(movie) | ||
| if self.config.clear_collected: | ||
| movie_trakt_ids.add(movie.trakt_id) | ||
| movie_trakt_ids.add(movie.trakt_id) | ||
|
|
||
| if movie_trakt_ids: | ||
| if self.config.clear_collected and movie_trakt_ids: | ||
| self.clear_collected(self.trakt.movie_collection, movie_trakt_ids) | ||
|
|
||
| remaining_movies_ids = ( | ||
| set(self.trakt.watched_movies.keys()).union( | ||
| set(self.trakt.ratings["movies"]) | ||
| ) - movie_trakt_ids | ||
| ) | ||
|
|
||
| if remaining_movies_ids and not is_partial and self.config["plex_online"]: | ||
| """Sync ratings and watched status of movies not in Plex library""" | ||
| items = set(self.trakt.watched_movies.values()).union( | ||
| set(self.trakt.ratings.items["movies"]) | ||
| ) | ||
| # items is a set() of trakt.movies.Movies already watched or rated (can a user rate without watch?) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can definitely rate movie without watching it: |
||
| sync_items = [] | ||
| for tm in items: | ||
| if tm.trakt in remaining_movies_ids: | ||
| sync_items.append(tm) | ||
| remaining_movies_ids.remove(tm.trakt) | ||
| for movie in walker.media_from_traktlist(sync_items, title="Trakt watched movies"): | ||
| if movie is not None: | ||
| self.sync_watched(movie, dry_run=dry_run) | ||
| # Rating medias from Plex Discover not implemented yet https://github.com/pkkid/python-plexapi/issues/1137 | ||
| # self.sync_ratings(movie, dry_run=dry_run) | ||
|
|
||
| shows = set() | ||
| episode_trakt_ids = set() | ||
| for episode in walker.find_episodes(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,23 +4,60 @@ | |
|
|
||
| from plextraktsync.decorators.flatten import flatten_dict | ||
|
|
||
| from trakt.movies import Movie | ||
| from trakt.tv import TVEpisode, TVSeason, TVShow | ||
|
|
||
| if TYPE_CHECKING: | ||
| from plextraktsync.trakt.TraktApi import TraktApi | ||
|
|
||
| trakt_types = { | ||
| "movie": Movie, | ||
| "show": TVShow, | ||
| "season": TVSeason, | ||
| "episode": TVEpisode, | ||
| } | ||
|
|
||
|
|
||
| class TraktRatingCollection(dict): | ||
| def __init__(self, trakt: TraktApi): | ||
| super().__init__() | ||
| self.trakt = trakt | ||
| self.items = dict() | ||
|
|
||
| def __missing__(self, media_type: str): | ||
| ratings = self.ratings(media_type) | ||
| self[media_type] = ratings | ||
| self.items[media_type] = self.rating_items(media_type) | ||
|
|
||
| return ratings | ||
|
|
||
| @flatten_dict | ||
| def ratings(self, media_type: str): | ||
| """Yield trakt id and rating of all rated media_type""" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method does not |
||
| index = media_type.rstrip("s") | ||
| for r in self.trakt.get_ratings(media_type): | ||
| yield r[index]["ids"]["trakt"], r["rating"] | ||
|
|
||
| def rating_items(self, media_type: str): | ||
| """Yield TraktMedia of all rated media_type""" | ||
| index = media_type.rstrip("s") | ||
| for r in self.trakt.get_ratings(media_type): | ||
| title = r[index].get("title") | ||
| if index == "movie": | ||
| show = season = number = None | ||
| else: | ||
| show = title = r["show"]["title"] | ||
| if index == "episode": | ||
| season = r[index]["season"] | ||
| number = r[index]["number"] | ||
| if index == "season": | ||
| season = r[index]["number"] | ||
| number = None | ||
| ids = r[index]["ids"] | ||
| yield trakt_types[index]( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. point of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reporting this.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you put the generator to set(): it's what the |
||
| title=title, | ||
| show=show, | ||
| season=season, | ||
| number=number, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ids=ids, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.