Ejemplo n.º 1
0
    def perform_searches():
        foundResults = {}
        finalResults = []

        for providerID, providerObj in sickrage.srCore.providersDict.sort(
                randomize=sickrage.srCore.srConfig.RANDOMIZE_PROVIDERS).items():

            # check provider type and provider is enabled
            if not sickrage.srCore.srConfig.USE_NZBS and providerObj.type in [NZBProvider.type, NewznabProvider.type]:
                continue
            elif not sickrage.srCore.srConfig.USE_TORRENTS and providerObj.type in [TorrentProvider.type,
                                                                                    TorrentRssProvider.type]:
                continue
            elif not providerObj.isEnabled:
                continue

            if providerObj.anime_only and not show.is_anime:
                sickrage.srCore.srLogger.debug("" + str(show.name) + " is not an anime, skiping")
                continue

            foundResults[providerObj.name] = {}

            searchCount = 0
            search_mode = providerObj.search_mode

            # Always search for episode when manually searching when in sponly
            if search_mode == 'sponly' and manualSearch == True:
                search_mode = 'eponly'

            while True:
                searchCount += 1

                if search_mode == 'eponly':
                    sickrage.srCore.srLogger.info("Performing episode search for " + show.name)
                else:
                    sickrage.srCore.srLogger.info("Performing season pack search for " + show.name)

                try:
                    threading.currentThread().setName(origThreadName + "::[" + providerObj.name + "]")

                    providerObj.cache.updateCache()
                    searchResults = providerObj.findSearchResults(show,
                                                                  episodes,
                                                                  search_mode,
                                                                  manualSearch,
                                                                  downCurQuality)
                except AuthException as e:
                    sickrage.srCore.srLogger.error("Authentication error: {}".format(e.message))
                    break
                except Exception as e:
                    sickrage.srCore.srLogger.error(
                        "Error while searching " + providerObj.name + ", skipping: {}".format(e.message))
                    sickrage.srCore.srLogger.debug(traceback.format_exc())
                    break
                finally:
                    threading.currentThread().setName(origThreadName)

                didSearch = True

                if len(searchResults):
                    # make a list of all the results for this provider
                    for curEp in searchResults:
                        if curEp in foundResults:
                            foundResults[providerObj.name][curEp] += searchResults[curEp]
                        else:
                            foundResults[providerObj.name][curEp] = searchResults[curEp]

                    break
                elif not providerObj.search_fallback or searchCount == 2:
                    break

                if search_mode == 'sponly':
                    sickrage.srCore.srLogger.debug("Fallback episode search initiated")
                    search_mode = 'eponly'
                else:
                    sickrage.srCore.srLogger.debug("Fallback season pack search initiate")
                    search_mode = 'sponly'

            # skip to next provider if we have no results to process
            if not len(foundResults[providerObj.name]):
                continue

            # pick the best season NZB
            bestSeasonResult = None
            if SEASON_RESULT in foundResults[providerObj.name]:
                bestSeasonResult = pickBestResult(foundResults[providerObj.name][SEASON_RESULT], show)

            highest_quality_overall = 0
            for cur_episode in foundResults[providerObj.name]:
                for cur_result in foundResults[providerObj.name][cur_episode]:
                    if cur_result.quality != Quality.UNKNOWN and cur_result.quality > highest_quality_overall:
                        highest_quality_overall = cur_result.quality
            sickrage.srCore.srLogger.debug(
                "The highest quality of any match is " + Quality.qualityStrings[highest_quality_overall])

            # see if every episode is wanted
            if bestSeasonResult:
                searchedSeasons = [str(x.season) for x in episodes]

                # get the quality of the season nzb
                seasonQual = bestSeasonResult.quality
                sickrage.srCore.srLogger.debug(
                    "The quality of the season " + bestSeasonResult.provider.type + " is " +
                    Quality.qualityStrings[
                        seasonQual])

                allEps = [int(x["episode"])
                          for x in main_db.MainDB().select(
                        "SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( " + ','.join(
                            searchedSeasons) + " ) )",
                        [show.indexerid])]

                sickrage.srCore.srLogger.info(
                    "Executed query: [SELECT episode FROM tv_episodes WHERE showid = %s AND season in  %s]" % (
                        show.indexerid, ','.join(searchedSeasons)))
                sickrage.srCore.srLogger.debug("Episode list: " + str(allEps))

                allWanted = True
                anyWanted = False
                for curEpNum in allEps:
                    for season in set([x.season for x in episodes]):
                        if not show.wantEpisode(season, curEpNum, seasonQual, downCurQuality):
                            allWanted = False
                        else:
                            anyWanted = True

                # if we need every ep in the season and there's nothing better then just download this and be done with it (unless single episodes are preferred)
                if allWanted and bestSeasonResult.quality == highest_quality_overall:
                    sickrage.srCore.srLogger.info(
                        "Every ep in this season is needed, downloading the whole " + bestSeasonResult.provider.type + " " + bestSeasonResult.name)
                    epObjs = []
                    for curEpNum in allEps:
                        for season in set([x.season for x in episodes]):
                            epObjs.append(show.getEpisode(season, curEpNum))
                    bestSeasonResult.episodes = epObjs

                    return [bestSeasonResult]

                elif not anyWanted:
                    sickrage.srCore.srLogger.debug(
                        "No eps from this season are wanted at this quality, ignoring the result of " + bestSeasonResult.name)

                else:

                    if bestSeasonResult.provider.type == NZBProvider.type:
                        sickrage.srCore.srLogger.debug(
                            "Breaking apart the NZB and adding the individual ones to our results")

                        # if not, break it apart and add them as the lowest priority results
                        individualResults = splitNZBResult(bestSeasonResult)
                        for curResult in individualResults:
                            if len(curResult.episodes) == 1:
                                epNum = curResult.episodes[0].episode
                            elif len(curResult.episodes) > 1:
                                epNum = MULTI_EP_RESULT

                            if epNum in foundResults[providerObj.name]:
                                foundResults[providerObj.name][epNum].append(curResult)
                            else:
                                foundResults[providerObj.name][epNum] = [curResult]

                    # If this is a torrent all we can do is leech the entire torrent, user will have to select which eps not do download in his torrent client
                    else:

                        # Season result from Torrent Provider must be a full-season torrent, creating multi-ep result for it.
                        sickrage.srCore.srLogger.info(
                            "Adding multi-ep result for full-season torrent. Set the episodes you don't want to 'don't download' in your torrent client if desired!")
                        epObjs = []
                        for curEpNum in allEps:
                            for season in set([x.season for x in episodes]):
                                epObjs.append(show.getEpisode(season, curEpNum))
                        bestSeasonResult.episodes = epObjs

                        if MULTI_EP_RESULT in foundResults[providerObj.name]:
                            foundResults[providerObj.name][MULTI_EP_RESULT].append(bestSeasonResult)
                        else:
                            foundResults[providerObj.name][MULTI_EP_RESULT] = [bestSeasonResult]

            # go through multi-ep results and see if we really want them or not, get rid of the rest
            multiResults = {}
            if MULTI_EP_RESULT in foundResults[providerObj.name]:
                for _multiResult in foundResults[providerObj.name][MULTI_EP_RESULT]:

                    sickrage.srCore.srLogger.debug(
                        "Seeing if we want to bother with multi-episode result " + _multiResult.name)

                    # Filter result by ignore/required/whitelist/blacklist/quality, etc
                    multiResult = pickBestResult(_multiResult, show)
                    if not multiResult:
                        continue

                    # see how many of the eps that this result covers aren't covered by single results
                    neededEps = []
                    notNeededEps = []
                    for epObj in multiResult.episodes:
                        # if we have results for the episode
                        if epObj.episode in foundResults[providerObj.name] and len(
                                foundResults[providerObj.name][epObj.episode]) > 0:
                            notNeededEps.append(epObj.episode)
                        else:
                            neededEps.append(epObj.episode)

                    sickrage.srCore.srLogger.debug(
                        "Single-ep check result is neededEps: " + str(neededEps) + ", notNeededEps: " + str(
                            notNeededEps))

                    if not neededEps:
                        sickrage.srCore.srLogger.debug(
                            "All of these episodes were covered by single episode results, ignoring this multi-episode result")
                        continue

                    # check if these eps are already covered by another multi-result
                    multiNeededEps = []
                    multiNotNeededEps = []
                    for epObj in multiResult.episodes:
                        if epObj.episode in multiResults:
                            multiNotNeededEps.append(epObj.episode)
                        else:
                            multiNeededEps.append(epObj.episode)

                    sickrage.srCore.srLogger.debug(
                        "Multi-ep check result is multiNeededEps: " + str(
                            multiNeededEps) + ", multiNotNeededEps: " + str(
                            multiNotNeededEps))

                    if not multiNeededEps:
                        sickrage.srCore.srLogger.debug(
                            "All of these episodes were covered by another multi-episode nzbs, ignoring this multi-ep result")
                        continue

                    # don't bother with the single result if we're going to get it with a multi result
                    for epObj in multiResult.episodes:
                        multiResults[epObj.episode] = multiResult
                        if epObj.episode in foundResults[providerObj.name]:
                            sickrage.srCore.srLogger.debug(
                                "A needed multi-episode result overlaps with a single-episode result for ep #" + str(
                                    epObj.episode) + ", removing the single-episode results from the list")
                            del foundResults[providerObj.name][epObj.episode]

            # of all the single ep results narrow it down to the best one for each episode
            finalResults += set(multiResults.values())
            for curEp in foundResults[providerObj.name]:
                if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
                    continue

                if not len(foundResults[providerObj.name][curEp]) > 0:
                    continue

                # if all results were rejected move on to the next episode
                bestResult = pickBestResult(foundResults[providerObj.name][curEp], show)
                if not bestResult:
                    continue

                # add result if its not a duplicate and
                found = False
                for i, result in enumerate(finalResults):
                    for bestResultEp in bestResult.episodes:
                        if bestResultEp in result.episodes:
                            if result.quality < bestResult.quality:
                                finalResults.pop(i)
                            else:
                                found = True
                if not found:
                    finalResults += [bestResult]

            # check that we got all the episodes we wanted first before doing a match and snatch
            wantedEpCount = 0
            for wantedEp in episodes:
                for result in finalResults:
                    if wantedEp in result.episodes and isFinalResult(result):
                        wantedEpCount += 1

            # make sure we search every provider for results unless we found everything we wanted
            if wantedEpCount == len(episodes):
                break

        return finalResults
