Fix multiple watched bug
use trakt id instead of slug
fetch specials episodes status
fetch watched episodes even if no air date
MODIFY
main.py
main.py
@@ -105,7 +105,7 @@ def process_movie_section(s, watched_set, ratings_dict, listutil, collection):
# sync watch status
if CONFIG['sync']['watched_status']:
watchedOnPlex = movie.isWatched
- watchedOnTrakt = m.slug in watched_set
+ watchedOnTrakt = m.trakt in watched_set
if watchedOnPlex is not watchedOnTrakt:
# if watch status is not synced
# send watched status from plex to trakt
@@ -131,7 +131,7 @@ def process_movie_section(s, watched_set, ratings_dict, listutil, collection):
"Movie [{} ({})]: NOT FOUND on trakt - GUID: {}".format(movie.title, movie.year, guid))
-def process_show_section(s):
+def process_show_section(s, watched_set):
with requests_cache.disabled():
allShows = s.all()
logging.info("Now working on show section {} containing {} elements".format(s.title, len(allShows)))
@@ -175,7 +175,7 @@ def process_show_section(s):
logging.error("Show [{} ({})]: Did not find on Trakt. Aborting. GUID: {}".format(show.title, show.year, guid))
continue
with requests_cache.disabled():
- trakt_watched = pytrakt_extensions.watched(trakt_show.slug)
+ #trakt_watched = pytrakt_extensions.watched(trakt_show.trakt)
trakt_collected = pytrakt_extensions.collected(trakt_show.slug)
start_time = time()
# this lookup-table is accessible via lookup[season][episode]
@@ -196,8 +196,8 @@ def process_show_section(s):
except TypeError:
logging.error("Show [{} ({})]: Invalid episode {}".format(show.title, show.year, episode))
continue
- watched = trakt_watched.get_completed(
- episode.seasonNumber, episode.index)
+ watched = watched_set.get_completed(
+ trakt_show.trakt, episode.seasonNumber, episode.index)
collected = trakt_collected.get_completed(
episode.seasonNumber, episode.index)
# sync collected
@@ -260,12 +260,13 @@ def main():
liked_lists = pytrakt_extensions.get_liked_lists()
trakt_user = trakt.users.User(getenv('TRAKT_USERNAME'))
trakt_watched_movies = set(
- map(lambda m: m.slug, trakt_user.watched_movies))
+ map(lambda m: m.trakt, trakt_user.watched_movies))
logging.debug("Watched movies from trakt: {}".format(
trakt_watched_movies))
trakt_movie_collection = set(
map(lambda m: m.slug, trakt_user.movie_collection))
#logging.debug("Movie collection from trakt:", trakt_movie_collection)
+ trakt_watched_shows = pytrakt_extensions.allwatched()
if CONFIG['sync']['watchlist']:
listutil.addList(None, "Trakt Watchlist", list_set=set(
map(lambda m: m.slug, trakt_user.watchlist_movies)))
@@ -304,7 +305,7 @@ def main():
# process show sections
elif type(section) is plexapi.library.ShowSection:
print("Processing section", section.title)
- process_show_section(section)
+ process_show_section(section, trakt_watched_shows)
else:
continue

MODIFY
pytrakt_extensions.py
pytrakt_extensions.py
@@ -42,9 +42,15 @@ def instance(self):
@get
-def watched(show_slug):
+def allwatched():
+ # returns a ShowProgress object containing all watched episodes
+ data = yield 'sync/watched/shows'
+ yield AllWatchedShows(data)
+
+@get
+def watched(show_id):
# returns a ShowProgress object containing the watched states of the passed show
- data = yield 'shows/{}/progress/watched'.format(show_slug)
+ data = yield 'shows/{}/progress/watched?specials=true'.format(show_id)
yield ShowProgress(**data)
@get
@@ -55,10 +61,12 @@ def collected(show_slug):
yield ShowProgress(**data)
class EpisodeProgress():
- def __init__(self, number=0, aired=0, completed=False, last_watched_at=None, collected_at=None):
+ def __init__(self, number=0, aired=0, plays=False, completed=False, last_watched_at=None, collected_at=None):
self.number = number
self.aired = aired
self.completed = completed
+ if plays > 0:
+ self.completed = True
self.last_watched_at = last_watched_at
self.collected_at = collected_at
#print("Episode {} completed: {}".format(number, completed))
@@ -87,14 +95,17 @@ def get_completed(self, episode):
class ShowProgress():
- def __init__(self, aired=0, completed=False, last_watched_at=None, reset_at=None, seasons=None, hidden_seasons=None, next_episode=0, last_episode=0, last_collected_at=None):
+ def __init__(self, aired=0, plays=None, completed=False, last_watched_at=None, last_updated_at=None, reset_at=None, show=None, seasons=None, hidden_seasons=None, next_episode=0, last_episode=0, last_collected_at=None):
self.aired = aired
self.last_watched_at = last_watched_at
+ self.last_updated_at = last_updated_at
self.last_collected_at = last_collected_at
self.reset_at = reset_at
self.hidden_seasons = hidden_seasons
self.next_episode = next_episode
self.last_episode = last_episode
+ self.trakt = show['ids']['trakt'] if show else None
+ self.slug = show['ids']['slug'] if show else None
self.seasons = {}
allCompleted = True
for season in seasons:
@@ -112,6 +123,19 @@ def get_completed(self, season, episode):
return False
return self.seasons[season].get_completed(episode)
+class AllWatchedShows():
+ def __init__(self, shows=None):
+ self.shows = {}
+ for show in shows:
+ prog = ShowProgress(**show)
+ self.shows[prog.trakt] = prog
+
+ def get_completed(self, trakt_id, season, episode):
+ if trakt_id not in self.shows.keys():
+ return False
+ elif season not in self.shows[trakt_id].seasons.keys():
+ return False
+ return self.shows[trakt_id].seasons[season].get_completed(episode)
if __name__ == "__main__":
print(get_liked_lists())
\ No newline at end of file

Fix multiple watched bug

- use trakt id instead of slug
- fetch specials episodes status
- fetch watched episodes even if no air date