Added sync config
ADD
config.json
+{
+ "sync": {
+ "liked_lists": true,
+ "watchlist": true,
+ "watched_status": true,
+ "collection": true,
+ "ratings": true
+ }
+}
\ No newline at end of file

ADD
config.py
+import json
+
+with open('config.json', 'r') as fp:
+ CONFIG = json.load(fp)
\ No newline at end of file

MODIFY
main.py
main.py
+
import plexapi.server
import trakt
import trakt.movies
import pytrakt_extensions
from trakt_list_util import TraktListUtil
+from config import CONFIG
import requests
import requests_cache
@@ -56,11 +58,15 @@ def process_movie_section(s, watched_set, ratings_dict, listutil, collection):
if type(result) is trakt.movies.Movie:
m = result
break
+
+ if CONFIG['sync']['collection']:
# add to collection if necessary
if m.slug not in collection:
logging.info('Movie [{} ({})]: Added to trakt collection'.format(movie.title, movie.year))
m.add_to_library()
+
# compare ratings
+ if CONFIG['sync']['ratings']:
if m.slug in ratings_dict:
trakt_rating = int(ratings_dict[m.slug])
else:
@@ -76,7 +82,9 @@ def process_movie_section(s, watched_set, ratings_dict, listutil, collection):
with requests_cache.disabled():
movie.rate(trakt_rating)
logging.info("Movie [{} ({})]: Rating with {} on plex".format(movie.title, movie.year, trakt_rating))
+
# sync watch status
+ if CONFIG['sync']['watched_status']:
watchedOnPlex = movie.isWatched
watchedOnTrakt = m.slug in watched_set
if watchedOnPlex is not watchedOnTrakt:
@@ -146,10 +154,14 @@ def process_show_section(s):
eps = lookup[episode.seasonNumber][episode.index]
watched = trakt_watched.get_completed(episode.seasonNumber, episode.index)
collected = trakt_collected.get_completed(episode.seasonNumber, episode.index)
+ # sync collected
+ if CONFIG['sync']['collection']:
if not collected:
with requests_cache.disabled():
eps.instance.add_to_library()
logging.info("Show [{} ({})]: Collected episode S{:02}E{:02}".format(show.title, show.year, episode.seasonNumber, episode.index))
+ # sync watched status
+ if CONFIG['sync']['watched_status']:
if episode.isWatched != watched:
if episode.isWatched:
with requests_cache.disabled():
@@ -170,21 +182,26 @@ def process_show_section(s):
def main():
+
start_time = time()
load_dotenv()
logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', filename='last_update.log', filemode='w', level=logging.INFO)
listutil = TraktListUtil()
# do not use the cache for account specific stuff as this is subject to change
with requests_cache.disabled():
+ if CONFIG['sync']['liked_lists']:
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))
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)
+ if CONFIG['sync']['watchlist']:
listutil.addList(None, "Trakt Watchlist", list_set=set(map(lambda m: m.slug, trakt_user.watchlist_movies)))
#logging.debug("Movie watchlist from trakt:", trakt_movie_watchlist)
user_ratings = trakt_user.get_ratings(media_type='movies')
+
+ if CONFIG['sync']['liked_lists']:
for lst in liked_lists:
listutil.addList(lst['username'], lst['listname'])
ratings = {}

Added sync config