Ejemplo n.º 2
0
    def perform_searches():
        search_results = {}
        found_results = {}
        final_results = []

        for providerID, providerObj in sickrage.app.search_providers.sort(
                randomize=sickrage.app.config.randomize_providers).items():

            # check if provider is enabled
            if not providerObj.isEnabled:
                continue

            # check provider type
            if not sickrage.app.config.use_nzbs and providerObj.type in [
                    NZBProvider.type, NewznabProvider.type
            ]:
                continue
            elif not sickrage.app.config.use_torrents and providerObj.type in [
                    TorrentProvider.type, TorrentRssProvider.type
            ]:
                continue

            if providerObj.anime_only and not show.is_anime:
                sickrage.app.log.debug("" + str(show.name) +
                                       " is not an anime, skiping")
                continue

            found_results[providerObj.name] = {}

            search_count = 0
            search_mode = providerObj.search_mode

            # Always search for episode when manually searching when in sponly
            if search_mode == 'sponly' and manualSearch == True:
                search_mode = 'eponly'

            while True:
                search_count += 1

                try:
                    threading.currentThread().setName(origThreadName + "::[" +
                                                      providerObj.name + "]")

                    # update provider RSS cache
                    if sickrage.app.config.enable_rss_cache and updateCache:
                        providerObj.cache.update()

                    if len(episodes):
                        if search_mode == 'eponly':
                            sickrage.app.log.info(
                                "Performing episode search for " + show.name)
                        else:
                            sickrage.app.log.info(
                                "Performing season pack search for " +
                                show.name)

                    # search provider for episodes
                    search_results = providerObj.findSearchResults(
                        show, episodes, search_mode, manualSearch,
                        downCurQuality, cacheOnly)
                except AuthException as e:
                    sickrage.app.log.warning(
                        "Authentication error: {}".format(e))
                    break
                except Exception as e:
                    sickrage.app.log.error("Error while searching " +
                                           providerObj.name +
                                           ", skipping: {}".format(e))
                    break
                finally:
                    threading.currentThread().setName(origThreadName)

                if len(search_results):
                    # make a list of all the results for this provider
                    for curEp in search_results:
                        if curEp in found_results:
                            found_results[providerObj.
                                          name][curEp] += search_results[curEp]
                        else:
                            found_results[providerObj.
                                          name][curEp] = search_results[curEp]

                        # Sort results by seeders if available
                        if providerObj.type == 'torrent' or getattr(
                                providerObj, 'torznab', False):
                            found_results[providerObj.name][curEp].sort(
                                key=lambda k: int(k.seeders), reverse=True)

                    break
                elif not providerObj.search_fallback or search_count == 2:
                    break

                if search_mode == 'sponly':
                    sickrage.app.log.debug("Fallback episode search initiated")
                    search_mode = 'eponly'
                else:
                    sickrage.app.log.debug(
                        "Fallback season pack search initiate")
                    search_mode = 'sponly'

            # skip to next provider if we have no results to process
            if not len(found_results[providerObj.name]):
                continue

            # pick the best season NZB
            bestSeasonResult = None
            if SEASON_RESULT in found_results[providerObj.name]:
                bestSeasonResult = pickBestResult(
                    found_results[providerObj.name][SEASON_RESULT], show)

            highest_quality_overall = 0
            for cur_episode in found_results[providerObj.name]:
                for cur_result in found_results[providerObj.name][cur_episode]:
                    if cur_result.quality != Quality.UNKNOWN and cur_result.quality > highest_quality_overall:
                        highest_quality_overall = cur_result.quality

            sickrage.app.log.debug(
                "The highest quality of any match is " +
                Quality.qualityStrings[highest_quality_overall])

            # see if every episode is wanted
            if bestSeasonResult:
                searchedSeasons = {x.season for x in episodes}

                # get the quality of the season nzb
                seasonQual = bestSeasonResult.quality
                sickrage.app.log.debug("The quality of the season " +
                                       bestSeasonResult.provider.type +
                                       " is " +
                                       Quality.qualityStrings[seasonQual])

                allEps = [
                    int(x["episode"]) for x in sickrage.app.main_db.get_many(
                        'tv_episodes', show.indexerid)
                    if x['season'] in searchedSeasons
                ]

                sickrage.app.log.debug("Episode list: " + str(allEps))

                allWanted = True
                anyWanted = False
                for curEpNum in allEps:
                    for season in set([x.season for x in episodes]):
                        if not show.want_episode(season, curEpNum, seasonQual,
                                                 downCurQuality):
                            allWanted = False
                        else:
                            anyWanted = True

                # if we need every ep in the season and there's nothing better then just download this and be done
                # with it (unless single episodes are preferred)
                if allWanted and bestSeasonResult.quality == highest_quality_overall:
                    sickrage.app.log.info(
                        "Every ep in this season is needed, downloading the whole "
                        + bestSeasonResult.provider.type + " " +
                        bestSeasonResult.name)

                    epObjs = []
                    for curEpNum in allEps:
                        for season in set([x.season for x in episodes]):
                            epObjs.append(show.get_episode(season, curEpNum))

                    bestSeasonResult.episodes = epObjs

                    return [bestSeasonResult]

                elif not anyWanted:
                    sickrage.app.log.debug(
                        "No eps from this season are wanted at this quality, ignoring the result of "
                        + bestSeasonResult.name)
                else:
                    if bestSeasonResult.provider.type == NZBProvider.type:
                        sickrage.app.log.debug(
                            "Breaking apart the NZB and adding the individual ones to our results"
                        )

                        # if not, break it apart and add them as the lowest priority results
                        individualResults = splitNZBResult(bestSeasonResult)
                        for curResult in individualResults:
                            epNum = -1
                            if len(curResult.episodes) == 1:
                                epNum = curResult.episodes[0].episode
                            elif len(curResult.episodes) > 1:
                                epNum = MULTI_EP_RESULT

                            if epNum in found_results[providerObj.name]:
                                found_results[providerObj.name][epNum].append(
                                    curResult)
                            else:
                                found_results[providerObj.name][epNum] = [
                                    curResult
                                ]

                    # If this is a torrent all we can do is leech the entire torrent, user will have to select which eps not do download in his torrent client
                    else:
                        # Season result from Torrent Provider must be a full-season torrent, creating multi-ep result for it.
                        sickrage.app.log.info(
                            "Adding multi-ep result for full-season torrent. Set the episodes you don't want to 'don't download' in your torrent client if desired!"
                        )

                        epObjs = []
                        for curEpNum in allEps:
                            for season in set([x.season for x in episodes]):
                                epObjs.append(
                                    show.get_episode(season, curEpNum))
                        bestSeasonResult.episodes = epObjs

                        if MULTI_EP_RESULT in found_results[providerObj.name]:
                            found_results[providerObj.name][
                                MULTI_EP_RESULT].append(bestSeasonResult)
                        else:
                            found_results[
                                providerObj.name][MULTI_EP_RESULT] = [
                                    bestSeasonResult
                                ]

            # go through multi-ep results and see if we really want them or not, get rid of the rest
            multiResults = {}
            if MULTI_EP_RESULT in found_results[providerObj.name]:
                for _multiResult in found_results[
                        providerObj.name][MULTI_EP_RESULT]:

                    sickrage.app.log.debug(
                        "Seeing if we want to bother with multi-episode result "
                        + _multiResult.name)

                    # Filter result by ignore/required/whitelist/blacklist/quality, etc
                    multiResult = pickBestResult(_multiResult, show)
                    if not multiResult:
                        continue

                    # see how many of the eps that this result covers aren't covered by single results
                    neededEps = []
                    notNeededEps = []
                    for epObj in multiResult.episodes:
                        # if we have results for the episode
                        if epObj.episode in found_results[
                                providerObj.name] and len(found_results[
                                    providerObj.name][epObj.episode]) > 0:
                            notNeededEps.append(epObj.episode)
                        else:
                            neededEps.append(epObj.episode)

                    sickrage.app.log.debug(
                        "Single-ep check result is neededEps: " +
                        str(neededEps) + ", notNeededEps: " +
                        str(notNeededEps))

                    if not neededEps:
                        sickrage.app.log.debug(
                            "All of these episodes were covered by single episode results, ignoring this multi-episode result"
                        )
                        continue

                    # check if these eps are already covered by another multi-result
                    multiNeededEps = []
                    multiNotNeededEps = []
                    for epObj in multiResult.episodes:
                        if epObj.episode in multiResults:
                            multiNotNeededEps.append(epObj.episode)
                        else:
                            multiNeededEps.append(epObj.episode)

                    sickrage.app.log.debug(
                        "Multi-ep check result is multiNeededEps: " +
                        str(multiNeededEps) + ", multiNotNeededEps: " +
                        str(multiNotNeededEps))

                    if not multiNeededEps:
                        sickrage.app.log.debug(
                            "All of these episodes were covered by another multi-episode nzbs, ignoring this multi-ep result"
                        )
                        continue

                    # don't bother with the single result if we're going to get it with a multi result
                    for epObj in multiResult.episodes:
                        multiResults[epObj.episode] = multiResult
                        if epObj.episode in found_results[providerObj.name]:
                            sickrage.app.log.debug(
                                "A needed multi-episode result overlaps with a single-episode result for ep #"
                                + str(epObj.episode) +
                                ", removing the single-episode results from the list"
                            )
                            del found_results[providerObj.name][epObj.episode]

            # of all the single ep results narrow it down to the best one for each episode
            final_results += set(multiResults.values())
            for curEp in found_results[providerObj.name]:
                if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
                    continue

                if not len(found_results[providerObj.name][curEp]) > 0:
                    continue

                # if all results were rejected move on to the next episode
                bestResult = pickBestResult(
                    found_results[providerObj.name][curEp], show)
                if not bestResult:
                    continue

                # add result if its not a duplicate and
                found = False
                for i, result in enumerate(final_results):
                    for bestResultEp in bestResult.episodes:
                        if bestResultEp in result.episodes:
                            if result.quality < bestResult.quality:
                                final_results.pop(i)
                            else:
                                found = True
                if not found:
                    final_results += [bestResult]

            # check that we got all the episodes we wanted first before doing a match and snatch
            wantedEpCount = 0
            for wantedEp in episodes:
                for result in final_results:
                    if wantedEp in result.episodes and isFinalResult(result):
                        wantedEpCount += 1

            # make sure we search every provider for results unless we found everything we wanted
            if wantedEpCount == len(episodes):
                break

        return final_results
