def SyncSection(key): if Prefs['username'] is None: Log.Info('You need to enter you login information first.') return MessageContainer( 'Login information missing', 'You need to enter you login information first.' ) prefs = (Prefs['sync_watched'], Prefs['sync_ratings'], Prefs['sync_collection']) if all(x is not True for x in prefs): Log.Info('You need to enable at least one type of actions to sync first.') return MessageContainer( 'No type selected', 'You need to enable at least one type of actions to sync first.' ) # Sync the library with trakt.tv all_movies = [] all_episodes = [] ratings_movies = [] ratings_episodes = [] collection_movies = [] collection_episodes = [] for value in key.split(','): section = PMS.get_section(value) if not section: Log.Warn('Unable to get section with key "%s"' % value) continue item_kind = section.xpath('//MediaContainer')[0].get('viewGroup') # Sync movies if item_kind == 'movie': for video in PMS.get_section_videos(value): push_movie(all_movies, collection_movies, ratings_movies, video) # Sync TV Shows if item_kind == 'show': for directory in PMS.get_section_directories(value): push_show(all_episodes, collection_episodes, ratings_episodes, directory) Log.Info('Found %s movies' % len(all_movies)) Log.Info('Found %s series' % len(all_episodes)) if Prefs['sync_ratings'] is True: if len(ratings_episodes) > 0: Trakt.request('rate/episodes', { 'episodes': ratings_episodes }) if len(ratings_movies) > 0: Trakt.request('rate/movies', { 'movies': ratings_movies }) if Prefs['sync_watched'] is True: if len(all_movies) > 0: Trakt.request('movie/seen', { 'movies': all_movies }) for episode in all_episodes: Trakt.request('show/episode/seen', episode) if Prefs['sync_collection'] is True: if len(collection_movies) > 0: Trakt.request('movie/library', { 'movies': collection_movies }) for episode in collection_episodes: Trakt.request('show/episode/library', episode) Log.Info('Syncing is done!') Dict['Last_sync_up'] = Datetime.Now() return MessageContainer('Done', 'Syncing is done!')
def ManuallyTrakt(): if Prefs['username'] is None: Log.Info('You need to enter you login information first.') return MessageContainer('Login information missing', 'You need to enter you login information first.') if Prefs['sync_watched'] is not True and Prefs['sync_ratings'] is not True: Log.Info('You need to enable at least one type of actions to sync first.') return MessageContainer('No type selected', 'You need to enable at least one type of actions to sync first.') values = {'extended': 'min'} movie_list = None show_list = None movies_rated_list = None episodes_rated_list = None # Get watched and rated lists from trakt if Prefs['sync_watched'] is True: movie_list = Trakt.request( 'user/library/movies/watched.json', values, param=Prefs['username'] ).get('data') show_list = Trakt.request( 'user/library/shows/watched.json', values, param=Prefs['username'] ).get('data') if not all([x is not None for x in [movie_list, show_list]]): return MessageContainer('Network error', 'Network error while requesting watched items from trakt.') if Prefs['sync_ratings'] is True: movies_rated_list = Trakt.request( 'user/ratings/movies.json', values, param=Prefs['username'] ).get('data') episodes_rated_list = Trakt.request( 'user/ratings/episodes.json', values, param=Prefs['username'] ).get('data') if not all([x is not None for x in [movies_rated_list, episodes_rated_list]]): return MessageContainer('Network error', 'Network error while requesting rated items from trakt.') # Go through the Plex library and update flags for section_type, key, title in itersections(): # Sync movies if section_type == 'movie': for video in PMS.get_section_videos(key): pull_movie(movie_list, movies_rated_list, video) # Sync TV Shows if section_type == 'show': for directory in PMS.get_section_directories(key): tvdb_id = match_tvdb_id(directory.get('ratingKey')) if not tvdb_id: continue if tvdb_id is not None: pull_show(show_list, episodes_rated_list, directory, tvdb_id) Log.Info('Syncing is done!') Dict['Last_sync_down'] = Datetime.Now() return MessageContainer('Done', 'Syncing is done!')