def get_indexer_absolute_numbering(indexer_id, indexer, sceneAbsoluteNumber, fallback_to_xem=True, scene_season=None): """ Returns a tuple, (season, episode, absolute_number) with the TVDB absolute numbering for (sceneAbsoluteNumber) (this works like the reverse of get_absolute_numbering) """ if indexer_id is None or sceneAbsoluteNumber is None: return sceneAbsoluteNumber indexer_id = int(indexer_id) indexer = int(indexer) if scene_season is None: rows = main_db.MainDB().select( "SELECT absolute_number FROM scene_numbering WHERE indexer = ? AND indexer_id = ? AND scene_absolute_number = ?", [indexer, indexer_id, sceneAbsoluteNumber]) else: rows = main_db.MainDB().select( "SELECT absolute_number FROM scene_numbering WHERE indexer = ? AND indexer_id = ? AND scene_absolute_number = ? AND scene_season = ?", [indexer, indexer_id, sceneAbsoluteNumber, scene_season]) if rows: return int(rows[0]["absolute_number"]) else: if fallback_to_xem: return get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNumber, scene_season) return sceneAbsoluteNumber
def setUp_test_db(force=False): """upgrades the db to the latest version """ global TESTDB_INITALIZED if not TESTDB_INITALIZED or force: # remove old db files tearDown_test_db() # upgrade main main_db.MainDB().InitialSchema().upgrade() # sanity check main main_db.MainDB().SanityCheck() # upgrade cache cache_db.CacheDB().InitialSchema().upgrade() # upgrade failed failed_db.FailedDB().InitialSchema().upgrade() # populate scene exceiptions table # retrieve_exceptions(False, False) TESTDB_INITALIZED = True
def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute_number=None, sceneSeason=None, sceneEpisode=None, sceneAbsolute=None): """ Set scene numbering for a season/episode. To clear the scene numbering, leave both sceneSeason and sceneEpisode as None. """ if indexer_id is None: return indexer_id = int(indexer_id) indexer = int(indexer) if season and episode: main_db.MainDB().action( "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)", [indexer, indexer_id, season, episode]) main_db.MainDB().action( "UPDATE scene_numbering SET scene_season = ?, scene_episode = ? WHERE indexer = ? AND indexer_id = ? AND season = ? AND episode = ?", [sceneSeason, sceneEpisode, indexer, indexer_id, season, episode]) elif absolute_number: main_db.MainDB().action( "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)", [indexer, indexer_id, absolute_number]) main_db.MainDB().action( "UPDATE scene_numbering SET scene_absolute_number = ? WHERE indexer = ? AND indexer_id = ? AND absolute_number = ?", [sceneAbsolute, indexer, indexer_id, absolute_number]) # Reload data from DB so that cache and db are in sync show = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id) show.flushEpisodes()
def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNumber, scene_season=None): """ Reverse of find_xem_numbering: lookup a tvdb season and episode using scene numbering :param indexer_id: int :param sceneAbsoluteNumber: int :return: int """ if indexer_id is None or sceneAbsoluteNumber is None: return sceneAbsoluteNumber indexer_id = int(indexer_id) indexer = int(indexer) xem_refresh(indexer_id, indexer) if scene_season is None: rows = main_db.MainDB().select( "SELECT absolute_number FROM tv_episodes WHERE indexer = ? AND showid = ? AND scene_absolute_number = ?", [indexer, indexer_id, sceneAbsoluteNumber]) else: rows = main_db.MainDB().select( "SELECT absolute_number FROM tv_episodes WHERE indexer = ? AND showid = ? AND scene_absolute_number = ? AND scene_season = ?", [indexer, indexer_id, sceneAbsoluteNumber, scene_season]) if rows: return int(rows[0]["absolute_number"]) return sceneAbsoluteNumber
def _set_lastBacklog(self, when): sickrage.LOGGER.debug("Setting the last backlog in the DB to " + str(when)) sqlResults = main_db.MainDB().select("SELECT * FROM info") if len(sqlResults) == 0: main_db.MainDB().action("INSERT INTO info (last_backlog, last_indexer) VALUES (?,?)", [str(when), 0]) else: main_db.MainDB().action("UPDATE info SET last_backlog=" + str(when))
def already_postprocessed(dirName, videofile, force, result): """ Check if we already post processed a file :param dirName: Directory a file resides in :param videofile: File name :param force: Force checking when already checking (currently unused) :param result: True if file is already postprocessed, False if not :return: """ if force: return False # Avoid processing the same dir again if we use a process method <> move if main_db.MainDB().select( "SELECT * FROM tv_episodes WHERE release_name = ?", [dirName]): # result.output += logHelper(u"You're trying to post process a dir that's already been processed, skipping", LOGGER.DEBUG) return True else: if main_db.MainDB().select( "SELECT * FROM tv_episodes WHERE release_name = ?", [videofile.rpartition('.')[0]]): # result.output += logHelper(u"You're trying to post process a video that's already been processed, skipping", LOGGER.DEBUG) return True # Needed if we have downloaded the same episode @ different quality # But we need to make sure we check the history of the episode we're going to PP, and not others np = NameParser(dirName, tryIndexers=True) try: parse_result = np.parse(dirName) except: parse_result = False search_sql = "SELECT tv_episodes.indexerid, history.resource FROM tv_episodes INNER JOIN history ON history.showid=tv_episodes.showid" # This part is always the same search_sql += " WHERE history.season=tv_episodes.season and history.episode=tv_episodes.episode" # If we find a showid, a season number, and one or more episode numbers then we need to use those in the query if parse_result and (parse_result.show.indexerid and parse_result.episode_numbers and parse_result.season_number): search_sql += " and tv_episodes.showid = '" + str( parse_result.show.indexerid ) + "' and tv_episodes.season = '" + str( parse_result.season_number ) + "' and tv_episodes.episode = '" + str( parse_result.episode_numbers[0]) + "'" search_sql += " and tv_episodes.status IN (" + ",".join( [str(x) for x in Quality.DOWNLOADED]) + ")" search_sql += " and history.resource LIKE ?" if main_db.MainDB().select(search_sql, ['%' + videofile]): # result.output += logHelper(u"You're trying to post process a video that's already been processed, skipping", LOGGER.DEBUG) return True return False
def get(self, limit=100, action=None): """ :param limit: The maximum number of elements to return :param action: The type of action to filter in the history. Either 'downloaded' or 'snatched'. Anything else or no value will return everything (up to ``limit``) :return: The last ``limit`` elements of type ``action`` in the history """ action = action.lower() if isinstance(action, str) else '' limit = int(limit) if action == 'downloaded': actions = Quality.DOWNLOADED elif action == 'snatched': actions = Quality.SNATCHED else: actions = [] common_sql = 'SELECT action, date, episode, provider, h.quality, resource, season, show_name, showid ' \ 'FROM history h, tv_shows s ' \ 'WHERE h.showid = s.indexer_id ' filter_sql = 'AND action in (' + ','.join(['?'] * len(actions)) + ') ' order_sql = 'ORDER BY date DESC ' if limit == 0: if len(actions) > 0: results = main_db.MainDB().select( common_sql + filter_sql + order_sql, actions) else: results = main_db.MainDB().select(common_sql + order_sql) else: if len(actions) > 0: results = main_db.MainDB().select( common_sql + filter_sql + order_sql + 'LIMIT ?', actions + [limit]) else: results = main_db.MainDB().select( common_sql + order_sql + 'LIMIT ?', [limit]) data = [] for result in results: data.append({ 'action': result[b'action'], 'date': result[b'date'], 'episode': result[b'episode'], 'provider': result[b'provider'], 'quality': result[b'quality'], 'resource': result[b'resource'], 'season': result[b'season'], 'show_id': result[b'showid'], 'show_name': result[b'show_name'] }) return data
def get_indexer_numbering(indexer_id, indexer, sceneSeason, sceneEpisode, fallback_to_xem=True): """ Returns a tuple, (season, episode) with the TVDB numbering for (sceneSeason, sceneEpisode) (this works like the reverse of get_scene_numbering) """ if indexer_id is None or sceneSeason is None or sceneEpisode is None: return sceneSeason, sceneEpisode indexer_id = int(indexer_id) indexer = int(indexer) rows = main_db.MainDB().select( "SELECT season, episode FROM scene_numbering WHERE indexer = ? AND indexer_id = ? AND scene_season = ? AND scene_episode = ?", [indexer, indexer_id, sceneSeason, sceneEpisode]) if rows: return int(rows[0][b"season"]), int(rows[0][b"episode"]) else: if fallback_to_xem: return get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode) return sceneSeason, sceneEpisode
def deleteEpisode(self, full=False): sickrage.LOGGER.debug("Deleting %s S%02dE%02d from the DB" % (self.show.name, self.season or 0, self.episode or 0)) # remove myself from the show dictionary if self.show.getEpisode(self.season, self.episode, noCreate=True) == self: sickrage.LOGGER.debug("Removing myself from my show's list") del self.show.episodes[self.season][self.episode] # delete myself from the DB sickrage.LOGGER.debug("Deleting myself from the database") sql = "DELETE FROM tv_episodes WHERE showid=" + str(self.show.indexerid) + " AND season=" + str( self.season) + " AND episode=" + str(self.episode) main_db.MainDB().action(sql) data = sickrage.NOTIFIERS.trakt_notifier.trakt_episode_data_generate([(self.season, self.episode)]) if sickrage.USE_TRAKT and sickrage.TRAKT_SYNC_WATCHLIST and data: sickrage.LOGGER.debug("Deleting myself from Trakt") sickrage.NOTIFIERS.trakt_notifier.update_watchlist(self.show, data_episode=data, update="remove") if full: sickrage.LOGGER.info('Attempt to delete episode file %s' % self._location) try: os.remove(self._location) except OSError as e: sickrage.LOGGER.warning('Unable to delete %s: %s / %s' % (self._location, repr(e), str(e))) raise EpisodeDeletedException()
def findPropers(self, search_date=datetime.datetime.today()): results = [] sqlResults = main_db.MainDB().select( 'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' + ' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' + ' WHERE e.airdate >= ' + str(search_date.toordinal()) + ' AND e.status IN (' + ','.join([ str(x) for x in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST ]) + ')') for sqlshow in sqlResults or []: show = findCertainShow(sickrage.srCore.SHOWLIST, int(sqlshow["showid"])) if show: curEp = show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"])) for term in self.proper_strings: searchString = self._get_episode_search_strings( curEp, add_string=term) for item in self.search(searchString[0]): title, url = self._get_title_and_url(item) results.append( Proper(title, url, datetime.datetime.today(), show)) return results
def findPropers(self, search_date=datetime.datetime.today()): results = [] sqlResults = main_db.MainDB().select( 'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' + ' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' + ' WHERE e.airdate >= ' + str(search_date.toordinal()) + ' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' + ' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))' ) if not sqlResults: return [] for sqlshow in sqlResults: self.show = findCertainShow(sickrage.srCore.SHOWLIST, int(sqlshow["showid"])) if self.show: curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"])) searchStrings = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK') for searchString in searchStrings: for item in self.search(searchString): title, url = self._get_title_and_url(item) if re.match(r'.*(REPACK|PROPER).*', title, re.I): results.append(Proper(title, url, datetime.datetime.today(), self.show)) return results
def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode): """ Reverse of find_xem_numbering: lookup a tvdb season and episode using scene numbering :param indexer_id: int :param sceneSeason: int :param sceneEpisode: int :return: (int, int) a tuple of (season, episode) """ if indexer_id is None or sceneSeason is None or sceneEpisode is None: return sceneSeason, sceneEpisode indexer_id = int(indexer_id) indexer = int(indexer) xem_refresh(indexer_id, indexer) rows = main_db.MainDB().select( "SELECT season, episode FROM tv_episodes WHERE indexer = ? AND showid = ? AND scene_season = ? AND scene_episode = ?", [indexer, indexer_id, sceneSeason, sceneEpisode]) if rows: return int(rows[0]["season"]), int(rows[0]["episode"]) return sceneSeason, sceneEpisode
def _logHistoryItem(action, showid, season, episode, quality, resource, provider, version=-1): """ Insert a history item in DB :param action: action taken (snatch, download, etc) :param showid: showid this entry is about :param season: show season :param episode: show episode :param quality: media quality :param resource: resource used :param provider: provider used :param version: tracked version of file (defaults to -1) """ logDate = datetime.datetime.today().strftime(History.date_format) resource = resource main_db.MainDB().action( "INSERT INTO history (action, date, showid, season, episode, quality, resource, provider, version) VALUES (?,?,?,?,?,?,?,?,?)", [ action, logDate, showid, season, episode, quality, resource, provider, version ])
def get_xem_absolute_numbering_for_show(indexer_id, indexer): """ Returns a dict of (season, episode) : (sceneSeason, sceneEpisode) mappings for an entire show. Both the keys and values of the dict are tuples. Will be empty if there are no scene numbers set in xem """ if indexer_id is None: return {} indexer_id = int(indexer_id) indexer = int(indexer) xem_refresh(indexer_id, indexer) result = {} rows = main_db.MainDB().select( 'SELECT absolute_number, scene_absolute_number FROM tv_episodes WHERE indexer = ? AND showid = ? AND scene_absolute_number != 0 ORDER BY absolute_number', [indexer, indexer_id]) for row in rows: absolute_number = int(row['absolute_number']) scene_absolute_number = int(row['scene_absolute_number']) result[absolute_number] = scene_absolute_number return result
def get_absolute_number_from_season_and_episode(show, season, episode): """ Find the absolute number for a show episode :param show: Show object :param season: Season number :param episode: Episode number :return: The absolute number """ absolute_number = None if season and episode: sql = "SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?" sqlResults = main_db.MainDB().select(sql, [show.indexerid, season, episode]) if len(sqlResults) == 1: absolute_number = int(sqlResults[0]["absolute_number"]) sickrage.srCore.srLogger.debug( "Found absolute number %s for show %s S%02dE%02d" % (absolute_number, show.name, season, episode)) else: sickrage.srCore.srLogger.debug( "No entries for absolute number for show %s S%02dE%02d" % (show.name, season, episode)) return absolute_number
def get_xem_numbering_for_show(indexer_id, indexer): """ Returns a dict of (season, episode) : (sceneSeason, sceneEpisode) mappings for an entire show. Both the keys and values of the dict are tuples. Will be empty if there are no scene numbers set in xem """ if indexer_id is None: return {} indexer_id = int(indexer_id) indexer = int(indexer) xem_refresh(indexer_id, indexer) rows = main_db.MainDB().select( 'SELECT season, episode, scene_season, scene_episode FROM tv_episodes WHERE indexer = ? AND showid = ? AND (scene_season OR scene_episode) != 0 ORDER BY season, episode', [indexer, indexer_id]) result = {} for row in rows: season = int(row['season']) episode = int(row['episode']) scene_season = int(row['scene_season']) scene_episode = int(row['scene_episode']) result[(season, episode)] = (scene_season, scene_episode) return result
def searchDBForShow(regShowName, log=False): """ Searches if show names are present in the DB :param regShowName: list of show names to look for :param log: Boolean, log debug results of search (defaults to False) :return: Indexer ID of found show """ showNames = [re.sub('[. -]', ' ', regShowName)] yearRegex = r"([^()]+?)\s*(\()?(\d{4})(?(2)\))$" for showName in showNames: sqlResults = main_db.MainDB().select( "SELECT * FROM tv_shows WHERE show_name LIKE ?", [showName]) if len(sqlResults) == 1: return int(sqlResults[0]["indexer_id"]) else: # if we didn't get exactly one result then try again with the year stripped off if possible match = re.match(yearRegex, showName) if match and match.group(1): if log: sickrage.srCore.srLogger.debug( "Unable to match original name but trying to manually strip and specify show year" ) sqlResults = main_db.MainDB().select( "SELECT * FROM tv_shows WHERE (show_name LIKE ?) AND startyear = ?", [match.group(1) + '%', match.group(3)]) if len(sqlResults) == 0: if log: sickrage.srCore.srLogger.debug( "Unable to match a record in the DB for " + showName) continue elif len(sqlResults) > 1: if log: sickrage.srCore.srLogger.debug( "Multiple results for " + showName + " in the DB, unable to match show name") continue else: return int(sqlResults[0]["indexer_id"])
def _del_all_keywords(self, table): """ DB: Remove all keywords for current show :param table: SQL table remove keywords from """ main_db.MainDB().action( 'DELETE FROM [' + table + '] WHERE show_id = ?', [self.show_id])
def clear(self): """ Clear all the history """ main_db.MainDB().action( 'DELETE ' 'FROM history ' 'WHERE 1 = 1' )
def _set_lastProperSearch(self, when): """ Record last propersearch in DB :param when: When was the last proper search """ sickrage.srCore.srLogger.debug( "Setting the last Proper search in the DB to " + str(when)) sqlResults = main_db.MainDB().select("SELECT * FROM info") if len(sqlResults) == 0: main_db.MainDB().action( "INSERT INTO info (last_backlog, last_indexer, last_proper_search) VALUES (?,?,?)", [0, 0, str(when)]) else: main_db.MainDB().action("UPDATE info SET last_proper_search=" + str(when))
def run(self, force=False): if self.amActive: return self.amActive = True update_datetime = datetime.datetime.now() update_date = update_datetime.date() if sickrage.USE_FAILED_DOWNLOADS: FailedHistory.trimHistory() sickrage.LOGGER.info("Doing full update on all shows") # select 10 'Ended' tv_shows updated more than 90 days ago to include in this update stale_should_update = [] stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal() # last_update_date <= 90 days, sorted ASC because dates are ordinal sql_result = main_db.MainDB().select( "SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;", [stale_update_date]) for cur_result in sql_result: stale_should_update.append(int(cur_result[b'indexer_id'])) # start update process piList = [] for curShow in sickrage.showList: try: # get next episode airdate curShow.nextEpisode() # if should_update returns True (not 'Ended') or show is selected stale 'Ended' then update, otherwise just refresh if curShow.should_update(update_date=update_date) or curShow.indexerid in stale_should_update: try: piList.append( sickrage.SHOWQUEUE.updateShow(curShow, True)) # @UndefinedVariable except CantUpdateShowException as e: sickrage.LOGGER.debug("Unable to update show: {0}".format(str(e))) else: sickrage.LOGGER.debug( "Not updating episodes for show " + curShow.name + " because it's marked as ended and last/next episode is not within the grace period.") piList.append( sickrage.SHOWQUEUE.refreshShow(curShow, True)) # @UndefinedVariable except (CantUpdateShowException, CantRefreshShowException) as e: sickrage.LOGGER.error("Automatic update failed: {}".format(e)) ProgressIndicators.setIndicator('dailyUpdate', QueueProgressIndicator("Daily Update", piList)) sickrage.LOGGER.info("Completed full update on all shows") self.amActive = False
def _add_keywords(self, table, values): """ DB: Adds keywords into database for current show :param table: SQL table to add keywords to :param values: Values to be inserted in table """ for value in values: main_db.MainDB().action( 'INSERT INTO [' + table + '] (show_id, keyword) VALUES (?,?)', [self.show_id, value])
def trim(self): """ Remove all elements older than 30 days from the history """ main_db.MainDB().action( 'DELETE ' 'FROM history ' 'WHERE date < ?', [(datetime.today() - timedelta(days=30)).strftime(History.date_format)] )
def loadFromDB(self): """ Populates the showList with shows from the database """ sqlResults = main_db.MainDB().select("SELECT * FROM tv_shows") for sqlShow in sqlResults: try: curShow = TVShow(int(sqlShow[b"indexer"]), int(sqlShow[b"indexer_id"])) sickrage.showList.append(curShow) except Exception as e: print "There was an error creating the show"
def makeSceneSearchString(show, ep_obj): numseasons = 0 numseasonsSQlResult = main_db.MainDB().select( "SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0", [show.indexerid]) if numseasonsSQlResult: numseasons = int(numseasonsSQlResult[0][0]) # see if we should use dates instead of episodes if (show.air_by_date or show.sports) and ep_obj.airdate != date.fromordinal(1): epStrings = [str(ep_obj.airdate)] elif show.is_anime: epStrings = [ "%02i" % int(ep_obj.scene_absolute_number if ep_obj.scene_absolute_number > 0 else ep_obj.scene_episode) ] else: epStrings = [ "S%02iE%02i" % (int(ep_obj.scene_season), int(ep_obj.scene_episode)), "%ix%02i" % (int(ep_obj.scene_season), int(ep_obj.scene_episode)) ] # for single-season shows just search for the show name -- if total ep count (exclude s0) is less than 11 # due to the amount of qualities and releases, it is easy to go over the 50 result limit on rss feeds otherwise if numseasons == 1 and not ep_obj.show.is_anime: epStrings = [''] showNames = set(makeSceneShowSearchStrings(show, ep_obj.scene_season)) toReturn = [] for curShow in showNames: for curEpString in epStrings: if ep_obj.show.is_anime: if ep_obj.show.release_groups is not None: if len(ep_obj.show.release_groups.whitelist) > 0: for keyword in ep_obj.show.release_groups.whitelist: toReturn.append(keyword + '.' + curShow + '.' + curEpString) elif len(ep_obj.show.release_groups.blacklist) == 0: # If we have neither whitelist or blacklist we just append what we have toReturn.append(curShow + '.' + curEpString) else: toReturn.append(curShow + '.' + curEpString) return toReturn
def setUp_test_db(): """upgrades the db to the latest version """ global TESTDB_INITALIZED if not TESTDB_INITALIZED: # remove old db files tearDown_test_db() # upgrading the db main_db.MainDB().InitialSchema().upgrade() # fix up any db problems main_db.MainDB().SanityCheck() # and for cachedb too cache_db.CacheDB().InitialSchema().upgrade() # and for faileddb too failed_db.FailedDB().InitialSchema().upgrade() TESTDB_INITALIZED = True
def _get_lastProperSearch(): """ Find last propersearch from DB """ sqlResults = main_db.MainDB().select("SELECT * FROM info") try: last_proper_search = datetime.date.fromordinal( int(sqlResults[0]["last_proper_search"])) except: return datetime.date.fromordinal(1) return last_proper_search
def removeEpisodeFromTraktCollection(self): if sickrage.srCore.srConfig.TRAKT_SYNC_REMOVE and sickrage.srCore.srConfig.TRAKT_SYNC and sickrage.srCore.srConfig.USE_TRAKT: sickrage.srCore.srLogger.debug( "COLLECTION::REMOVE::START - Look for Episodes to Remove From Trakt Collection" ) sql_selection = 'SELECT tv_shows.indexer, tv_shows.startyear, showid, show_name, season, episode, tv_episodes.status, tv_episodes.location FROM tv_episodes,tv_shows WHERE tv_shows.indexer_id = tv_episodes.showid' episodes = main_db.MainDB().select(sql_selection) if episodes is not None: trakt_data = [] for cur_episode in episodes: trakt_id = srIndexerApi( cur_episode["indexer"]).config['trakt_id'] if self._checkInList(trakt_id, str(cur_episode["showid"]), str(cur_episode["season"]), str(cur_episode["episode"]), List='Collection'): if cur_episode["location"] == '': sickrage.srCore.srLogger.debug( "Removing Episode %s S%02dE%02d from collection" % (cur_episode["show_name"], cur_episode["season"], cur_episode["episode"])) trakt_data.append( (cur_episode["showid"], cur_episode["indexer"], cur_episode["show_name"], cur_episode["startyear"], cur_episode["season"], cur_episode["episode"])) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) self.trakt_api.traktRequest("sync/collection/remove", data, method='POST') self._getShowCollection() except traktException as e: sickrage.srCore.srLogger.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.srCore.srLogger.debug( "COLLECTION::REMOVE::FINISH - Look for Episodes to Remove From Trakt Collection" )
def removeEpisodeFromTraktWatchList(self): if sickrage.srCore.srConfig.TRAKT_SYNC_WATCHLIST and sickrage.srCore.srConfig.USE_TRAKT: sickrage.srCore.srLogger.debug( "WATCHLIST::REMOVE::START - Look for Episodes to Remove from Trakt Watchlist" ) sql_selection = 'SELECT tv_shows.indexer, tv_shows.startyear, showid, show_name, season, episode, tv_episodes.status FROM tv_episodes,tv_shows WHERE tv_shows.indexer_id = tv_episodes.showid' episodes = main_db.MainDB().select(sql_selection) if episodes is not None: trakt_data = [] for cur_episode in episodes: trakt_id = srIndexerApi( cur_episode["indexer"]).config['trakt_id'] if self._checkInList( trakt_id, str(cur_episode["showid"]), str(cur_episode["season"]), str(cur_episode["episode"]) ) and cur_episode[ "status"] not in Quality.SNATCHED + Quality.SNATCHED_PROPER + [ UNKNOWN ] + [WANTED]: sickrage.srCore.srLogger.debug( "Removing Episode %s S%02dE%02d from watchlist" % (cur_episode["show_name"], cur_episode["season"], cur_episode["episode"])) trakt_data.append( (cur_episode["showid"], cur_episode["indexer"], cur_episode["show_name"], cur_episode["startyear"], cur_episode["season"], cur_episode["episode"])) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) self.trakt_api.traktRequest("sync/watchlist/remove", data, method='POST') self._getEpisodeWatchlist() except traktException as e: sickrage.srCore.srLogger.warning( "Could not connect to Trakt service. Error: %s" % e) sickrage.srCore.srLogger.debug( "WATCHLIST::REMOVE::FINISH - Look for Episodes to Remove from Trakt Watchlist" )
def addEpisodeToTraktWatchList(self): if sickrage.srCore.srConfig.TRAKT_SYNC_WATCHLIST and sickrage.srCore.srConfig.USE_TRAKT: sickrage.srCore.srLogger.debug( "WATCHLIST::ADD::START - Look for Episodes to Add to Trakt Watchlist" ) sql_selection = 'SELECT tv_shows.indexer, tv_shows.startyear, showid, show_name, season, episode FROM tv_episodes,tv_shows WHERE tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status IN (' + ','.join( [ str(x) for x in Quality.SNATCHED + Quality.SNATCHED_PROPER + [WANTED] ]) + ')' episodes = main_db.MainDB().select(sql_selection) if episodes is not None: trakt_data = [] for cur_episode in episodes: trakt_id = srIndexerApi( cur_episode["indexer"]).config['trakt_id'] if not self._checkInList(trakt_id, str(cur_episode["showid"]), str(cur_episode["season"]), str(cur_episode["episode"])): sickrage.srCore.srLogger.debug( "Adding Episode %s S%02dE%02d to watchlist" % (cur_episode["show_name"], cur_episode["season"], cur_episode["episode"])) trakt_data.append( (cur_episode["showid"], cur_episode["indexer"], cur_episode["show_name"], cur_episode["startyear"], cur_episode["season"], cur_episode["episode"])) if len(trakt_data): try: data = self.trakt_bulk_data_generate(trakt_data) self.trakt_api.traktRequest("sync/watchlist", data, method='POST') self._getEpisodeWatchlist() except traktException as e: sickrage.srCore.srLogger.warning( "Could not connect to Trakt service. Error %s" % e) sickrage.srCore.srLogger.debug( "WATCHLIST::ADD::FINISH - Look for Episodes to Add to Trakt Watchlist" )