def remove_episodes_from_trakt_collection(self): trakt_data = [] sickrage.app.log.debug( "COLLECTION::REMOVE::START - Look for Episodes to Remove From Trakt Collection" ) for s in get_show_list(): for e in s.episodes: if e.location: continue series_provider_trakt_id = s.series_provider.trakt_id if self._check_in_list(series_provider_trakt_id, str(e.series_id), e.season, e.episode, 'Collection'): sickrage.app.log.debug( f"Removing Episode {s.name} S{e.season:02d}E{e.episode:02d} from collection" ) trakt_data.append( (e.series_id, s.series_provider_id, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: TraktAPI()["sync/collection"].remove( self.trakt_bulk_data_generate(trakt_data)) self._get_show_collection() except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Error: {e}") sickrage.app.log.debug( "COLLECTION::REMOVE::FINISH - Look for Episodes to Remove From Trakt Collection" )
def remove_episodes_from_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "WATCHLIST::REMOVE::START - Look for Episodes to Remove from Trakt Watchlist" ) for s in get_show_list(): for e in s.episodes: series_provider_trakt_id = s.series_provider.trakt_id if self._check_in_list(series_provider_trakt_id, str(e.series_id), e.season, e.episode): sickrage.app.log.debug( f"Removing Episode {s.name} S{e.season:02d}E{e.episode:02d} from watchlist" ) trakt_data.append( (e.series_id, s.series_provider_id, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) TraktAPI()["sync/watchlist"].remove(data) self._get_episode_watchlist() except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Error: {e}") sickrage.app.log.debug( "WATCHLIST::REMOVE::FINISH - Look for Episodes to Remove from Trakt Watchlist" )
def add_episodes_to_trakt_collection(self): trakt_data = [] sickrage.app.log.debug( "COLLECTION::SYNC::START - Look for Episodes to Add to Trakt Collection" ) for s in get_show_list(): for e in s.episodes: trakt_id = s.series_provider.trakt_id if not self._check_in_list(trakt_id, str(e.series_id), e.season, e.episode, 'Collection'): sickrage.app.log.debug( f"Adding Episode {s.name} S{e.season:02d}E{e.episode:02d} to collection" ) trakt_data.append( (e.series_id, s.series_provider_id, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: TraktAPI()["sync/collection"].add( self.trakt_bulk_data_generate(trakt_data)) self._get_show_collection() except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Error: {e}") sickrage.app.log.debug( "COLLECTION::ADD::FINISH - Look for Episodes to Add to Trakt Collection" )
def add_episodes_to_trakt_collection(self): trakt_data = [] sickrage.app.log.debug( "COLLECTION::SYNC::START - Look for Episodes to Add to Trakt Collection" ) for s in get_show_list(): for e in s.episodes: trakt_id = IndexerApi(s.indexer).trakt_id if not self._check_in_list(trakt_id, str(e.showid), e.season, e.episode, 'Collection'): sickrage.app.log.debug( "Adding Episode %s S%02dE%02d to collection" % (s.name, e.season, e.episode)) trakt_data.append((e.showid, s.indexer, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: TraktAPI()["sync/collection"].add( self.trakt_bulk_data_generate(trakt_data)) self._get_show_collection() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.app.log.debug( "COLLECTION::ADD::FINISH - Look for Episodes to Add to Trakt Collection" )
def get(self, *args, **kwargs): indexer_id = self.get_argument('indexer_id') data = {'shows': [{'ids': {'tvdb': indexer_id}}]} TraktAPI()["users/me/lists/{list}".format( list=sickrage.app.config.trakt_blacklist_name)].add(data) return self.redirect('/home/addShows/trendingShows/')
def remove_episodes_from_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "WATCHLIST::REMOVE::START - Look for Episodes to Remove from Trakt Watchlist" ) for s in get_show_list(): for e in s.episodes: trakt_id = IndexerApi(s.indexer).trakt_id if self._check_in_list(trakt_id, str(e.showid), e.season, e.episode): sickrage.app.log.debug( "Removing Episode %s S%02dE%02d from watchlist" % (s.name, e.season, e.episode)) trakt_data.append((e.showid, s.indexer, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) TraktAPI()["sync/watchlist"].remove(data) self._get_episode_watchlist() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.app.log.debug( "WATCHLIST::REMOVE::FINISH - Look for Episodes to Remove from Trakt Watchlist" )
def add_show_to_trakt_library(self, show_obj): """ Sends a request to trakt indicating that the given show and all its episodes is part of our library. show_obj: The TVShow object to add to trakt """ data = {} if not self.find_show_match(show_obj.indexer, show_obj.indexer_id): # URL parameters data = { 'shows': [{ 'title': show_obj.name, 'year': show_obj.startyear, 'ids': { IndexerApi(show_obj.indexer).trakt_id: show_obj.indexer_id } }] } if len(data): sickrage.app.log.debug("Adding %s to tv library" % show_obj.name) try: TraktAPI()["sync/collection"].add(data) except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Aborting adding show %s to Trakt library. Error: %s" % (show_obj.name, repr(e))) return
def get(self, *args, **kwargs): """ Display the new show page which collects a tvdb id, folder, and extra options and posts them to addNewShow """ show_list = self.get_argument('list', 'trending') limit = self.get_argument('limit', None) or 10 trakt_shows = [] shows, black_list = getattr(TraktAPI()['shows'], show_list)( extended="full", limit=int(limit) + get_show_list().count()), False while len(trakt_shows) < int(limit): trakt_shows += [ x for x in shows if 'tvdb' in x.ids and not find_show(int(x.ids['tvdb']), session=self.db_session) ] return self.render( "/home/trakt_shows.mako", title="Trakt {} Shows".format(show_list.capitalize()), header="Trakt {} Shows".format(show_list.capitalize()), enable_anime_options=False, black_list=black_list, trakt_shows=trakt_shows[:int(limit)], trakt_list=show_list, limit=limit, controller='home', action="trakt_shows")
def remove_episodes_from_trakt_collection(self): trakt_data = [] sickrage.app.log.debug( "COLLECTION::REMOVE::START - Look for Episodes to Remove From Trakt Collection" ) for s in get_show_list(): for e in s.episodes: if e.location: continue trakt_id = IndexerApi(s.indexer).trakt_id if self._check_in_list(trakt_id, str(e.showid), e.season, e.episode, 'Collection'): sickrage.app.log.debug( "Removing Episode %s S%02dE%02d from collection" % (s.name, e.season, e.episode)) trakt_data.append((e.showid, s.indexer, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: TraktAPI()["sync/collection"].remove( self.trakt_bulk_data_generate(trakt_data)) self._get_show_collection() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.app.log.debug( "COLLECTION::REMOVE::FINISH - Look for Episodes to Remove From Trakt Collection" )
def add_episodes_to_trakt_watch_list(self): session = sickrage.app.main_db.session() trakt_data = [] sickrage.app.log.debug( "WATCHLIST::ADD::START - Look for Episodes to Add to Trakt Watchlist" ) for s in get_show_list(): for e in session.query(MainDB.TVEpisode).filter_by( showid=s.indexer_id).filter(~MainDB.TVEpisode.episode.in_( Quality.SNATCHED + Quality.SNATCHED_PROPER + [UNKNOWN] + [WANTED])): trakt_id = IndexerApi(s.indexer).trakt_id if self._check_in_list(trakt_id, str(e.showid), e.season, e.episode): sickrage.app.log.debug( "Adding Episode %s S%02dE%02d to watchlist" % (s.name, e.season, e.episode)) trakt_data.append((e.showid, s.indexer, s.name, s.startyear, e.season, e.episode)) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) TraktAPI()["sync/watchlist"].add(data) self._get_episode_watchlist() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error %s" % e) sickrage.app.log.debug( "WATCHLIST::ADD::FINISH - Look for Episodes to Add to Trakt Watchlist" )
def update_library(self, ep_obj): """ Sends a request to trakt indicating that the given episode is part of our library. ep_obj: The TVEpisode object to add to trakt """ if sickrage.app.config.use_trakt: try: # URL parameters data = { 'shows': [{ 'title': ep_obj.show.name, 'year': ep_obj.show.startyear, 'ids': { IndexerApi(ep_obj.show.indexer).trakt_id: ep_obj.show.indexer_id }, }] } if sickrage.app.config.trakt_sync_watchlist: if sickrage.app.config.trakt_remove_serieslist: TraktAPI()["sync/watchlist"].remove(data) # Add Season and Episode + Related Episodes data['shows'][0]['seasons'] = [{ 'number': ep_obj.season, 'episodes': [] }] for relEp_Obj in [ep_obj] + ep_obj.related_episodes: data['shows'][0]['seasons'][0]['episodes'].append( {'number': relEp_Obj.episode}) if sickrage.app.config.trakt_sync_watchlist: if sickrage.app.config.trakt_remove_watchlist: TraktAPI()["sync/watchlist"].remove(data) # update library TraktAPI()["sync/collection"].add(data) except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service: %s" % e)
def find_show_match(self, indexer, indexer_id): traktShow = None try: library = TraktAPI()["sync/collection"].shows() or {} if not library: sickrage.app.log.debug( "No shows found in your library, aborting library update") return traktShow = [ x for __, x in library.items() if int(indexer_id) == int(x.ids[IndexerApi(indexer).trakt_id]) ] except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Aborting library check. Error: %s" % repr(e)) return traktShow
def find_show_match(self, series_provider_id, series_id): trakt_show = None try: library = TraktAPI()["sync/collection"].shows() or {} if not library: sickrage.app.log.debug( "No shows found in your library, aborting library update") return trakt_show = [ x for __, x in library.items() if int(series_id) == int(x.ids[ sickrage.app.series_providers[series_provider_id].trakt_id] ) ] except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Aborting library check. Error: {repr(e)}" ) return trakt_show
def _get_show_watchlist(self): """ Get Watchlist and parse once into addressable structure """ try: sickrage.app.log.debug("Getting Show Watchlist") self.ShowWatchlist = TraktAPI()["sync/watchlist"].shows() or {} except Exception as e: sickrage.app.log.warning( "Could not connect to trakt service, cannot download Show Watchlist: %s" % repr(e)) return False return True
def add_episodes_to_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "WATCHLIST::ADD::START - Look for Episodes to Add to Trakt Watchlist" ) for show_object in get_show_list(): for episode_object in show_object.episodes: if episode_object.status in flatten([ EpisodeStatus.composites(EpisodeStatus.SNATCHED), EpisodeStatus.composites( EpisodeStatus.SNATCHED_PROPER), EpisodeStatus.UNKNOWN, EpisodeStatus.WANTED ]): continue trakt_id = show_object.series_provider.trakt_id if self._check_in_list(trakt_id, str(show_object.series_id), episode_object.season, episode_object.episode): sickrage.app.log.debug( f"Adding Episode {show_object.name} S{episode_object.season:02d}E{episode_object.episode:02d} to watchlist" ) trakt_data.append( (show_object.series_id, show_object.series_provider_id, show_object.name, show_object.startyear, episode_object.season, episode_object.episode)) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) TraktAPI()["sync/watchlist"].add(data) self._get_episode_watchlist() except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Error {e}") sickrage.app.log.debug( "WATCHLIST::ADD::FINISH - Look for Episodes to Add to Trakt Watchlist" )
def test_notify(self, username, blacklist_name=None): """ Sends a test notification to trakt with the given authentication info and returns a boolean representing success. api: The api string to use username: The username to use blacklist_name: slug of trakt list used to hide not interested show Returns: True if the request succeeded, False otherwise """ try: if blacklist_name and blacklist_name is not None: if not TraktAPI()["users/me/lists/{list}".format( list=blacklist_name)].get(): return "Trakt blacklist doesn't exists" return "Test notice sent successfully to Trakt" except Exception as e: sickrage.app.log.warning("Could not connect to Trakt service: %s" % e) return "Test notice failed to Trakt: %s" % e
def add_episodes_to_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "WATCHLIST::ADD::START - Look for Episodes to Add to Trakt Watchlist" ) for show_object in get_show_list(): for episode_object in show_object.episodes: if episode_object.status in Quality.SNATCHED + Quality.SNATCHED_PROPER + [ UNKNOWN, WANTED ]: continue trakt_id = IndexerApi(show_object.indexer).trakt_id if self._check_in_list(trakt_id, str(show_object.indexer_id), episode_object.season, episode_object.episode): sickrage.app.log.debug( "Adding Episode %s S%02dE%02d to watchlist" % (show_object.name, episode_object.season, episode_object.episode)) trakt_data.append( (show_object.indexer_id, show_object.indexer, show_object.name, show_object.startyear, episode_object.season, episode_object.episode)) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) TraktAPI()["sync/watchlist"].add(data) self._get_episode_watchlist() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error %s" % e) sickrage.app.log.debug( "WATCHLIST::ADD::FINISH - Look for Episodes to Add to Trakt Watchlist" )
def remove_show_from_trakt_library(self, show_obj): if self.find_show_match(show_obj.series_provider_id, show_obj.series_id): # URL parameters data = { 'shows': [{ 'title': show_obj.name, 'year': show_obj.startyear, 'ids': { show_obj.series_provider.trakt_id: show_obj.series_id } }] } sickrage.app.log.debug(f"Removing {show_obj.name} from tv library") try: TraktAPI()["sync/collection"].remove(data) except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Aborting removing show {show_obj.name} from Trakt library. Error: {repr(e)}" )
def add_show_to_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "SHOW_WATCHLIST::ADD::START - Look for Shows to Add to Trakt Watchlist" ) for show in get_show_list(): if not self._check_in_list( IndexerApi(show.indexer).trakt_id, str(show.indexer_id), 0, 0, 'Show'): sickrage.app.log.debug( "Adding Show: Indexer %s %s - %s to Watchlist" % (IndexerApi(show.indexer).trakt_id, str( show.indexer_id), show.name)) show_el = { 'title': show.name, 'year': show.startyear, 'ids': { IndexerApi(show.indexer).trakt_id: show.indexer_id } } trakt_data.append(show_el) if len(trakt_data): try: data = {'shows': trakt_data} TraktAPI()["sync/watchlist"].add(data) self._get_show_watchlist() except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.app.log.debug( "SHOW_WATCHLIST::ADD::FINISH - Look for Shows to Add to Trakt Watchlist" )
def add_show_to_trakt_watch_list(self): trakt_data = [] sickrage.app.log.debug( "SHOW_WATCHLIST::ADD::START - Look for Shows to Add to Trakt Watchlist" ) for show in get_show_list(): series_provider_trakt_id = show.series_provider.trakt_id if not self._check_in_list(series_provider_trakt_id, str(show.series_id), 0, 0, 'Show'): sickrage.app.log.debug( f"Adding Show: Series Provider {series_provider_trakt_id} {str(show.series_id)} - {show.name} to Watchlist" ) show_el = { 'title': show.name, 'year': show.startyear, 'ids': { series_provider_trakt_id: show.series_id } } trakt_data.append(show_el) if len(trakt_data): try: data = {'shows': trakt_data} TraktAPI()["sync/watchlist"].add(data) self._get_show_watchlist() except Exception as e: sickrage.app.log.warning( f"Could not connect to Trakt service. Error: {e}") sickrage.app.log.debug( "SHOW_WATCHLIST::ADD::FINISH - Look for Shows to Add to Trakt Watchlist" )
def remove_show_from_sick_rage(self): sickrage.app.log.debug( "SHOW_SICKRAGE::REMOVE::START - Look for Shows to remove from SiCKRAGE" ) for show in get_show_list(): if show.status == "Ended": try: progress = TraktAPI()["shows"].get(show.imdb_id) except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Aborting removing show %s from SiCKRAGE. Error: %s" % (show.name, repr(e))) return if progress.status in ['canceled', 'ended']: sickrage.app.show_queue.remove_show(show.indexer_id, full=True) sickrage.app.log.debug( "Show: %s has been removed from SiCKRAGE" % show.name) sickrage.app.log.debug( "SHOW_SICKRAGE::REMOVE::FINISH - Trakt Show Watchlist")
def remove_show_from_trakt_library(self, show_obj): if self.find_show_match(show_obj.indexer, show_obj.indexer_id): # URL parameters data = { 'shows': [{ 'title': show_obj.name, 'year': show_obj.startyear, 'ids': { IndexerApi(show_obj.indexer).trakt_id: show_obj.indexer_id } }] } sickrage.app.log.debug("Removing %s from tv library" % show_obj.name) try: TraktAPI()["sync/collection"].remove(data) except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service. Aborting removing show %s from Trakt library. Error: %s" % (show_obj.name, repr(e)))
def run(self): super(ShowTaskAdd, self).run() start_time = time.time() sickrage.app.log.info( "Started adding show {} from show dir: {}".format( self.show_name, self.show_dir)) series_provider_language = self.lang or sickrage.app.config.general.series_provider_default_language series_info = sickrage.app.series_providers[ self.series_provider_id].get_series_info( self.series_id, language=series_provider_language, enable_cache=False) if not series_info: sickrage.app.alerts.error( _("Unable to add show"), _("Unable to look up the show in {} on {} using ID {}, not using the NFO. Delete .nfo and try adding " "manually again.").format( self.show_dir, sickrage.app.series_providers[ self.series_provider_id].name, self.series_id)) if sickrage.app.config.trakt.enable: title = self.show_dir.split("/")[-1] data = { 'shows': [{ 'title': title, 'ids': { sickrage.app.series_providers[self.series_provider_id].trakt_id: self.series_id } }] } TraktAPI()["sync/watchlist"].remove(data) return self._finish_early() # this usually only happens if they have an NFO in their show dir which gave us a series id that has no # proper english version of the show try: series_info.name except AttributeError: sickrage.app.log.warning( f"Show in {self.show_dir} has no name on {sickrage.app.series_providers[self.series_provider_id].name}, " f"probably the wrong language used to search with") sickrage.app.alerts.error( _("Unable to add show"), _(f"Show in {self.show_dir} has no name on {sickrage.app.series_providers[self.series_provider_id].name}, " f"probably the wrong language. Delete .nfo and add manually in the correct language" )) return self._finish_early() # if the show has no episodes/seasons if not len(series_info): sickrage.app.log.warning("Show " + str(series_info['name']) + " is on " + str(sickrage.app.series_providers[ self.series_provider_id].name) + "but contains no season/episode data.") sickrage.app.alerts.error( _("Unable to add show"), _("Show ") + str(series_info['name']) + _(" is on ") + str(sickrage.app.series_providers[ self.series_provider_id].name) + _(" but contains no season/episode data.")) return self._finish_early() try: # add show to database show_obj = TVShow(self.series_id, self.series_provider_id, lang=self.lang, location=self.show_dir) # set up initial values show_obj.subtitles = self.subtitles if self.subtitles is not None else sickrage.app.config.subtitles.default show_obj.sub_use_sr_metadata = self.sub_use_sr_metadata if self.sub_use_sr_metadata is not None else False show_obj.quality = self.quality if self.quality is not None else sickrage.app.config.general.quality_default show_obj.flatten_folders = self.flatten_folders if self.flatten_folders is not None else sickrage.app.config.general.flatten_folders_default show_obj.scene = self.scene if self.scene is not None else sickrage.app.config.general.scene_default show_obj.anime = self.anime if self.anime is not None else sickrage.app.config.general.anime_default show_obj.dvd_order = self.dvd_order if self.dvd_order is not None else False show_obj.search_format = self.search_format if self.search_format is not None else sickrage.app.config.general.search_format_default show_obj.skip_downloaded = self.skip_downloaded if self.skip_downloaded is not None else sickrage.app.config.general.skip_downloaded_default show_obj.paused = self.paused if self.paused is not None else False # set up default new/missing episode status sickrage.app.log.info( "Setting all current episodes to the specified default status: " + str(self.default_status)) show_obj.default_ep_status = self.default_status # save to database show_obj.save() if show_obj.anime: if self.blacklist: show_obj.release_groups.set_black_keywords(self.blacklist) if self.whitelist: show_obj.release_groups.set_white_keywords(self.whitelist) except SeriesProviderException as e: sickrage.app.log.warning( _("Unable to add show due to an error with ") + sickrage.app.series_providers[self.series_provider_id].name + ": {}".format(e)) sickrage.app.alerts.error( _("Unable to add show due to an error with ") + sickrage.app.series_providers[self.series_provider_id].name + "") return self._finish_early() except MultipleShowObjectsException: sickrage.app.log.warning( _("The show in ") + self.show_dir + _(" is already in your show list, skipping")) sickrage.app.alerts.error( _('Show skipped'), _("The show in ") + self.show_dir + _(" is already in your show list")) return self._finish_early() except Exception as e: sickrage.app.log.error(_("Error trying to add show: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) raise self._finish_early() try: sickrage.app.log.debug( _("Attempting to retrieve show info from IMDb")) show_obj.load_imdb_info() except Exception as e: sickrage.app.log.debug(_("Error loading IMDb info: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) try: show_obj.load_episodes_from_series_provider() except Exception as e: sickrage.app.log.debug( _("Error with ") + show_obj.series_provider.name + _(", not creating episode list: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) try: show_obj.load_episodes_from_dir() except Exception as e: sickrage.app.log.debug( "Error searching dir for episodes: {}".format(e)) sickrage.app.log.debug(traceback.format_exc()) show_obj.write_metadata(force=True) show_obj.populate_cache() if sickrage.app.config.trakt.enable: # if there are specific episodes that need to be added by trakt sickrage.app.trakt_searcher.manage_new_show(show_obj) # add show to trakt.tv library if sickrage.app.config.trakt.sync: sickrage.app.trakt_searcher.add_show_to_trakt_library(show_obj) if sickrage.app.config.trakt.sync_watchlist: sickrage.app.log.info("update watchlist") sickrage.app.notification_providers['trakt'].update_watchlist( show_obj) # Retrieve scene exceptions show_obj.retrieve_scene_exceptions() # Load XEM data to DB for show xem_refresh(show_obj.series_id, show_obj.series_provider_id, force=True) # check if show has XEM mapping so we can determine if searches should go by scene numbering or series_provider_id # numbering. # if not self.scene and get_xem_numbering_for_show(show_obj.series_id, show_obj.series_provider_id): # show_obj.scene = 1 # if they set default ep status to WANTED then run the backlog to search for episodes if show_obj.default_ep_status == EpisodeStatus.WANTED: sickrage.app.log.info( _("Launching backlog for this show since it has episodes that are WANTED" )) sickrage.app.backlog_searcher.search_backlog( show_obj.series_id, show_obj.series_provider_id) show_obj.default_ep_status = self.default_status_after show_obj.save() WebSocketMessage('SHOW_ADDED', { 'seriesSlug': show_obj.slug, 'series': show_obj.to_json(progress=True) }).push() sickrage.app.log.info( "Finished adding show {} in {}s from show dir: {}".format( self.show_name, round(time.time() - start_time, 2), self.show_dir))
def run(self): start_time = time.time() sickrage.app.log.info( "Started adding show {} from show dir: {}".format( self.show_name, self.showDir)) index_name = IndexerApi(self.indexer).name # make sure the Indexer IDs are valid lINDEXER_API_PARMS = IndexerApi(self.indexer).api_params.copy() lINDEXER_API_PARMS['cache'] = False lINDEXER_API_PARMS[ 'language'] = self.lang or sickrage.app.config.indexer_default_language sickrage.app.log.info("{}: {}".format(index_name, repr(lINDEXER_API_PARMS))) t = IndexerApi(self.indexer).indexer(**lINDEXER_API_PARMS) s = t[self.indexer_id] if not s: sickrage.app.alerts.error( _("Unable to add show"), _("Unable to look up the show in {} on {} using ID {}, not using the NFO. Delete .nfo and try adding " "manually again.").format(self.showDir, index_name, self.indexer_id)) if sickrage.app.config.use_trakt: title = self.showDir.split("/")[-1] data = { 'shows': [{ 'title': title, 'ids': { IndexerApi(self.indexer).trakt_id: self.indexer_id } }] } TraktAPI()["sync/watchlist"].remove(data) return self._finish_early() # this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no # proper english version of the show try: s.seriesname except AttributeError: sickrage.app.log.warning( "Show in {} has no name on {}, probably the wrong language used to search with" .format(self.showDir, index_name)) sickrage.app.alerts.error( _("Unable to add show"), _("Show in {} has no name on {}, probably the wrong language. Delete .nfo " "and add manually in the correct language").format( self.showDir, index_name)) return self._finish_early() # if the show has no episodes/seasons if not len(s): sickrage.app.log.warning("Show " + str(s['seriesname']) + " is on " + str(IndexerApi(self.indexer).name) + "but contains no season/episode " "data.") sickrage.app.alerts.error( _("Unable to add show"), _("Show ") + str(s['seriesname']) + _(" is on ") + str(IndexerApi(self.indexer).name) + _(" but contains no season/episode data.")) return self._finish_early() try: # add show to database show_obj = TVShow(self.indexer_id, self.indexer, lang=self.lang, location=self.showDir) # set up initial values show_obj.subtitles = self.subtitles if self.subtitles is not None else sickrage.app.config.subtitles_default show_obj.sub_use_sr_metadata = self.sub_use_sr_metadata if self.sub_use_sr_metadata is not None else False show_obj.quality = self.quality if self.quality is not None else sickrage.app.config.quality_default show_obj.flatten_folders = self.flatten_folders if self.flatten_folders is not None else sickrage.app.config.flatten_folders_default show_obj.scene = self.scene if self.scene is not None else sickrage.app.config.scene_default show_obj.anime = self.anime if self.anime is not None else sickrage.app.config.anime_default show_obj.dvdorder = self.dvdorder if self.dvdorder is not None else False show_obj.search_format = self.search_format if self.search_format is not None else sickrage.app.config.search_format_default show_obj.skip_downloaded = self.skip_downloaded if self.skip_downloaded is not None else sickrage.app.config.skip_downloaded_default show_obj.paused = self.paused if self.paused is not None else False # set up default new/missing episode status sickrage.app.log.info( "Setting all current episodes to the specified default status: " + str(self.default_status)) show_obj.default_ep_status = self.default_status # save to database show_obj.save() if show_obj.anime: if self.blacklist: show_obj.release_groups.set_black_keywords(self.blacklist) if self.whitelist: show_obj.release_groups.set_white_keywords(self.whitelist) except indexer_exception as e: sickrage.app.log.warning( _("Unable to add show due to an error with ") + IndexerApi(self.indexer).name + ": {}".format(e)) sickrage.app.alerts.error( _("Unable to add show due to an error with ") + IndexerApi(self.indexer).name + "") return self._finish_early() except MultipleShowObjectsException: sickrage.app.log.warning( _("The show in ") + self.showDir + _(" is already in your show list, skipping")) sickrage.app.alerts.error( _('Show skipped'), _("The show in ") + self.showDir + _(" is already in your show list")) return self._finish_early() except Exception as e: sickrage.app.log.error(_("Error trying to add show: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) raise self._finish_early() try: sickrage.app.log.debug( _("Attempting to retrieve show info from IMDb")) show_obj.load_imdb_info() except Exception as e: sickrage.app.log.debug(_("Error loading IMDb info: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) try: show_obj.load_episodes_from_indexer() except Exception as e: sickrage.app.log.debug( _("Error with ") + IndexerApi(show_obj.indexer).name + _(", not creating episode list: {}").format(e)) sickrage.app.log.debug(traceback.format_exc()) try: show_obj.load_episodes_from_dir() except Exception as e: sickrage.app.log.debug( "Error searching dir for episodes: {}".format(e)) sickrage.app.log.debug(traceback.format_exc()) show_obj.write_metadata(force=True) show_obj.populate_cache() if sickrage.app.config.use_trakt: # if there are specific episodes that need to be added by trakt sickrage.app.trakt_searcher.manage_new_show(show_obj) # add show to trakt.tv library if sickrage.app.config.trakt_sync: sickrage.app.trakt_searcher.add_show_to_trakt_library(show_obj) if sickrage.app.config.trakt_sync_watchlist: sickrage.app.log.info("update watchlist") sickrage.app.notifier_providers['trakt'].update_watchlist( show_obj) # Retrieve scene exceptions show_obj.retrieve_scene_exceptions() # Load XEM data to DB for show xem_refresh(show_obj.indexer_id, show_obj.indexer, force=True) # check if show has XEM mapping so we can determine if searches should go by scene numbering or indexer # numbering. # if not self.scene and get_xem_numbering_for_show(show_obj.indexer_id, show_obj.indexer): # show_obj.scene = 1 # if they set default ep status to WANTED then run the backlog to search for episodes if show_obj.default_ep_status == WANTED: sickrage.app.log.info( _("Launching backlog for this show since it has episodes that are WANTED" )) sickrage.app.backlog_searcher.search_backlog(show_obj.indexer_id) show_obj.default_ep_status = self.default_status_after show_obj.save() sickrage.app.log.info( "Finished adding show {} in {}s from show dir: {}".format( self.show_name, round(time.time() - start_time, 2), self.showDir))
def update_watchlist(self, show_object=None, s=None, e=None, data_show=None, data_episode=None, update="add"): """ Sends a request to trakt indicating that the given episode is part of our library. show_obj: The TVShow object to add to trakt s: season number e: episode number data_show: structured object of shows traktv type data_episode: structured object of episodes traktv type update: type o action add or remove """ sickrage.app.log.debug( "Add episodes, showid: indexer_id {}, Title {} to Trak.tv Watchlist" .format(show_object.indexer_id, show_object.name)) if sickrage.app.config.use_trakt: data = {} try: # URL parameters if show_object is not None: data = { 'shows': [{ 'title': show_object.name, 'year': show_object.startyear, 'ids': { IndexerApi(show_object.indexer).trakt_id: show_object.indexer_id }, }] } elif data_show is not None: data.update(data_show) else: sickrage.app.log.warning( "there's a coding problem contact developer. It's needed to be provided " "at lest one of the two: data_show or show_obj") return False if data_episode is not None: data['shows'][0].update(data_episode) elif s is not None: # traktv URL parameters season = { 'season': [{ 'number': s, }] } if e is not None: # traktv URL parameters episode = {'episodes': [{'number': e}]} season['season'][0].update(episode) data['shows'][0].update(season) trakt_url = "sync/watchlist" if update == "remove": TraktAPI()[trakt_url].remove(data) else: TraktAPI()[trakt_url].add(data) except Exception as e: sickrage.app.log.warning( "Could not connect to Trakt service: %s" % e) return False return True