Ejemplo n.º 3
0
    def perform_searches():

        finalResults = []
        didSearch = False

        for providerID, providerObj in providers.items():
            if providerObj.anime_only and not show.is_anime:
                sickrage.LOGGER.debug("" + str(show.name) +
                                      " is not an anime, skiping")
                continue

            threading.currentThread().setName(origThreadName + "::[" +
                                              providerObj.name + "]")

            foundResults[providerObj.name] = {}

            searchCount = 0
            search_mode = providerObj.search_mode

            # Always search for episode when manually searching when in sponly
            if search_mode == 'sponly' and manualSearch == True:
                search_mode = 'eponly'

            while True:
                searchCount += 1

                if search_mode == 'eponly':
                    sickrage.LOGGER.info("Performing episode search for " +
                                         show.name)
                else:
                    sickrage.LOGGER.info("Performing season pack search for " +
                                         show.name)

                try:
                    providerObj.cache.updateCache()
                    searchResults = providerObj.findSearchResults(
                        show, episodes, search_mode, manualSearch,
                        downCurQuality)
                except AuthException as e:
                    sickrage.LOGGER.error("Authentication error: {}".format(e))
                    break
                except Exception as e:
                    sickrage.LOGGER.error("Error while searching " +
                                          providerObj.name +
                                          ", skipping: {}".format(e))
                    sickrage.LOGGER.debug(traceback.format_exc())
                    break

                didSearch = True

                if len(searchResults):
                    # make a list of all the results for this provider
                    for curEp in searchResults:
                        if curEp in foundResults:
                            foundResults[providerObj.
                                         name][curEp] += searchResults[curEp]
                        else:
                            foundResults[
                                providerObj.name][curEp] = searchResults[curEp]

                    break
                elif not providerObj.search_fallback or searchCount == 2:
                    break

                if search_mode == 'sponly':
                    sickrage.LOGGER.debug("Fallback episode search initiated")
                    search_mode = 'eponly'
                else:
                    sickrage.LOGGER.debug(
                        "Fallback season pack search initiate")
                    search_mode = 'sponly'

            # skip to next provider if we have no results to process
            if not len(foundResults[providerObj.name]):
                continue

            # pick the best season NZB
            bestSeasonResult = None
            if SEASON_RESULT in foundResults[providerObj.name]:
                bestSeasonResult = pickBestResult(
                    foundResults[providerObj.name][SEASON_RESULT], show)

            highest_quality_overall = 0
            for cur_episode in foundResults[providerObj.name]:
                for cur_result in foundResults[providerObj.name][cur_episode]:
                    if cur_result.quality != Quality.UNKNOWN and cur_result.quality > highest_quality_overall:
                        highest_quality_overall = cur_result.quality
            sickrage.LOGGER.debug(
                "The highest quality of any match is " +
                Quality.qualityStrings[highest_quality_overall])

            # see if every episode is wanted
            if bestSeasonResult:
                searchedSeasons = [str(x.season) for x in episodes]

                # get the quality of the season nzb
                seasonQual = bestSeasonResult.quality
                sickrage.LOGGER.debug("The quality of the season " +
                                      bestSeasonResult.provider.type + " is " +
                                      Quality.qualityStrings[seasonQual])

                allEps = [
                    int(x[b"episode"]) for x in main_db.MainDB().select(
                        "SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( "
                        + ','.join(searchedSeasons) + " ) )", [show.indexerid])
                ]

                sickrage.LOGGER.info(
                    "Executed query: [SELECT episode FROM tv_episodes WHERE showid = %s AND season in  %s]"
                    % (show.indexerid, ','.join(searchedSeasons)))
                sickrage.LOGGER.debug("Episode list: " + str(allEps))

                allWanted = True
                anyWanted = False
                for curEpNum in allEps:
                    for season in set([x.season for x in episodes]):
                        if not show.wantEpisode(season, curEpNum, seasonQual,
                                                downCurQuality):
                            allWanted = False
                        else:
                            anyWanted = True

                # if we need every ep in the season and there's nothing better then just download this and be done with it (unless single episodes are preferred)
                if allWanted and bestSeasonResult.quality == highest_quality_overall:
                    sickrage.LOGGER.info(
                        "Every ep in this season is needed, downloading the whole "
                        + bestSeasonResult.provider.type + " " +
                        bestSeasonResult.name)
                    epObjs = []
                    for curEpNum in allEps:
                        for season in set([x.season for x in episodes]):
                            epObjs.append(show.getEpisode(season, curEpNum))
                    bestSeasonResult.episodes = epObjs

                    return [bestSeasonResult]

                elif not anyWanted:
                    sickrage.LOGGER.debug(
                        "No eps from this season are wanted at this quality, ignoring the result of "
                        + bestSeasonResult.name)

                else:

                    if bestSeasonResult.provider.type == GenericProvider.NZB:
                        sickrage.LOGGER.debug(
                            "Breaking apart the NZB and adding the individual ones to our results"
                        )

                        # if not, break it apart and add them as the lowest priority results
                        individualResults = splitNZBResult(bestSeasonResult)
                        for curResult in individualResults:
                            if len(curResult.episodes) == 1:
                                epNum = curResult.episodes[0].episode
                            elif len(curResult.episodes) > 1:
                                epNum = MULTI_EP_RESULT

                            if epNum in foundResults[providerObj.name]:
                                foundResults[providerObj.name][epNum].append(
                                    curResult)
                            else:
                                foundResults[providerObj.name][epNum] = [
                                    curResult
                                ]

                    # If this is a torrent all we can do is leech the entire torrent, user will have to select which eps not do download in his torrent client
                    else:

                        # Season result from Torrent Provider must be a full-season torrent, creating multi-ep result for it.
                        sickrage.LOGGER.info(
                            "Adding multi-ep result for full-season torrent. Set the episodes you don't want to 'don't download' in your torrent client if desired!"
                        )
                        epObjs = []
                        for curEpNum in allEps:
                            for season in set([x.season for x in episodes]):
                                epObjs.append(show.getEpisode(
                                    season, curEpNum))
                        bestSeasonResult.episodes = epObjs

                        if MULTI_EP_RESULT in foundResults[providerObj.name]:
                            foundResults[providerObj.name][
                                MULTI_EP_RESULT].append(bestSeasonResult)
                        else:
                            foundResults[providerObj.name][MULTI_EP_RESULT] = [
                                bestSeasonResult
                            ]

            # go through multi-ep results and see if we really want them or not, get rid of the rest
            multiResults = {}
            if MULTI_EP_RESULT in foundResults[providerObj.name]:
                for _multiResult in foundResults[
                        providerObj.name][MULTI_EP_RESULT]:

                    sickrage.LOGGER.debug(
                        "Seeing if we want to bother with multi-episode result "
                        + _multiResult.name)

                    # Filter result by ignore/required/whitelist/blacklist/quality, etc
                    multiResult = pickBestResult(_multiResult, show)
                    if not multiResult:
                        continue

                    # see how many of the eps that this result covers aren't covered by single results
                    neededEps = []
                    notNeededEps = []
                    for epObj in multiResult.episodes:
                        # if we have results for the episode
                        if epObj.episode in foundResults[
                                providerObj.name] and len(foundResults[
                                    providerObj.name][epObj.episode]) > 0:
                            notNeededEps.append(epObj.episode)
                        else:
                            neededEps.append(epObj.episode)

                    sickrage.LOGGER.debug(
                        "Single-ep check result is neededEps: " +
                        str(neededEps) + ", notNeededEps: " +
                        str(notNeededEps))

                    if not neededEps:
                        sickrage.LOGGER.debug(
                            "All of these episodes were covered by single episode results, ignoring this multi-episode result"
                        )
                        continue

                    # check if these eps are already covered by another multi-result
                    multiNeededEps = []
                    multiNotNeededEps = []
                    for epObj in multiResult.episodes:
                        if epObj.episode in multiResults:
                            multiNotNeededEps.append(epObj.episode)
                        else:
                            multiNeededEps.append(epObj.episode)

                    sickrage.LOGGER.debug(
                        "Multi-ep check result is multiNeededEps: " +
                        str(multiNeededEps) + ", multiNotNeededEps: " +
                        str(multiNotNeededEps))

                    if not multiNeededEps:
                        sickrage.LOGGER.debug(
                            "All of these episodes were covered by another multi-episode nzbs, ignoring this multi-ep result"
                        )
                        continue

                    # don't bother with the single result if we're going to get it with a multi result
                    for epObj in multiResult.episodes:
                        multiResults[epObj.episode] = multiResult
                        if epObj.episode in foundResults[providerObj.name]:
                            sickrage.LOGGER.debug(
                                "A needed multi-episode result overlaps with a single-episode result for ep #"
                                + str(epObj.episode) +
                                ", removing the single-episode results from the list"
                            )
                            del foundResults[providerObj.name][epObj.episode]

            # of all the single ep results narrow it down to the best one for each episode
            finalResults += set(multiResults.values())
            for curEp in foundResults[providerObj.name]:
                if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
                    continue

                if not len(foundResults[providerObj.name][curEp]) > 0:
                    continue

                # if all results were rejected move on to the next episode
                bestResult = pickBestResult(
                    foundResults[providerObj.name][curEp], show)
                if not bestResult:
                    continue

                # add result if its not a duplicate and
                found = False
                for i, result in enumerate(finalResults):
                    for bestResultEp in bestResult.episodes:
                        if bestResultEp in result.episodes:
                            if result.quality < bestResult.quality:
                                finalResults.pop(i)
                            else:
                                found = True
                if not found:
                    finalResults += [bestResult]

            # check that we got all the episodes we wanted first before doing a match and snatch
            wantedEpCount = 0
            for wantedEp in episodes:
                for result in finalResults:
                    if wantedEp in result.episodes and isFinalResult(result):
                        wantedEpCount += 1

            # make sure we search every provider for results unless we found everything we wanted
            if wantedEpCount == len(episodes):
                break

        if not didSearch:
            sickrage.LOGGER.warning(
                "No NZB/Torrent providers found or enabled in the sickrage config for backlog searches. Please check your settings."
            )

        return finalResults