Пример #1
0
    def _get_season_search_strings(ep_obj, **kwargs):
        search_params = []
        current_params = {'category': 'Season'}

        # Search for entire seasons: no need to do special things for air by date or sports shows
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            # Search for the year of the air by date show
            current_params['name'] = str(ep_obj.airdate).split('-')[0]
        elif ep_obj.show.is_anime:
            current_params['name'] = "%d" % ep_obj.scene_absolute_number
        else:
            current_params['name'] = 'Season ' + str(ep_obj.scene_season)

        # search
        if ep_obj.show.indexer == 1:
            current_params['tvdb'] = ep_obj.show.indexerid
            search_params.append(current_params)
        else:
            name_exceptions = list(
                    set(get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
            for name in name_exceptions:
                # Search by name if we don't have tvdb id
                current_params['series'] = sanitizeSceneName(name)
                search_params.append(current_params)

        return search_params
Пример #2
0
    def _get_episode_search_strings(self, episode, add_string=''):
        search_string = {'Episode': []}

        if not episode:
            return []

        for show_name in set(show_names.allPossibleShowNames(episode.show)):
            for sep in ' ', ' - ':
                ep_string = sanitizeSceneName(show_name) + sep
                if episode.show.air_by_date:
                    ep_string += str(episode.airdate)
                elif episode.show.sports:
                    ep_string += str(
                        episode.airdate) + '|' + episode.airdate.strftime('%b')
                elif episode.show.anime:
                    ep_string += '%i' % int(episode.scene_absolute_number)
                else:
                    ep_string += sickrage.app.naming_ep_type[4] % {
                        'seasonnumber': episode.scene_season,
                        'episodenumber': episode.scene_episode
                    }

                if add_string:
                    ep_string += ' %s' % add_string

                search_string['Episode'].append(
                    re.sub(r'\s+', ' ',
                           ep_string.replace('.', ' ').strip()))

        return [search_string]
Пример #3
0
def get_scene_exception_by_name_multiple(show_name):
    """
    Given a show name, return the indexerid of the exception, None if no exception
    is present.
    """

    out = []

    dbData = sorted([x['doc'] for x in sickrage.srCore.cacheDB.db.all('scene_exceptions', with_doc=True)], key=lambda d: d['season'])

    # try the obvious case first
    exception_result = [x for x in dbData if x['show_name'].lower() == show_name.lower()]
    if exception_result:
        return [(int(x['indexer_id']), int(x['season'])) for x in exception_result]

    for cur_exception in dbData:
        cur_exception_name = cur_exception['show_name']
        cur_indexer_id = int(cur_exception['indexer_id'])
        cur_season = int(cur_exception['season'])

        if show_name.lower() in (
                cur_exception_name.lower(),
                sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')):
            sickrage.srCore.srLogger.debug(
                "Scene exception lookup got indexer id " + str(cur_indexer_id) + ", using that")
            out.append((cur_indexer_id, cur_season))

    if out:
        return out
    return [(None, None)]
Пример #4
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []
        params = {}
        if not ep_obj:
            return to_return

        params['maxage'] = (datetime.datetime.now() - datetime.datetime.combine(ep_obj.airdate,
                                                                                datetime.datetime.min.time())).days + 1
        params['tvdbid'] = ep_obj.show.indexerid

        # season
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate).split('-')[0]
            params['season'] = date_str
            params['q'] = date_str.replace('-', '.')
        else:
            params['season'] = str(ep_obj.scene_season)

        save_q = ' ' + params['q'] if 'q' in params else ''

        # add new query strings for exceptions
        name_exceptions = list(
            set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = sanitizeSceneName(cur_exception) + save_q
            to_return.append(dict(params))

        return to_return
Пример #5
0
    def _get_season_search_strings(ep_obj, **kwargs):
        search_params = []
        current_params = {'category': 'Season'}

        # Search for entire seasons: no need to do special things for air by date or sports shows
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            # Search for the year of the air by date show
            current_params['name'] = str(ep_obj.airdate).split('-')[0]
        elif ep_obj.show.is_anime:
            current_params['name'] = "%d" % ep_obj.scene_absolute_number
        else:
            current_params['name'] = 'Season ' + str(ep_obj.scene_season)

        # search
        if ep_obj.show.indexer == 1:
            current_params['tvdb'] = ep_obj.show.indexerid
            search_params.append(current_params)
        else:
            name_exceptions = list(
                set(
                    get_scene_exceptions(ep_obj.show.indexerid) +
                    [ep_obj.show.name]))
            for name in name_exceptions:
                # Search by name if we don't have tvdb id
                current_params['series'] = sanitizeSceneName(name)
                search_params.append(current_params)

        return search_params
Пример #6
0
def get_scene_exception_by_name_multiple(show_name):
    """
    Given a show name, return the indexerid of the exception, None if no exception
    is present.
    """

    out = []

    # try the obvious case first
    exception_result = [
        x for x in sorted(sickrage.app.cache_db.all('scene_exceptions'),
                          key=lambda d: d['season'])
        if x['show_name'].lower() == show_name.lower()
    ]
    if exception_result:
        return [(int(x['indexer_id']), int(x['season']))
                for x in exception_result]

    for cur_exception in sorted(sickrage.app.cache_db.all('scene_exceptions'),
                                key=lambda d: d['season']):
        cur_exception_name = cur_exception['show_name']
        cur_indexer_id = int(cur_exception['indexer_id'])
        cur_season = int(cur_exception['season'])

        if show_name.lower() in (
                cur_exception_name.lower(),
                sanitizeSceneName(cur_exception_name).lower().replace(
                    '.', ' ')):
            sickrage.app.log.debug("Scene exception lookup got indexer id " +
                                   str(cur_indexer_id) + ", using that")
            out.append((cur_indexer_id, cur_season))

    if out:
        return out
    return [(None, None)]
Пример #7
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        to_return = []
        params = {}
        if not ep_obj:
            return to_return

        params['maxage'] = (datetime.datetime.now() - datetime.datetime.combine(ep_obj.airdate,
                                                                                datetime.datetime.min.time())).days + 1
        params['tvdbid'] = ep_obj.show.indexerid

        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate)
            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        else:
            params['season'] = ep_obj.scene_season
            params['ep'] = ep_obj.scene_episode

        # add new query strings for exceptions
        name_exceptions = list(
            set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Пример #8
0
    def _get_episode_search_strings(self, episode, add_string=''):
        search_string = {'Episode': []}

        if not episode:
            return []

        for show_name in set(show_names.allPossibleShowNames(episode.show)):
            for sep in ' ', ' - ':
                ep_string = sanitizeSceneName(show_name) + sep
                if episode.show.air_by_date:
                    ep_string += str(episode.airdate)
                elif episode.show.sports:
                    ep_string += str(episode.airdate) + '|' + episode.airdate.strftime('%b')
                elif episode.show.anime:
                    ep_string += '%i' % int(episode.scene_absolute_number)
                else:
                    ep_string += sickrage.app.naming_ep_type[4] % {'seasonnumber': episode.scene_season,
                                                                   'episodenumber': episode.scene_episode}

                if add_string:
                    ep_string += ' %s' % add_string

                search_string['Episode'].append(re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip()))

        return [search_string]
Пример #9
0
    def _get_episode_search_strings(ep_obj, add_string='', **kwargs):

        if not ep_obj:
            return [{}]

        to_return = []
        search_params = {'category': 'Episode'}

        # episode
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate)

            # BTN uses dots in dates, we just search for the date since that
            # combined with the series identifier should result in just one episode
            search_params['name'] = date_str.replace('-', '.')
        elif ep_obj.show.anime:
            search_params['name'] = "%i" % int(ep_obj.scene_absolute_number)
        else:
            # Do a general name search for the episode, formatted like SXXEYY
            search_params['name'] = "S%02dE%02d" % (ep_obj.scene_season, ep_obj.scene_episode)

        # search
        if ep_obj.show.indexer == 1:
            search_params['tvdb'] = ep_obj.show.indexerid
            to_return.append(search_params)
        else:
            # add new query string for every exception
            name_exceptions = list(
                    set(get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
            for cur_exception in name_exceptions:
                search_params['series'] = sanitizeSceneName(cur_exception)
                to_return.append(search_params)

        return to_return
Пример #10
0
    def _get_episode_search_strings(ep_obj, add_string='', **kwargs):

        if not ep_obj:
            return [{}]

        to_return = []
        search_params = {'category': 'Episode'}

        # episode
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate)

            # BTN uses dots in dates, we just search for the date since that
            # combined with the series identifier should result in just one episode
            search_params['name'] = date_str.replace('-', '.')
        elif ep_obj.show.anime:
            search_params['name'] = "%i" % int(ep_obj.scene_absolute_number)
        else:
            # Do a general name search for the episode, formatted like SXXEYY
            search_params['name'] = "S%02dE%02d" % (ep_obj.scene_season, ep_obj.scene_episode)

        # search
        if ep_obj.show.indexer == 1:
            search_params['tvdb'] = ep_obj.show.indexerid
            to_return.append(search_params)
        else:
            # add new query string for every exception
            name_exceptions = list(
                set(get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
            for cur_exception in name_exceptions:
                search_params['series'] = sanitizeSceneName(cur_exception)
                to_return.append(search_params)

        return to_return
Пример #11
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        to_return = []
        params = {}
        if not ep_obj:
            return to_return

        params['maxage'] = (datetime.datetime.now() - datetime.datetime.combine(ep_obj.airdate,
                                                                                datetime.datetime.min.time())).days + 1
        params['tvdbid'] = ep_obj.show.indexerid

        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate)
            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        else:
            params['season'] = ep_obj.scene_season
            params['ep'] = ep_obj.scene_episode

        # add new query strings for exceptions
        name_exceptions = list(
            set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Пример #12
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []
        params = {}
        if not ep_obj:
            return to_return

        params['maxage'] = (datetime.datetime.now() - datetime.datetime.combine(ep_obj.airdate,
                                                                                datetime.datetime.min.time())).days + 1
        params['tvdbid'] = ep_obj.show.indexerid

        # season
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate).split('-')[0]
            params['season'] = date_str
            params['q'] = date_str.replace('-', '.')
        else:
            params['season'] = str(ep_obj.scene_season)

        save_q = ' ' + params['q'] if 'q' in params else ''

        # add new query strings for exceptions
        name_exceptions = list(
            set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = sanitizeSceneName(cur_exception) + save_q
            to_return.append(dict(params))

        return to_return
Пример #13
0
def get_scene_exception_by_name_multiple(show_name):
    """
    Given a show name, return the indexerid of the exception, None if no exception
    is present.
    """

    # try the obvious case first
    exception_result = cache_db.CacheDB().select(
            "SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC",
            [show_name.lower()])
    if exception_result:
        return [(int(x[b"indexer_id"]), int(x[b"season"])) for x in exception_result]

    out = []
    all_exception_results = cache_db.CacheDB().select("SELECT show_name, indexer_id, season FROM scene_exceptions")

    for cur_exception in all_exception_results:

        cur_exception_name = cur_exception[b"show_name"]
        cur_indexer_id = int(cur_exception[b"indexer_id"])
        cur_season = int(cur_exception[b"season"])

        if show_name.lower() in (
                cur_exception_name.lower(),
                sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')):
            sickrage.LOGGER.debug("Scene exception lookup got indexer id " + str(cur_indexer_id) + ", using that")
            out.append((cur_indexer_id, cur_season))

    if out:
        return out

    return [(None, None)]
Пример #14
0
    def _search_params(self, ep_obj, mode, season_numbering=None):
        if not ep_obj:
            return []

        searches = []
        season = 'Season' if mode == 'Season' else ''

        air_by_date = ep_obj.show.air_by_date
        sports = ep_obj.show.sports

        if not season_numbering and (air_by_date or sports):
            date_fmt = '%Y' if season else '%Y.%m.%d'
            search_name = ep_obj.airdate.strftime(date_fmt)
        else:
            search_name = '{type} {number}'.format(
                type=season,
                number=ep_obj.scene_season if season else episode_num(
                    ep_obj.scene_season, ep_obj.scene_episode
                ),
            ).strip()

        params = {
            'category': season or 'Episode',
            'name': search_name,
        }

        # Search
        if ep_obj.show.indexer == 1:
            params['tvdb'] = ep_obj.show.indexerid
            searches.append(params)
        else:
            name_exceptions = list(
                set(scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
            for name in name_exceptions:
                # Search by name if we don't have tvdb id
                params['series'] = sanitizeSceneName(name)
                searches.append(params)

        # extend air by date searches to include season numbering
        if air_by_date and not season_numbering:
            searches.extend(
                self._search_params(ep_obj, mode, season_numbering=True)
            )

        return searches
Пример #15
0
    def _search_params(self, ep_obj, mode, season_numbering=None):
        if not ep_obj:
            return []

        searches = []
        season = 'Season' if mode == 'Season' else ''

        air_by_date = ep_obj.show.air_by_date
        sports = ep_obj.show.sports

        if not season_numbering and (air_by_date or sports):
            date_fmt = '%Y' if season else '%Y.%m.%d'
            search_name = ep_obj.airdate.strftime(date_fmt)
        else:
            search_name = '{type} {number}'.format(
                type=season,
                number=ep_obj.season if season else episode_num(
                    ep_obj.season, ep_obj.episode
                ),
            ).strip()

        params = {
            'category': season or 'Episode',
            'name': search_name,
        }

        # Search
        if ep_obj.show.indexer == 1:
            params['tvdb'] = ep_obj.show.indexerid
            searches.append(params)
        else:
            name_exceptions = list(
                set(scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
            for name in name_exceptions:
                # Search by name if we don't have tvdb id
                params['series'] = sanitizeSceneName(name)
                searches.append(params)

        # extend air by date searches to include season numbering
        if air_by_date and not season_numbering:
            searches.extend(
                self._search_params(ep_obj, mode, season_numbering=True)
            )

        return searches
Пример #16
0
def get_scene_exception_by_name_multiple(show_name):
    """
    Given a show name, return the indexerid of the exception, None if no exception
    is present.
    """

    # try the obvious case first
    exception_result = cache_db.CacheDB().select(
        "SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC",
        [show_name.lower()])
    if exception_result:
        return [(int(x["indexer_id"]), int(x["season"]))
                for x in exception_result]

    out = []
    all_exception_results = cache_db.CacheDB().select(
        "SELECT show_name, indexer_id, season FROM scene_exceptions")

    for cur_exception in all_exception_results:

        cur_exception_name = cur_exception["show_name"]
        cur_indexer_id = int(cur_exception["indexer_id"])
        cur_season = int(cur_exception["season"])

        if show_name.lower() in (
                cur_exception_name.lower(),
                sanitizeSceneName(cur_exception_name).lower().replace(
                    '.', ' ')):
            sickrage.srCore.srLogger.debug(
                "Scene exception lookup got indexer id " +
                str(cur_indexer_id) + ", using that")
            out.append((cur_indexer_id, cur_season))

    if out:
        return out

    return [(None, None)]
Пример #17
0
 def dot(name):
     return sanitizeSceneName(name)
Пример #18
0
 def dot(name):
     return sanitizeSceneName(name)