def findNeededEpisodes(self, episode, manualSearch=False, downCurQuality=False): sqlResults = [] neededEps = {} cl = [] if not episode: sqlResults = self._getDB().select("SELECT * FROM [" + self.providerID + "]") elif type(episode) != list: sqlResults = self._getDB().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) + "|%" ] ]) if len(cl) > 0: sqlResults = list( itertools.chain(*self._getDB().mass_action(cl))) del cl # cleanup # 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.srCore.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.srLogger.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.srLogger.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.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 # 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 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.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.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.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.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.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.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.srConfig.USE_FAILED_DOWNLOADS and FailedHistory.hasFailed(cur_result.name, cur_result.size, cur_result.provider.name): sickrage.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.srLogger.info("Preferring " + cur_result.name + " (x264 over xvid)") bestResult = cur_result if bestResult: sickrage.srLogger.debug("Picked " + bestResult.name + " as the best") else: sickrage.srLogger.debug("No result picked.") return bestResult
def _test_filterBadReleases(self, name, expected): result = show_names.filterBadReleases(name) self.assertEqual(result, expected)
def findNeededEpisodes(self, episode, manualSearch=False, downCurQuality=False): sqlResults = [] neededEps = {} cl = [] if not episode: sqlResults = self._getDB().select("SELECT * FROM [" + self.providerID + "]") elif type(episode) != list: sqlResults = self._getDB().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) + "|%"]]) if len(cl) > 0: sqlResults = list(itertools.chain(*self._getDB().mass_action(cl))) # 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.srCore.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.srLogger.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.srLogger.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.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 # 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 _test_filterBadReleases(self, name, expected): result = show_names.filterBadReleases(name) self.assertEqual(result, expected)