def _test_filterBadReleases(self, name, expected): result = show_names.filterBadReleases(name) self.assertEqual(result, expected)
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 search_cache(self, ep_obj, manualSearch=False, downCurQuality=False): neededEps = {} dbData = [] # get data from external database if sickrage.app.config.enable_api_providers_cache and not self.provider.private: try: dbData += ProviderCacheAPI().get(self.providerID, ep_obj.show.indexerid, ep_obj.season, ep_obj.episode)['data'] except Exception: pass # get data from internal database dbData += [ x for x in sickrage.app.cache_db.get_many('providers', self.providerID) ] # for each cache entry for curResult in (x for x in dbData if x['indexerid'] == ep_obj.show.indexerid and x['season'] == ep_obj.season and "|" + str(ep_obj.episode) + "|" in x['episodes']): result = self.provider.getResult() # ignore invalid urls if not validate_url(curResult["url"]) and not curResult["url"].startswith('magnet') \ or is_ip_private(curResult["url"].split(r'//')[-1].split(r'/')[0]): continue # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it result.show = findCertainShow(int(curResult["indexerid"])) if not result.show: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not result.show.is_anime: sickrage.app.log.debug("" + str(result.show.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue try: result.episodes = [ result.show.getEpisode(curSeason, int(curEp)) for curEp in filter(None, curResult["episodes"].split("|")) ] except EpisodeNotFoundException: continue result.quality = int(curResult["quality"]) result.release_group = curResult["release_group"] result.version = curResult["version"] # make sure we want the episode wantEp = False for curEp in result.episodes: if result.show.wantEpisode(curEp.season, curEp.episode, result.quality, manualSearch, downCurQuality): wantEp = True if not wantEp: sickrage.app.log.info( "Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[result.quality]) continue # build a result object result.name = curResult["name"] result.url = curResult["url"] sickrage.app.log.info("Found result " + result.name + " at " + result.url) result.seeders = curResult.get("seeders", -1) result.leechers = curResult.get("leechers", -1) result.size = curResult.get("size", -1) result.content = None # add it to the list if ep_obj.episode not in neededEps: neededEps[ep_obj.episode] = [result] else: neededEps[ep_obj.episode] += [result] # datetime stamp this search so cache gets cleared self.last_search = datetime.datetime.today() return neededEps
def findNeededEpisodes(self, episode, manualSearch=False, downCurQuality=False): neededEps = {} cl = [] myDB = self._getDB() if not episode: sqlResults = myDB.select("SELECT * FROM [" + self.providerID + "]") elif type(episode) != list: sqlResults = myDB.select( "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", [episode.show.indexerid, episode.season, "%|" + str(episode.episode) + "|%"]) else: for epObj in episode: cl.append([ "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ? AND quality IN (" + ",".join( [str(x) for x in epObj.wantedQuality]) + ")", [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]]) sqlResults = myDB.mass_action(cl, fetchall=True) sqlResults = list(itertools.chain(*sqlResults)) # for each cache entry for curResult in sqlResults: # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult[b"name"]): continue # get the show object, or if it's not one of our shows then ignore it showObj = findCertainShow(sickrage.showList, int(curResult[b"indexerid"])) if not showObj: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not showObj.is_anime: sickrage.LOGGER.debug("" + str(showObj.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult[b"season"]) if curSeason == -1: continue curEp = curResult[b"episodes"].split("|")[1] if not curEp: continue curEp = int(curEp) curQuality = int(curResult[b"quality"]) curReleaseGroup = curResult[b"release_group"] curVersion = curResult[b"version"] # if the show says we want that episode then add it to the list if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch, downCurQuality): sickrage.LOGGER.info("Skipping " + curResult[b"name"] + " because we don't want an episode that's " + Quality.qualityStrings[curQuality]) continue epObj = showObj.getEpisode(curSeason, curEp) # build a result object title = curResult[b"name"] url = curResult[b"url"] sickrage.LOGGER.info("Found result " + title + " at " + url) result = self.provider.getResult([epObj]) result.show = showObj result.url = url result.name = title result.quality = curQuality result.release_group = curReleaseGroup result.version = curVersion result.content = None # add it to the list if epObj not in neededEps: neededEps[epObj] = [result] else: neededEps[epObj].append(result) # datetime stamp this search so cache gets cleared self.setLastSearch() return neededEps
def searchCache(self, episode=None, manualSearch=False, downCurQuality=False): neededEps = {} if not episode: sqlResults = self._getDB().select("SELECT * FROM [" + self.providerID + "]") else: sqlResults = self._getDB().select( "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", [episode.show.indexerid, episode.season, "%|" + str(episode.episode) + "|%"]) # for each cache entry for curResult in sqlResults: # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(curResult["indexerid"])) if not showObj: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not showObj.is_anime: sickrage.srCore.srLogger.debug("" + str(showObj.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue curEp = curResult["episodes"].split("|")[1] if not curEp: continue curEp = int(curEp) curQuality = int(curResult["quality"]) curReleaseGroup = curResult["release_group"] curVersion = curResult["version"] # if the show says we want that episode then add it to the list if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch, downCurQuality): sickrage.srCore.srLogger.info("Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[curQuality]) continue epObj = showObj.getEpisode(curSeason, curEp) # build a result object title = curResult["name"] url = curResult["url"] sickrage.srCore.srLogger.info("Found result " + title + " at " + url) result = self.provider.getResult([epObj]) result.show = showObj result.url = url result.name = title result.quality = curQuality result.release_group = curReleaseGroup result.version = curVersion result.content = None result.size = self.provider._get_size(url) result.files = self.provider._get_files(url) # add it to the list if epObj not in neededEps: neededEps[epObj.episode] = [result] else: neededEps[epObj.episode].append(result) # datetime stamp this search so cache gets cleared self.setLastSearch() return neededEps
def search_cache(self, ep_obj=None, manualSearch=False, downCurQuality=False): neededEps = {} dbData = [] # get data from external database if sickrage.app.config.enable_api_providers_cache and not self.provider.private: try: dbData += sickrage.app.api.get_cache_results( self.providerID, ep_obj.show.indexerid) except Exception: pass # get data from internal database dbData += [ x['doc'] for x in sickrage.app.cache_db.db.get_many( 'providers', self.providerID, with_doc=True) ] dbData = [ x for x in dbData if x['indexerid'] == ep_obj.show.indexerid and x['season'] == ep_obj.season and "|" + str(ep_obj.episode) + "|" in x['episodes'] ] if ep_obj else dbData # for each cache entry for curResult in dbData: result = self.provider.getResult() # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it showObj = findCertainShow(sickrage.app.showlist, int(curResult["indexerid"])) if not showObj: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not showObj.is_anime: sickrage.app.log.debug("" + str(showObj.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue curEp = curResult["episodes"].split("|")[1] if not curEp: continue curEp = int(curEp) result.quality = int(curResult["quality"]) result.release_group = curResult["release_group"] result.version = curResult["version"] # if the show says we want that episode then add it to the list if not showObj.wantEpisode(curSeason, curEp, result.quality, manualSearch, downCurQuality): sickrage.app.log.info( "Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[result.quality]) continue result.episodes = [showObj.getEpisode(curSeason, curEp)] # build a result object result.name = curResult["name"] result.url = curResult["url"] sickrage.app.log.info("Found result " + result.name + " at " + result.url) result.show = showObj result.seeders = curResult.get("seeders", -1) result.leechers = curResult.get("leechers", -1) result.size = curResult.get("size", -1) result.files = json.loads(curResult.get("files", {})) result.content = None # add it to the list if result.episodes[0].episode not in neededEps: neededEps[result.episodes[0].episode] = [result] else: neededEps[result.episodes[0].episode] += [result] # datetime stamp this search so cache gets cleared self.last_search = datetime.datetime.today() return neededEps
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 search_cache(self, episode=None, manualSearch=False, downCurQuality=False): neededEps = {} if not episode: dbData = [x['doc'] for x in sickrage.srCore.cacheDB.db.get_many('providers', self.providerID, with_doc=True)] else: dbData = [x['doc'] for x in sickrage.srCore.cacheDB.db.get_many('providers', self.providerID, with_doc=True) if x['doc']['indexerid'] == episode.show.indexerid and x['doc']['season'] == episode.season and "|" + str(episode.episode) + "|" in x['doc']['episodes']] # for each cache entry for curResult in dbData: # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(curResult["indexerid"])) if not showObj: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not showObj.is_anime: sickrage.srCore.srLogger.debug("" + str(showObj.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue curEp = curResult["episodes"].split("|")[1] if not curEp: continue curEp = int(curEp) curQuality = int(curResult["quality"]) curReleaseGroup = curResult["release_group"] curVersion = curResult["version"] # if the show says we want that episode then add it to the list if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch, downCurQuality): sickrage.srCore.srLogger.info( "Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[curQuality]) continue epObj = showObj.getEpisode(curSeason, curEp) # build a result object title = curResult["name"] url = curResult["url"] sickrage.srCore.srLogger.info("Found result " + title + " at " + url) result = self.provider.getResult([epObj]) result.show = showObj result.url = url result.name = title result.quality = curQuality result.release_group = curReleaseGroup result.version = curVersion result.content = None result.size = self.provider._get_size(url) result.files = self.provider._get_files(url) # add it to the list if epObj not in neededEps: neededEps[epObj.episode] = [result] else: neededEps[epObj.episode].append(result) # datetime stamp this search so cache gets cleared self.last_search = datetime.datetime.today() return neededEps
def search_cache(self, ep_obj, manualSearch=False, downCurQuality=False): season = ep_obj.scene_season if ep_obj.show.scene else ep_obj.season episode = ep_obj.scene_episode if ep_obj.show.scene else ep_obj.episode neededEps = {} dbData = [] # get data from external database if sickrage.app.config.enable_api_providers_cache and not self.provider.private: try: dbData += ProviderCacheAPI().get(self.providerID, ep_obj.show.indexerid, season, episode)['data'] except Exception: pass # get data from internal database dbData += [x for x in sickrage.app.cache_db.get_many('providers', self.providerID)] # for each cache entry for curResult in (x for x in dbData if x.get('indexerid') == ep_obj.show.indexerid and x.get('season') == season and "|{}|".format( episode) in x.get('episodes', [])): result = self.provider.getResult() # ignore invalid and private IP address urls if not validate_url(curResult["url"]): if not curResult["url"].startswith('magnet'): continue elif is_ip_private(curResult["url"].split(r'//')[-1].split(r'/')[0]): continue # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it result.show = findCertainShow(int(curResult["indexerid"])) if not result.show: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not result.show.is_anime: sickrage.app.log.debug("" + str(result.show.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue try: result.episodes = [result.show.get_episode(curSeason, int(curEp)) for curEp in filter(None, curResult["episodes"].split("|"))] except EpisodeNotFoundException: continue result.quality = int(curResult["quality"]) result.release_group = curResult["release_group"] result.version = curResult["version"] # make sure we want the episode wantEp = False for curEp in result.episodes: if result.show.want_episode(curEp.season, curEp.episode, result.quality, manualSearch, downCurQuality): wantEp = True if not wantEp: sickrage.app.log.info("Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[result.quality]) continue # build a result object result.name = curResult["name"] result.url = curResult["url"] sickrage.app.log.info("Found result " + result.name + " at " + result.url) result.seeders = curResult.get("seeders", -1) result.leechers = curResult.get("leechers", -1) result.size = curResult.get("size", -1) result.content = None # add it to the list if ep_obj.episode not in neededEps: neededEps[ep_obj.episode] = [result] else: neededEps[ep_obj.episode] += [result] # datetime stamp this search so cache gets cleared self.last_search = datetime.datetime.today() return neededEps
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.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.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.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
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 search_cache(self, ep_obj=None, manualSearch=False, downCurQuality=False): neededEps = {} dbData = [] # get data from external database if sickrage.app.config.enable_api_providers_cache and not self.provider.private: try: dbData += sickrage.app.api.get_cache_results(self.providerID, ep_obj.show.indexerid) except Exception: pass # get data from internal database dbData += [x['doc'] for x in sickrage.app.cache_db.db.get_many('providers', self.providerID, with_doc=True)] dbData = [x for x in dbData if x['indexerid'] == ep_obj.show.indexerid and x['season'] == ep_obj.season and "|" + str(ep_obj.episode) + "|" in x['episodes']] if ep_obj else dbData # for each cache entry for curResult in dbData: result = self.provider.getResult() # ignored/required words, and non-tv junk if not show_names.filterBadReleases(curResult["name"]): continue # get the show object, or if it's not one of our shows then ignore it showObj = findCertainShow(sickrage.app.showlist, int(curResult["indexerid"])) if not showObj: continue # skip if provider is anime only and show is not anime if self.provider.anime_only and not showObj.is_anime: sickrage.app.log.debug("" + str(showObj.name) + " is not an anime, skiping") continue # get season and ep data (ignoring multi-eps for now) curSeason = int(curResult["season"]) if curSeason == -1: continue curEp = curResult["episodes"].split("|")[1] if not curEp: continue curEp = int(curEp) result.quality = int(curResult["quality"]) result.release_group = curResult["release_group"] result.version = curResult["version"] # if the show says we want that episode then add it to the list if not showObj.wantEpisode(curSeason, curEp, result.quality, manualSearch, downCurQuality): sickrage.app.log.info( "Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[result.quality]) continue result.episodes = [showObj.getEpisode(curSeason, curEp)] # build a result object result.name = curResult["name"] result.url = curResult["url"] sickrage.app.log.info("Found result " + result.name + " at " + result.url) result.show = showObj result.seeders = curResult.get("seeders", -1) result.leechers = curResult.get("leechers", -1) result.size = curResult.get("size", -1) result.files = json.loads(curResult.get("files", {})) result.content = None # add it to the list if result.episodes[0].episode not in neededEps: neededEps[result.episodes[0].episode] = [result] else: neededEps[result.episodes[0].episode] += [result] # datetime stamp this search so cache gets cleared self.last_search = datetime.datetime.today() return neededEps