def compareShows(self, shows_col1, shows_col2, watched=False, restrict=False): shows = [] p = 'watched' if watched else 'seasons' for show_col1 in shows_col1: show_col2 = utilities.findShow(show_col1, shows_col2) if show_col2: season_diff = {} show_col2_seasons = show_col2[p] for season in show_col1[p]: a = show_col1[p][season] if season in show_col2_seasons: b = show_col2_seasons[season] diff = list(set(a).difference(set(b))) if len(diff) > 0: if restrict: t = list(set(show_col2['seasons'][season]).intersection(set(diff))) if len(t) > 0: eps = {} for ep in t: eps[ep] = show_col2['seasons'][season][ep] season_diff[season] = eps else: eps = {} for ep in diff: eps[ep] = ep season_diff[season] = eps else: if not restrict: if len(a) > 0: season_diff[season] = a if len(season_diff) > 0: show = {'title': show_col1['title'], 'tvdb_id': show_col1['tvdb_id'], 'year': show_col1['year'], 'seasons': season_diff} if 'imdb_id' in show_col1 and show_col1['imdb_id']: show['imdb_id'] = show_col1['imdb_id'] if 'imdb_id' in show_col2 and show_col2['imdb_id']: show['imdb_id'] = show_col2['imdb_id'] if 'tvshowid' in show_col1: show['tvshowid'] = show_col1['tvshowid'] if 'tvshowid' in show_col2: show['tvshowid'] = show_col2['tvshowid'] shows.append(show) else: if not restrict: if 'in_collection' in show_col1 and show_col1['in_collection']: if self.countEpisodes([show_col1], watched=watched) > 0: show = {'title': show_col1['title'], 'tvdb_id': show_col1['tvdb_id'], 'year': show_col1['year'], 'seasons': show_col1[p]} if 'tvshowid' in show_col1: show['tvshowid'] = show_col1['tvshowid'] shows.append(show) return shows
def traktLoadShows(self): self.updateProgress(10, line1=utilities.getString(1485), line2=utilities.getString(1486)) Debug('[Episodes Sync] Getting episode collection from trakt.tv') library_shows = self.traktapi.getShowLibrary() if not isinstance(library_shows, list): Debug("[Episodes Sync] Invalid trakt.tv show list, possible error getting data from trakt, aborting trakt.tv collection update.") return False self.updateProgress(12, line2=utilities.getString(1487)) Debug('[Episodes Sync] Getting watched episodes from trakt.tv') watched_shows = self.traktapi.getWatchedEpisodeLibrary() if not isinstance(watched_shows, list): Debug("[Episodes Sync] Invalid trakt.tv watched show list, possible error getting data from trakt, aborting trakt.tv watched update.") return False shows = [] i = 0 x = float(len(library_shows)) # reformat show array for show in library_shows: if show['title'] is None and show['imdb_id'] is None and show['tvdb_id'] is None: # has no identifing values, skip it continue y = {} w = {} for s in show['seasons']: y[s['season']] = s['episodes'] w[s['season']] = [] show['seasons'] = y show['watched'] = w show['in_collection'] = True if show['imdb_id'] is None: show['imdb_id'] = "" if show['tvdb_id'] is None: show['tvdb_id'] = "" shows.append(show) i = i + 1 y = ((i / x) * 8) + 12 self.updateProgress(int(y), line2=utilities.getString(1488)) i = 0 x = float(len(watched_shows)) for watched_show in watched_shows: if watched_show['title'] is None and watched_show['imdb_id'] is None and watched_show['tvdb_id'] is None: # has no identifing values, skip it continue if watched_show['imdb_id'] is None: watched_show['imdb_id'] = "" if watched_show['tvdb_id'] is None: watched_show['tvdb_id'] = "" show = utilities.findShow(watched_show, shows) if show: for s in watched_show['seasons']: show['watched'][s['season']] = s['episodes'] else: y = {} w = {} for s in watched_show['seasons']: w[s['season']] = s['episodes'] y[s['season']] = [] watched_show['seasons'] = y watched_show['watched'] = w watched_show['in_collection'] = False shows.append(watched_show) i = i + 1 y = ((i / x) * 8) + 20 self.updateProgress(int(y), line2=utilities.getString(1488)) self.updateProgress(28, line2=utilities.getString(1489)) return shows