def isFinalResult(result): """ Checks if the given result is good enough quality that we can stop searching for other ones. If the result is the highest quality in both the any/best quality lists then this function returns True, if not then it's False """ sickrage.srCore.srLogger.debug("Checking if we should keep searching after we've found " + result.name) show_obj = result.episodes[0].show any_qualities, best_qualities = Quality.splitQuality(show_obj.quality) # if there is a redownload that's higher than this then we definitely need to keep looking if best_qualities and result.quality < max(best_qualities): return False # if it does not match the shows black and white list its no good elif show_obj.is_anime and show_obj.release_groups.is_valid(result): return False # if there's no redownload that's higher (above) and this is the highest initial download then we're good elif any_qualities and result.quality in any_qualities: return True elif best_qualities and result.quality == max(best_qualities): return True # if we got here than it's either not on the lists, they're empty, or it's lower than the highest required else: return False
def isFinalResult(result): """ Checks if the given result is good enough quality that we can stop searching for other ones. If the result is the highest quality in both the any/best quality lists then this function returns True, if not then it's False """ sickrage.app.log.debug( "Checking if we should keep searching after we've found " + result.name) show_obj = result.episodes[0].show any_qualities, best_qualities = Quality.splitQuality(show_obj.quality) # if there is a redownload that's higher than this then we definitely need to keep looking if best_qualities and result.quality < max(best_qualities): return False # if it does not match the shows black and white list its no good elif show_obj.is_anime and show_obj.release_groups.is_valid(result): return False # if there's no redownload that's higher (above) and this is the highest initial download then we're good elif any_qualities and result.quality in any_qualities: return True elif best_qualities and result.quality == max(best_qualities): return True # if we got here than it's either not on the lists, they're empty, or it's lower than the highest required else: return False
def wantedEpisodes(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ wanted = [] anyQualities, bestQualities = Quality.splitQuality(show.quality) # @UnusedVariable allQualities = list(set(anyQualities + bestQualities)) sickrage.srCore.srLogger.debug("Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any for dbData in [x['doc'] for x in sickrage.srCore.mainDB.db.get_many('tv_episodes', show.indexerid, with_doc=True) if x['doc']['season'] > 0 and x['doc']['airdate'] > fromDate.toordinal()]: curCompositeStatus = int(dbData["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(allQualities) else: highestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(dbData["season"]), int(dbData["episode"])) epObj.wantedQuality = [i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN)] wanted.append(epObj) return wanted
def _get_segments(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ wanted = [] anyQualities, bestQualities = Quality.splitQuality(show.quality) allQualities = list(set(anyQualities + bestQualities)) sickrage.app.log.debug("Seeing if we need anything from {}".format( show.name)) # check through the list of statuses to see if we want any for dbData in sickrage.app.main_db.get_many('tv_episodes', show.indexerid): if dbData['season'] > 0 and dbData[ 'airdate'] >= fromDate.toordinal(): curStatus, curQuality = Quality.splitCompositeStatus( int(dbData["status"] or -1)) # if we need a better one then say yes if curStatus not in (WANTED, DOWNLOADED, SNATCHED, SNATCHED_PROPER): continue if curStatus != WANTED: if bestQualities: if curQuality in bestQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max( bestQualities): continue else: if curQuality in anyQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max( anyQualities): continue # skip upgrading quality of downloaded episodes if enabled if curStatus == DOWNLOADED and show.skip_downloaded: continue epObj = show.getEpisode(int(dbData["season"]), int(dbData["episode"])) epObj.wantedQuality = [ i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN) ] wanted.append(epObj) return wanted
def isFirstBestMatch(result): """ Checks if the given result is a best quality match and if we want to archive the episode on first match. """ sickrage.LOGGER.debug("Checking if we should archive our first best quality match for for episode " + result.name) show_obj = result.episodes[0].show any_qualities, best_qualities = Quality.splitQuality(show_obj.quality) # if there is a redownload that's a match to one of our best qualities and we want to archive the episode then we are done if best_qualities and show_obj.archive_firstmatch and result.quality in best_qualities: return True return False
def _get_segments(self, show, fromDate): if show.paused: sickrage.srCore.srLogger.debug( "Skipping backlog for {show_name} because the show is paused". format(show_name=show.name)) return {} anyQualities, bestQualities = Quality.splitQuality( show.quality) # @UnusedVariable sickrage.srCore.srLogger.debug( "Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any wanted = {} for result in [ x['doc'] for x in sickrage.srCore.mainDB.db.get_many( 'tv_episodes', show.indexerid, with_doc=True) if x['doc']['season'] > 0 and x['doc']['airdate'] > fromDate.toordinal() ]: curCompositeStatus = int(result["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus( curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) lowestBestQuality = min(bestQualities) else: highestBestQuality = 0 lowestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(result["season"]), int(result["episode"])) # only fetch if not archive on first match, or if show is lowest than the lower expected quality if (epObj.show.archive_firstmatch == 0 or curQuality < lowestBestQuality): if epObj.season not in wanted: wanted[epObj.season] = [epObj] else: wanted[epObj.season].append(epObj) return wanted
def wantedEpisodes(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ wanted = [] anyQualities, bestQualities = Quality.splitQuality( show.quality) # @UnusedVariable allQualities = list(set(anyQualities + bestQualities)) sickrage.srCore.srLogger.debug("Seeing if we need anything from {}".format( show.name)) sqlResults = main_db.MainDB().select( "SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 AND airdate > ?", [show.indexerid, fromDate.toordinal()]) sickrage.srCore.srLogger.debug("Found {} episode(s) needed for {}".format( len(sqlResults), show.name)) # check through the list of statuses to see if we want any for result in sqlResults: curCompositeStatus = int(result["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus( curCompositeStatus) if bestQualities: highestBestQuality = max(allQualities) else: highestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(result["season"]), int(result["episode"])) epObj.wantedQuality = [ i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN) ] wanted.append(epObj) return wanted
def isFirstBestMatch(result): """ Checks if the given result is a best quality match and if we want to archive the episode on first match. """ sickrage.srCore.srLogger.debug( "Checking if we should archive our first best quality match for episode " + result.name) show_obj = result.episodes[0].show any_qualities, best_qualities = Quality.splitQuality(show_obj.quality) # if there is a redownload that's a match to one of our best qualities and we want to archive the episode then we are done if best_qualities and show_obj.archive_firstmatch and result.quality in best_qualities: return True return False
def _get_segments(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ wanted = [] anyQualities, bestQualities = Quality.splitQuality(show.quality) allQualities = list(set(anyQualities + bestQualities)) sickrage.app.log.debug("Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any for dbData in sickrage.app.main_db.get_many('tv_episodes', show.indexerid): if dbData['season'] > 0 and dbData['airdate'] >= fromDate.toordinal(): curStatus, curQuality = Quality.splitCompositeStatus(int(dbData["status"] or -1)) # if we need a better one then say yes if curStatus not in (WANTED, DOWNLOADED, SNATCHED, SNATCHED_PROPER): continue if curStatus != WANTED: if bestQualities: if curQuality in bestQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max(bestQualities): continue else: if curQuality in anyQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max(anyQualities): continue # skip upgrading quality of downloaded episodes if enabled if curStatus == DOWNLOADED and show.skip_downloaded: continue epObj = show.get_episode(int(dbData["season"]), int(dbData["episode"])) epObj.wantedQuality = [i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN)] wanted.append(epObj) return wanted
def _get_segments(self, show, from_date): anyQualities, bestQualities = Quality.splitQuality(show.quality) sickrage.app.log.debug("Seeing if we need anything from {}".format( show.name)) # check through the list of statuses to see if we want any wanted = [] for result in (x for x in sickrage.app.main_db.get_many( 'tv_episodes', show.indexerid) if x['season'] > 0 and datetime.date.today().toordinal( ) > x['airdate'] >= from_date.toordinal()): curStatus, curQuality = Quality.splitCompositeStatus( int(result["status"] or -1)) # if we need a better one then say yes if curStatus not in { WANTED, DOWNLOADED, SNATCHED, SNATCHED_PROPER }: continue if curStatus != WANTED: if bestQualities: if curQuality in bestQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max( bestQualities): continue else: if curQuality in anyQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max( anyQualities): continue # skip upgrading quality of downloaded episodes if enabled if curStatus == DOWNLOADED and show.skip_downloaded: continue epObj = show.getEpisode(int(result["season"]), int(result["episode"])) wanted.append(epObj) return wanted
def _get_segments(self, show, fromDate): if show.paused: sickrage.srCore.srLogger.debug("Skipping backlog for {show_name} because the show is paused".format(show_name=show.name)) return {} anyQualities, bestQualities = Quality.splitQuality(show.quality) # @UnusedVariable sickrage.srCore.srLogger.debug("Seeing if we need anything from {}".format(show.name)) sqlResults = main_db.MainDB().select( "SELECT status, season, episode FROM tv_episodes WHERE season > 0 AND airdate > ? AND showid = ?", [fromDate.toordinal(), show.indexerid]) # check through the list of statuses to see if we want any wanted = {} for result in sqlResults: curCompositeStatus = int(result["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) lowestBestQuality = min(bestQualities) else: highestBestQuality = 0 lowestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(result["season"]), int(result["episode"])) # only fetch if not archive on first match, or if show is lowest than the lower expected quality if (epObj.show.archive_firstmatch == 0 or curQuality < lowestBestQuality): if epObj.season not in wanted: wanted[epObj.season] = [epObj] else: wanted[epObj.season].append(epObj) return wanted
def _get_segments(self, show, fromDate): if show.paused: sickrage.LOGGER.debug("Skipping backlog for {show_name} because the show is paused".format(show_name=show.name)) return {} anyQualities, bestQualities = Quality.splitQuality(show.quality) # @UnusedVariable sickrage.LOGGER.debug("Seeing if we need anything from {show_name}".format(show_name=show.name)) sqlResults = main_db.MainDB().select( "SELECT status, season, episode FROM tv_episodes WHERE season > 0 AND airdate > ? AND showid = ?", [fromDate.toordinal(), show.indexerid]) # check through the list of statuses to see if we want any wanted = {} for result in sqlResults: curCompositeStatus = int(result[b"status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) lowestBestQuality = min(bestQualities) else: highestBestQuality = 0 lowestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(result[b"season"]), int(result[b"episode"])) # only fetch if not archive on first match, or if show is lowest than the lower expected quality if (epObj.show.archive_firstmatch == 0 or curQuality < lowestBestQuality): if epObj.season not in wanted: wanted[epObj.season] = [epObj] else: wanted[epObj.season].append(epObj) return wanted
def wantedEpisodes(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ anyQualities, bestQualities = Quality.splitQuality(show.quality) # @UnusedVariable allQualities = list(set(anyQualities + bestQualities)) sickrage.LOGGER.debug("Seeing if we need anything from " + show.name) sqlResults = main_db.MainDB().select( "SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 AND airdate > ?", [show.indexerid, fromDate.toordinal()], ) # check through the list of statuses to see if we want any wanted = [] for result in sqlResults: curCompositeStatus = int(result[b"status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(allQualities) else: highestBestQuality = 0 # if we need a better one then say yes if ( curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality ) or curStatus == WANTED: epObj = show.getEpisode(int(result[b"season"]), int(result[b"episode"])) epObj.wantedQuality = [i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN)] wanted.append(epObj) return wanted
def wantedEpisodes(show, fromDate): """ Get a list of episodes that we want to download :param show: Show these episodes are from :param fromDate: Search from a certain date :return: list of wanted episodes """ wanted = [] if show.paused: sickrage.app.log.debug("Not checking for episodes of {} because the show is paused".format(show.name)) return wanted anyQualities, bestQualities = Quality.splitQuality(show.quality) allQualities = list(set(anyQualities + bestQualities)) sickrage.app.log.debug("Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any for dbData in [x['doc'] for x in sickrage.app.main_db.db.get_many('tv_episodes', show.indexerid, with_doc=True) if x['doc']['season'] > 0 and x['doc']['airdate'] > fromDate.toordinal()]: curCompositeStatus = int(dbData["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(allQualities) else: highestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(dbData["season"]), int(dbData["episode"])) epObj.wantedQuality = [i for i in allQualities if (i > curQuality and i != Quality.UNKNOWN)] wanted.append(epObj) return wanted
def _get_segments(self, show, fromDate): if show.paused: sickrage.app.log.debug( "Skipping backlog for {show_name} because the show is paused".format(show_name=show.name)) return {} anyQualities, bestQualities = Quality.splitQuality(show.quality) sickrage.app.log.debug("Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any wanted = {} for result in [x['doc'] for x in sickrage.app.main_db.db.get_many('tv_episodes', show.indexerid, with_doc=True) if x['doc']['season'] > 0 and x['doc']['airdate'] > fromDate.toordinal()]: curCompositeStatus = int(result["status"] or -1) curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) lowestBestQuality = min(bestQualities) else: highestBestQuality = 0 lowestBestQuality = 0 # if we need a better one then say yes if (curStatus in (DOWNLOADED, SNATCHED, SNATCHED_PROPER) and curQuality < highestBestQuality) or curStatus == WANTED: epObj = show.getEpisode(int(result["season"]), int(result["episode"])) # only fetch if not archive on first match, or if show is lowest than the lower expected quality if epObj.show.archive_firstmatch == 0 or curQuality < lowestBestQuality: if epObj.season not in wanted: wanted[epObj.season] = [epObj] else: wanted[epObj.season].append(epObj) return wanted
def _get_segments(show, from_date): anyQualities, bestQualities = Quality.splitQuality(show.quality) sickrage.app.log.debug("Seeing if we need anything from {}".format(show.name)) # check through the list of statuses to see if we want any wanted = [] for result in (x for x in sickrage.app.main_db.get_many('tv_episodes', show.indexerid) if x['season'] > 0 and datetime.date.today().toordinal() > x['airdate'] >= from_date.toordinal()): curStatus, curQuality = Quality.splitCompositeStatus(int(result["status"] or -1)) # if we need a better one then say yes if curStatus not in {WANTED, DOWNLOADED, SNATCHED, SNATCHED_PROPER}: continue if curStatus != WANTED: if bestQualities: if curQuality in bestQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max(bestQualities): continue else: if curQuality in anyQualities: continue elif curQuality != Quality.UNKNOWN and curQuality > max(anyQualities): continue # skip upgrading quality of downloaded episodes if enabled if curStatus == DOWNLOADED and show.skip_downloaded: continue epObj = show.get_episode(int(result["season"]), int(result["episode"])) wanted.append(epObj) return wanted
def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None): numseasons = 0 if show.air_by_date or show.sports: # the search string for air by date shows is just seasonStrings = [str(ep_obj.airdate).split('-')[0]] elif show.is_anime: seasonEps = show.get_all_episodes(ep_obj.season) # get show qualities anyQualities, bestQualities = Quality.splitQuality(show.quality) # compile a list of all the episode numbers we need in this 'season' seasonStrings = [] for episode in seasonEps: # get quality of the episode curCompositeStatus = episode.status curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) else: highestBestQuality = 0 # if we need a better one then add it to the list of episodes to fetch if (curStatus in ( DOWNLOADED, SNATCHED) and curQuality < highestBestQuality) or curStatus == WANTED: ab_number = episode.scene_absolute_number if ab_number > 0: seasonStrings.append("%02d" % ab_number) else: numseasons = len({x['season'] for x in sickrage.app.main_db.get_many('tv_episodes', show.indexerid) if x['season'] != 0}) seasonStrings = ["S%02d" % int(ep_obj.scene_season)] showNames = set(makeSceneShowSearchStrings(show, ep_obj.scene_season)) toReturn = [] # search each show name for curShow in showNames: # most providers all work the same way if not extraSearchType: # if there's only one season then we can just use the show name straight up if numseasons == 1: toReturn.append(curShow) # for providers that don't allow multiple searches in one request we only search for Sxx style stuff else: for cur_season in seasonStrings: if ep_obj.show.is_anime: if ep_obj.show.release_groups is not None: if len(show.release_groups.whitelist) > 0: for keyword in show.release_groups.whitelist: toReturn.append(keyword + '.' + curShow + "." + cur_season) else: toReturn.append(curShow + "." + cur_season) return toReturn
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.app.log.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.app.log.info("Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.app.log.debug( cur_result.name + " is a quality we know we don't want, rejecting it") continue # check if seeders meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minseed') and cur_result.seeders not in (-1, None): if int(cur_result.seeders) < int(cur_result.provider.minseed): sickrage.app.log.info( "Discarding torrent because it doesn't meet the minimum seeders: {}. Seeders: " "{}".format(cur_result.name, cur_result.seeders)) continue # check if leechers meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minleech') and cur_result.leechers not in (-1, None): if int(cur_result.leechers) < int(cur_result.provider.minleech): sickrage.app.log.info( "Discarding torrent because it doesn't meet the minimum leechers: {}. Leechers: " "{}".format(cur_result.name, cur_result.leechers)) continue if show.rls_ignore_words and show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_ignore_words): sickrage.app.log.info("Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_require_words): sickrage.app.log.info("Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.app.log.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want") continue if hasattr(cur_result, 'size'): if FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.app.log.info(cur_result.name + " has previously failed, rejecting it") continue # quality definition video file size constraints check try: if cur_result.size: quality_size = sickrage.app.config.quality_sizes[ cur_result.quality] file_size = float(cur_result.size / 1000000) if file_size > quality_size: raise Exception( "Ignoring " + cur_result.name + " with size: {} based on quality size filter: {}". format(file_size, quality_size)) except Exception as e: sickrage.app.log.info(str(e)) continue # verify result content if not cur_result.provider.private: if cur_result.resultType in [ "nzb", "torrent" ] and not cur_result.provider.get_content(cur_result.url): if sickrage.app.config.download_unverified_magnet_link and cur_result.url.startswith( 'magnet'): # Attempt downloading unverified torrent magnet link pass else: sickrage.app.log.info( "Ignoring {} because we are unable to verify the download url" .format(cur_result.name)) continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower( ) or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower( ) and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower( ) and "x264" in cur_result.name.lower(): sickrage.app.log.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.app.log.debug("Picked " + bestResult.name + " as the best") else: sickrage.app.log.debug("No result picked.") return bestResult
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.app.log.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.app.log.info( "Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.app.log.debug(cur_result.name + " is a quality we know we don't want, rejecting it") continue # check if seeders and leechers meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minseed') and hasattr(cur_result.provider, 'minleech'): if cur_result.seeders not in (-1, None) and cur_result.leechers not in (-1, None): if int(cur_result.seeders) < int(cur_result.provider.minseed) or int(cur_result.leechers) < int(cur_result.provider.minleech): sickrage.app.log.info('Discarding torrent because it does not meet the minimum provider ' 'setting S:{} L:{}. Result has S:{} L:{}', cur_result.provider.minseed, cur_result.provider.minleech, cur_result.seeders, cur_result.leechers) continue if show.rls_ignore_words and show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_ignore_words): sickrage.app.log.info( "Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_require_words): sickrage.app.log.info( "Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.app.log.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want") continue if hasattr(cur_result, 'size'): if sickrage.app.config.use_failed_downloads and FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.app.log.info(cur_result.name + " has previously failed, rejecting it") continue # quality definition video file size constraints check try: quality_size = sickrage.app.config.quality_sizes[cur_result.quality] for file, file_size in cur_result.files.items(): if not file.decode('utf-8').endswith(tuple(video_exts)): continue file_size = float(file_size / 1000000) if file_size > quality_size: raise Exception( "Ignoring " + cur_result.name + " with size: {} based on quality size filter: {}".format( file_size, quality_size) ) except Exception as e: sickrage.app.log.info(e.message) continue # verify result content cur_result = _verify_result(cur_result) if not cur_result.content: sickrage.app.log.info( "Ignoring " + cur_result.name + " because it does not have valid download url") continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower() or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower() and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower() and "x264" in cur_result.name.lower(): sickrage.app.log.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.app.log.debug("Picked " + bestResult.name + " as the best") else: sickrage.app.log.debug("No result picked.") return bestResult
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.LOGGER.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.LOGGER.info("Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.LOGGER.debug( cur_result.name + " is a quality we know we don't want, rejecting it") continue if show.rls_ignore_words and show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_ignore_words): sickrage.LOGGER.info("Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_require_words): sickrage.LOGGER.info("Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.LOGGER.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want, ignoring it" ) continue if hasattr(cur_result, 'size'): if sickrage.USE_FAILED_DOWNLOADS and FailedHistory.hasFailed( cur_result.name, cur_result.size, cur_result.provider.name): sickrage.LOGGER.info(cur_result.name + " has previously failed, rejecting it") continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower( ) or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower( ) and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower( ) and "x264" in cur_result.name.lower(): sickrage.LOGGER.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.LOGGER.debug("Picked " + bestResult.name + " as the best") else: sickrage.LOGGER.debug("No result picked.") return bestResult
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.srCore.srLogger.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.srCore.srLogger.info( "Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.srCore.srLogger.debug(cur_result.name + " is a quality we know we don't want, rejecting it") continue if show.rls_ignore_words and show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_ignore_words): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_require_words): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want, ignoring it") continue if hasattr(cur_result, 'size'): if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS and FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.srCore.srLogger.info(cur_result.name + " has previously failed, rejecting it") continue # quality definition video file size constraints check try: quality_size = sickrage.srCore.srConfig.QUALITY_SIZES[cur_result.quality] for file, file_size in cur_result.files.items(): if not file.endswith(tuple(video_exts)): continue file_size = float(file_size / 1000000) if file_size > quality_size: raise Exception( "Ignoring " + cur_result.name + " with size: {} based on quality size filter: {}, ignoring it".format( file_size, quality_size) ) except Exception as e: sickrage.srCore.srLogger.info(e.message) continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower() or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower() and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower() and "x264" in cur_result.name.lower(): sickrage.srCore.srLogger.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.srCore.srLogger.debug("Picked " + bestResult.name + " as the best") else: sickrage.srCore.srLogger.debug("No result picked.") return bestResult
def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None): numseasons = 0 if show.air_by_date or show.sports: # the search string for air by date shows is just seasonStrings = [str(ep_obj.airdate).split('-')[0]] elif show.is_anime: seasonEps = show.getAllEpisodes(ep_obj.season) # get show qualities anyQualities, bestQualities = Quality.splitQuality(show.quality) # compile a list of all the episode numbers we need in this 'season' seasonStrings = [] for episode in seasonEps: # get quality of the episode curCompositeStatus = episode.status curStatus, curQuality = Quality.splitCompositeStatus( curCompositeStatus) if bestQualities: highestBestQuality = max(bestQualities) else: highestBestQuality = 0 # if we need a better one then add it to the list of episodes to fetch if (curStatus in (DOWNLOADED, SNATCHED) and curQuality < highestBestQuality) or curStatus == WANTED: ab_number = episode.scene_absolute_number if ab_number > 0: seasonStrings.append("%02d" % ab_number) else: 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]) seasonStrings = ["S%02d" % int(ep_obj.scene_season)] showNames = set(makeSceneShowSearchStrings(show, ep_obj.scene_season)) toReturn = [] # search each show name for curShow in showNames: # most providers all work the same way if not extraSearchType: # if there's only one season then we can just use the show name straight up if numseasons == 1: toReturn.append(curShow) # for providers that don't allow multiple searches in one request we only search for Sxx style stuff else: for cur_season in seasonStrings: if ep_obj.show.is_anime: if ep_obj.show.release_groups is not None: if len(show.release_groups.whitelist) > 0: for keyword in show.release_groups.whitelist: toReturn.append(keyword + '.' + curShow + "." + cur_season) else: toReturn.append(curShow + "." + cur_season) return toReturn
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.srCore.srLogger.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.srCore.srLogger.info( "Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.srCore.srLogger.debug(cur_result.name + " is a quality we know we don't want, rejecting it") continue if show.rls_ignore_words and show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_ignore_words): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_require_words): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.srCore.srLogger.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want, ignoring it") continue if hasattr(cur_result, 'size'): if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS and FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.srCore.srLogger.info(cur_result.name + " has previously failed, rejecting it") continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower() or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower() and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower() and "x264" in cur_result.name.lower(): sickrage.srCore.srLogger.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.srCore.srLogger.debug("Picked " + bestResult.name + " as the best") else: sickrage.srCore.srLogger.debug("No result picked.") return bestResult
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.app.log.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.app.log.info("Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.app.log.debug( cur_result.name + " is a quality we know we don't want, rejecting it") continue # check if seeders and leechers meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minseed') and hasattr( cur_result.provider, 'minleech'): if cur_result.seeders not in ( -1, None) and cur_result.leechers not in (-1, None): if int(cur_result.seeders) < int( cur_result.provider.minseed) or int( cur_result.leechers) < int( cur_result.provider.minleech): sickrage.app.log.info( 'Discarding torrent because it does not meet the minimum provider ' 'setting S:{} L:{}. Result has S:{} L:{}', cur_result.provider.minseed, cur_result.provider.minleech, cur_result.seeders, cur_result.leechers) continue if show.rls_ignore_words and show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_ignore_words): sickrage.app.log.info("Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord( cur_result.name, cur_result.show.rls_require_words): sickrage.app.log.info("Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.app.log.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want") continue if hasattr(cur_result, 'size'): if sickrage.app.config.use_failed_downloads and FailedHistory.hasFailed( cur_result.name, cur_result.size, cur_result.provider.name): sickrage.app.log.info(cur_result.name + " has previously failed, rejecting it") continue # quality definition video file size constraints check try: quality_size = sickrage.app.config.quality_sizes[ cur_result.quality] for file, file_size in cur_result.files.items(): if not file.decode('utf-8').endswith(tuple(video_exts)): continue file_size = float(file_size / 1000000) if file_size > quality_size: raise Exception( "Ignoring " + cur_result.name + " with size: {} based on quality size filter: {}". format(file_size, quality_size)) except Exception as e: sickrage.app.log.info(e.message) continue # verify result content cur_result = _verify_result(cur_result) if not cur_result.content: sickrage.app.log.info( "Ignoring " + cur_result.name + " because it does not have valid download url") continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower( ) or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower( ) and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower( ) and "x264" in cur_result.name.lower(): sickrage.app.log.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.app.log.debug("Picked " + bestResult.name + " as the best") else: sickrage.app.log.debug("No result picked.") return bestResult
def pickBestResult(results, show): """ Find the best result out of a list of search results for a show :param results: list of result objects :param show: Shows we check for :return: best result object """ results = results if isinstance(results, list) else [results] sickrage.app.log.debug("Picking the best result out of " + str([x.name for x in results])) bestResult = None # find the best result for the current episode for cur_result in results: if show and cur_result.show is not show: continue # build the black And white list if show.is_anime: if not show.release_groups.is_valid(cur_result): continue sickrage.app.log.info( "Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality]) anyQualities, bestQualities = Quality.splitQuality(show.quality) if cur_result.quality not in anyQualities + bestQualities: sickrage.app.log.debug(cur_result.name + " is a quality we know we don't want, rejecting it") continue # check if seeders meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minseed') and cur_result.seeders not in (-1, None): if int(cur_result.seeders) < min(cur_result.provider.minseed, 1): sickrage.app.log.info("Discarding torrent because it doesn't meet the minimum seeders: {}. Seeders: " "{}".format(cur_result.name, cur_result.seeders)) continue # check if leechers meet out minimum requirements, disgard result if it does not if hasattr(cur_result.provider, 'minleech') and cur_result.leechers not in (-1, None): if int(cur_result.leechers) < min(cur_result.provider.minleech, 0): sickrage.app.log.info("Discarding torrent because it doesn't meet the minimum leechers: {}. Leechers: " "{}".format(cur_result.name, cur_result.leechers)) continue if show.rls_ignore_words and show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_ignore_words): sickrage.app.log.info( "Ignoring " + cur_result.name + " based on ignored words filter: " + show.rls_ignore_words) continue if show.rls_require_words and not show_names.containsAtLeastOneWord(cur_result.name, cur_result.show.rls_require_words): sickrage.app.log.info( "Ignoring " + cur_result.name + " based on required words filter: " + show.rls_require_words) continue if not show_names.filterBadReleases(cur_result.name, parse=False): sickrage.app.log.info( "Ignoring " + cur_result.name + " because its not a valid scene release that we want") continue if hasattr(cur_result, 'size'): if FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.app.log.info(cur_result.name + " has previously failed, rejecting it") continue # quality definition video file size constraints check try: if cur_result.size: quality_size = sickrage.app.config.quality_sizes[cur_result.quality] file_size = float(cur_result.size / 1000000) if file_size > quality_size: raise Exception( "Ignoring " + cur_result.name + " with size: {} based on quality size filter: {}".format( file_size, quality_size) ) except Exception as e: sickrage.app.log.info(str(e)) continue # verify result content if not cur_result.provider.private: if cur_result.resultType in ["nzb", "torrent"] and not cur_result.provider.get_content(cur_result.url): if sickrage.app.config.download_unverified_magnet_link and cur_result.url.startswith('magnet'): # Attempt downloading unverified torrent magnet link pass else: sickrage.app.log.info( "Ignoring {} because we are unable to verify the download url".format(cur_result.name)) continue if not bestResult: bestResult = cur_result elif cur_result.quality in bestQualities and ( bestResult.quality < cur_result.quality or bestResult.quality not in bestQualities): bestResult = cur_result elif cur_result.quality in anyQualities and bestResult.quality not in bestQualities and bestResult.quality < cur_result.quality: bestResult = cur_result elif bestResult.quality == cur_result.quality: if "proper" in cur_result.name.lower() or "repack" in cur_result.name.lower(): bestResult = cur_result elif "internal" in bestResult.name.lower() and "internal" not in cur_result.name.lower(): bestResult = cur_result elif "xvid" in bestResult.name.lower() and "x264" in cur_result.name.lower(): sickrage.app.log.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.app.log.debug("Picked " + bestResult.name + " as the best") else: sickrage.app.log.debug("No result picked.") return bestResult