Exemplo n.º 1
0
    def _get_episode_search_strings(self, ep_obj, add_string=""):
        if not ep_obj:
            return []

        search_strings = []
        for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
            if self.show.air_by_date:
                ep_string = sanitizeSceneName(show_name) + " " + str(ep_obj.airdate).replace("-", "|")
            elif self.show.sports:
                ep_string = (
                    sanitizeSceneName(show_name)
                    + " "
                    + str(ep_obj.airdate).replace("-", "|")
                    + "|"
                    + ep_obj.airdate.strftime("%b")
                )
            elif self.show.anime:
                ep_string = sanitizeSceneName(show_name) + " " + "%i" % int(ep_obj.scene_absolute_number)
            else:
                ep_string = (
                    sanitizeSceneName(show_name)
                    + " "
                    + sickbeard.config.naming_ep_type[2]
                    % {"seasonnumber": ep_obj.scene_season, "episodenumber": ep_obj.scene_episode}
                )
            if add_string:
                ep_string += " %s" % add_string

            search_strings.append(ep_string)

        return [search_strings]
Exemplo n.º 2
0
    def _get_episode_search_strings(self, show, season, episode, add_string=''):

        search_string = {'Episode': []}

        if not episode:
            return []

        if show.air_by_date:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                ep_string = sanitizeSceneName(show_name) + ' ' + \
                            str(episode).replace('-', '|') + '|' + \
                            episode.strftime('%b')
                search_string['Episode'].append(ep_string)
        elif show.sports:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                ep_string = sanitizeSceneName(show_name) + ' ' + \
                            str(episode).replace('-', '|') + '|' + \
                            episode.strftime('%b')
                search_string['Episode'].append(ep_string)
        else:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
                            sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
                                                                  'episodenumber': episode}

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

        return [search_string]
Exemplo n.º 3
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []
        cur_params = {}

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

        # season
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate).split('-')[0]
            cur_params['season'] = date_str
            cur_params['q'] = date_str.replace('-', '.')
        elif ep_obj.show.is_anime:
            cur_params['season'] = "%d" % ep_obj.scene_absolute_number
        else:
            cur_params['season'] = str(ep_obj.scene_season)

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_params['rid'] = rid
        elif 'rid' in cur_params:
            cur_params.pop('rid')

        # add new query strings for exceptions
        name_exceptions = list(
            set(scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]))
        for cur_exception in name_exceptions:
            if 'q' in cur_params:
                cur_params['q'] = helpers.sanitizeSceneName(cur_exception) + '.' + cur_params['q']
            else:
                cur_params['q'] = helpers.sanitizeSceneName(cur_exception)
            to_return.append(cur_params)

        return to_return
Exemplo n.º 4
0
    def _get_season_search_strings(self, show, season=None):
        search_string = []

        if not (show and season):
            return []

        myDB = db.DBConnection()

        if show.air_by_date:
            (min_date, max_date) = self._get_airbydate_season_range(season)
            sqlResults = myDB.select(
                "SELECT DISTINCT airdate FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= ? AND status = ?",
                [show.tvdbid, min_date.toordinal(), max_date.toordinal(), WANTED],
            )
        else:
            sqlResults = myDB.select(
                "SELECT DISTINCT season FROM tv_episodes WHERE showid = ? AND season = ? AND status = ?",
                [show.tvdbid, season, WANTED],
            )

        for sqlEp in sqlResults:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                if show.air_by_date:
                    ep_string = (
                        sanitizeSceneName(show_name)
                        + " "
                        + str(datetime.date.fromordinal(sqlEp["airdate"])).replace("-", ".")
                    )
                    search_string.append(ep_string)
                else:
                    ep_string = sanitizeSceneName(show_name) + " S%02d" % sqlEp["season"]
                    search_string.append(ep_string)

        return search_string
Exemplo n.º 5
0
    def _get_episode_search_strings(self, ep_obj, add_string=""):

        search_string = {"Episode": []}

        if not ep_obj:
            return []

        if self.show.air_by_date:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = sanitizeSceneName(show_name) + " " + str(ep_obj.airdate).replace("-", "|")
                search_string["Episode"].append(ep_string)
        elif self.show.sports:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = (
                    sanitizeSceneName(show_name)
                    + " "
                    + str(ep_obj.airdate).replace("-", "|")
                    + "|"
                    + ep_obj.airdate.strftime("%b")
                )
                search_string["Episode"].append(ep_string)
        else:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = (
                    show_name_helpers.sanitizeSceneName(show_name)
                    + " "
                    + sickbeard.config.naming_ep_type[2]
                    % {"seasonnumber": ep_obj.scene_season, "episodenumber": ep_obj.scene_episode}
                )

                search_string["Episode"].append(re.sub("\s+", " ", ep_string))

        return [search_string]
Exemplo n.º 6
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        search_strings = []

        if not ep_obj:
            return []

        for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
            if self.show.air_by_date:
                ep_string = sanitizeSceneName(show_name) + ' ' + str(ep_obj.airdate).replace('-', '.')
            elif self.show.sports:
                ep_string = sanitizeSceneName(show_name) + ' ' + str(ep_obj.airdate).replace('-', '.') + '|' + \
                        ep_obj.airdate.strftime('%b')
            elif self.show.anime:
                ep_string = sanitizeSceneName(show_name) + ' %i' % int(ep_obj.scene_absolute_number)
            else:
                ep_string = sanitizeSceneName(show_name) + ' ' + \
                        sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season,
                                                                  'episodenumber': ep_obj.scene_episode}

            if len(add_string):
                ep_string += ' %s' % add_string

            search_strings.append(ep_string)

        return search_strings
Exemplo n.º 7
0
    def _get_episode_search_strings(self, ep_obj,french=None):
    
        params = {}
        
        global lang
        
        if not ep_obj:
            return [params]

        params['show_name'] = helpers.sanitizeSceneName(ep_obj.show.name).replace('.',' ').encode('utf-8')
        
        if ep_obj.show.air_by_date:
            params['date'] = str(ep_obj.airdate)
        else:
            params['season'] = ep_obj.season
            params['episode'] = ep_obj.episode

        to_return = [params]

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(ep_obj.show.tvdbid)
        for name_exception in name_exceptions:
            # don't add duplicates
            if name_exception != ep_obj.show.name:
                # only change show name
                cur_return = params.copy()
                cur_return['show_name'] = helpers.sanitizeSceneName(name_exception)
                to_return.append(cur_return)

        logger.log(u"KAT _get_episode_search_strings for %s is returning %s" % (repr(ep_obj), repr(params)), logger.DEBUG)
        if french:
            lang='fr'
        else:
            lang = ep_obj.show.audio_lang
        return to_return
Exemplo n.º 8
0
    def test_formating(self):
        self.loadFromDB()
        show = sickbeard.helpers.findCertainShow(sickbeard.showList, 75978)
        ep = show.getEpisode(7, 6)
        ep.airdate = datetime.datetime.now()

        print format(ep.episode, '02d')
        print format(ep.scene_episode, '02d')

        search_string = {'Episode':[]}
        episode = ep.airdate
        str(episode).replace('-', '|')
        ep_string = sanitizeSceneName(show.name) + ' ' + \
                    str(episode).replace('-', '|') + '|' + \
                    sickbeard.helpers.custom_strftime('%b', episode)

        search_string['Episode'].append(ep_string)

        scene_ep_string = sanitizeSceneName(show.name) + ' ' + \
                    sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + '|' + \
                    sickbeard.config.naming_ep_type[0] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + '|' + \
                    sickbeard.config.naming_ep_type[3] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + ' %s category:tv' % ''

        scene_season_string = show.name + ' S%02d' % int(ep.scene_season) + ' -S%02d' % int(ep.scene_season) + 'E' + ' category:tv'  #1) ShowName SXX -SXXE


        print(
            u'Searching "%s" for "%s" as "%s"' % (show.name, ep.prettyName(), ep.scene_prettyName()))

        print('Scene episode search strings: %s' % (scene_ep_string))

        print('Scene season search strings: %s' % (scene_season_string))
Exemplo n.º 9
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        search_string = {'Episode': []}

        if not ep_obj:
            return []

        if self.show.air_by_date:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = sanitizeSceneName(show_name) + '.' + \
                            str(ep_obj.airdate).replace('-', '|')
                search_string['Episode'].append(ep_string)
        elif self.show.sports:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = sanitizeSceneName(show_name) + '.' + \
                            str(ep_obj.airdate).replace('-', '|') + '|' + \
                            ep_obj.airdate.strftime('%b')
                search_string['Episode'].append(ep_string)
        elif self.show.anime:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = sanitizeSceneName(show_name) + '.' + \
                            "%i" % int(ep_obj.scene_absolute_number)
                search_string['Episode'].append(ep_string)
        else:
            for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
                ep_string = show_name_helpers.sanitizeSceneName(show_name) + '.' + \
                            sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season,
                                                                  'episodenumber': ep_obj.scene_episode} + ' %s' % add_string

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

        return [search_string]
Exemplo n.º 10
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        if not ep_obj:
            return [{}]

        search_params = {'category': 'Episode'}

        if self.show.indexer == 1:
            search_params['tvdb'] = self.show.indexerid
        elif self.show.indexer == 2:
            search_params['tvrage'] = self.show.indexerid
        else:
            search_params['series'] = sanitizeSceneName(self.show.name)

        if self.show.air_by_date:
            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 self.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'] = ep_obj.airdate.strftime('%b')
        elif self.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)

        to_return = [search_params]

        # only do scene exceptions if we are searching by name
        if 'series' in search_params:

            # add new query string for every exception
            name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid)
            for cur_exception in name_exceptions:

                # don't add duplicates
                if cur_exception == self.show.name:
                    continue

                # copy all other parameters before setting the show name for this exception
                cur_return = search_params.copy()
                cur_return['series'] = sanitizeSceneName(cur_exception)
                to_return.append(cur_return)

        return to_return
Exemplo n.º 11
0
    def _get_episode_search_strings(self, ep_obj, french=None):
        showNames = show_name_helpers.allPossibleShowNames(ep_obj.show)
        for show_name in showNames:
            ep_obj.show.sname=show_name
            params = {}

            if not ep_obj:
                return [params]
        
        # search directly by tvrage id
            if ep_obj.show.tvrid:
                params['rid'] = ep_obj.show.tvrid
                if ep_obj.show.audio_lang=="fr" or french:
                    params['q'] = "french"
                else:
                    params['q'] = helpers.sanitizeSceneName(ep_obj.show.sname)
        # if we can't then fall back on a very basic name search
            else:
                if ep_obj.show.audio_lang=="fr" or french:
                    params['q'] = helpers.sanitizeSceneName(ep_obj.show.sname) + " french"
                else:
                    params['q'] = helpers.sanitizeSceneName(ep_obj.show.sname)

            if ep_obj.show.air_by_date:
                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

                to_return = [params]

        # only do exceptions if we are searching by name
            if 'q' in params:

            # add new query strings for exceptions
                name_exceptions = scene_exceptions.get_scene_exceptions(ep_obj.show.tvdbid)
                for cur_exception in name_exceptions:

                # don't add duplicates
                    if cur_exception == ep_obj.show.sname:
                        continue

                    cur_return = params.copy()
                    cur_return['q'] = helpers.sanitizeSceneName(cur_exception)
                    to_return.append(cur_return)

        return to_return
Exemplo n.º 12
0
    def _get_episode_search_strings(self, show, season, episode, add_string=""):

        if not episode:
            return [{}]

        search_params = {"category": "Episode"}

        if show.indexer == 1:
            search_params["tvdb"] = show.indexerid
        elif show.indexer == 2:
            search_params["tvrage"] = show.indexerid
        else:
            search_params["series"] = sanitizeSceneName(show.name)

        if show.air_by_date:
            date_str = str(episode)

            # 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("-", ".")
        if show.sports:
            date_str = str(episode)

            # 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("-", ".")
        else:
            # Do a general name search for the episode, formatted like SXXEYY
            search_params["name"] = "S%02dE%02d" % (season, episode)

        to_return = [search_params]

        # only do scene exceptions if we are searching by name
        if "series" in search_params:

            # add new query string for every exception
            name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid)
            for cur_exception in name_exceptions:

                # don't add duplicates
                if cur_exception == show.name:
                    continue

                # copy all other parameters before setting the show name for this exception
                cur_return = search_params.copy()
                cur_return["series"] = sanitizeSceneName(cur_exception)
                to_return.append(cur_return)

        return to_return
Exemplo n.º 13
0
    def _get_season_search_strings(self, show, season, wantedEp, searchSeason=False):

        if not show:
            return [{}]

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid) + [show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search

            cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            # air-by-date means &season=2010&q=2010.03, no other way to do it atm
            if show.air_by_date:
                cur_params['season'] = str(season).split('-')[0]
                if 'q' in cur_params:
                    cur_params['q'] += '.' + str(season).replace('-', '.')
                else:
                    cur_params['q'] = str(season).replace('-', '.')
            else:
                cur_params['season'] = str(season)

                to_return.append(cur_params)

        return to_return
Exemplo n.º 14
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        """
        Makes objects to pass to search for manual and backlog season pack searching
        Returns a list containing dicts of search parameters
        """
        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

        name_exceptions = list(set([ep_obj.show.name] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Exemplo n.º 15
0
    def _get_season_search_strings(self, show, season, episode):

        if not show:
            return [{}]

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(
            show.indexerid) + [show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search
            cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            # season
            cur_params['season'] = str(season)

            # episode
            cur_params['episode'] = self._get_episode_search_strings(
                show, season, episode)[0]['ep']

            to_return.append(cur_params)

        return to_return
Exemplo n.º 16
0
    def _get_season_search_strings(self, ep_obj):
        """
        Makes objects to pass to _doSearch for manual and backlog season pack searching
        Returns a list containing dicts of search parameters
        """
        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).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 ''

        name_exceptions = list(set([ep_obj.show.name] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception) + save_q
            to_return.append(dict(params))

        return to_return
Exemplo n.º 17
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        to_return = []
        params = {}

        if not ep_obj:
            return [params]

        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('-', '/')
        elif ep_obj.show.anime:
            params['ep'] = "%i" % int(ep_obj.scene_absolute_number)
        else:
            params['season'] = ep_obj.scene_season
            params['ep'] = ep_obj.scene_episode

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_return = params.copy()
            cur_return['rid'] = rid
            to_return.append(cur_return)

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

        return to_return
Exemplo n.º 18
0
    def _get_season_search_strings(self, ep_obj):
        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)
        elif ep_obj.show.indexer == 2:
            current_params['tvrage'] = ep_obj.show.indexerid
            search_params.append(current_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 or tvrage id
                current_params['series'] = sanitizeSceneName(name)
                search_params.append(current_params)

        return search_params
Exemplo n.º 19
0
def get_scene_exception_by_name_multiple(show_name):
    """
    Given a show name, return the tvdbid of the exception, None if no exception
    is present.
    """

    myDB = db.DBConnection("cache.db")

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

    out = []
    all_exception_results = myDB.select("SELECT show_name, tvdb_id, season FROM scene_exceptions")
    for cur_exception in all_exception_results:

        cur_exception_name = cur_exception["show_name"]
        cur_tvdb_id = int(cur_exception["tvdb_id"])
        cur_season = int(cur_exception["season"])

        if show_name.lower() in (cur_exception_name.lower(), sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')):
            logger.log(u"Scene exception lookup got tvdb id " + str(cur_tvdb_id) + u", using that", logger.DEBUG)
            out.append((cur_tvdb_id, cur_season))
    if out:
        return out
    else:
        return [(None, None)]
Exemplo n.º 20
0
    def _episode_strings(self, ep_obj):

        search_params = []
        base_params = {}

        if not ep_obj:
            return [base_params]

        if ep_obj.show.air_by_date or ep_obj.show.is_sports:
            date_str = str(ep_obj.airdate)
            base_params['season'] = date_str.partition('-')[0]
            base_params['ep'] = date_str.partition('-')[2].replace('-', '/')
        elif ep_obj.show.is_anime:
            base_params['ep'] = '%i' % int(ep_obj.scene_absolute_number if int(
                ep_obj.scene_absolute_number) > 0 else ep_obj.scene_episode)
        else:
            base_params['season'], base_params['ep'] = (
                (ep_obj.season,
                 ep_obj.episode), (ep_obj.scene_season,
                                   ep_obj.scene_episode))[ep_obj.show.is_scene]

        # search
        ids = helpers.mapIndexersToShow(ep_obj.show)
        if ids[1]:  # or ids[2]:
            params = base_params.copy()
            use_id = False
            if ids[1]:
                if self.supports_tvdbid():
                    params['tvdbid'] = ids[1]
                use_id = True
            if ids[2]:
                params['rid'] = ids[2]
                use_id = True
            use_id and search_params.append(params)

        # add new query strings for exceptions
        name_exceptions = list(
            set([
                helpers.sanitizeSceneName(a) for a in
                scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) +
                [ep_obj.show.name]
            ]))

        for cur_exception in name_exceptions:
            params = base_params.copy()
            params['q'] = cur_exception
            search_params.append(params)

            if ep_obj.show.is_anime:
                # Experimental, add a search string without search explicitly for the episode!
                # Remove the ?ep=e46 parameter and use the episode number to the query parameter.
                # Can be useful for newznab indexers that do not have the episodes 100% parsed.
                # Start with only applying the search string to anime shows
                params = base_params.copy()
                params['q'] = '%s.%02d' % (cur_exception, int(params['ep']))
                if 'ep' in params:
                    params.pop('ep')
                search_params.append(params)

        return [{'Episode': search_params}]
Exemplo n.º 21
0
    def _get_season_search_strings(self, season, episode):
        search_params = []

        name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
        for name in name_exceptions:

            current_params = {}

            if self.show.indexer == 1:
                current_params['tvdb'] = self.show.indexerid
            elif self.show.indexer == 2:
                current_params['tvrage'] = self.show.indexerid
            else:
                # Search by name if we don't have tvdb or tvrage id
                current_params['series'] = sanitizeSceneName(name)

            whole_season_params = current_params.copy()

            # Search for entire seasons: no need to do special things for air by date shows
            whole_season_params['category'] = 'Season'
            whole_season_params['name'] = 'Season ' + str(season)
            search_params.append(whole_season_params)

            # Search for episodes in the season
            search_params.append(self._get_episode_search_strings(season, episode)[0])

        return search_params
Exemplo n.º 22
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(
            self.show.indexerid) + [self.show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search
            if ep_obj.show.indexer == 2:
                cur_params['rid'] = ep_obj.show.indexerid
            else:
                cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

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

            if not ('rid' in cur_params and to_return):
                to_return.append(cur_params)

        return to_return
Exemplo n.º 23
0
def get_scene_exception_by_name(show_name):
    """
    Given a show name, return the tvdbid of the exception, None if no exception
    is present.
    """

    myDB = db.DBConnection("cache.db")

    # try the obvious case first
    exception_result = myDB.select(
        "SELECT tvdb_id FROM scene_exceptions WHERE LOWER(show_name) = ?",
        [show_name.lower()])
    if exception_result:
        return int(exception_result[0]["tvdb_id"])

    all_exception_results = myDB.select(
        "SELECT DISTINCT show_name, tvdb_id FROM scene_exceptions")
    for cur_exception in all_exception_results:

        cur_exception_name = cur_exception["show_name"]
        cur_tvdb_id = int(cur_exception["tvdb_id"])

        if show_name.lower() in (
                cur_exception_name.lower(),
                helpers.sanitizeSceneName(cur_exception_name).lower().replace(
                    '.', ' ')):
            logger.log(
                u"Scene exception lookup got tvdb id " + str(cur_tvdb_id) +
                u", using that", logger.DEBUG)
            return cur_tvdb_id

    return None
Exemplo n.º 24
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        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('-', '.')
        else:
            # BTN uses the same format for both Anime and TV
            # Do a general name search for the episode, formatted like SXXEYY
            search_params['name'] = "{ep}".format(ep=episode_num(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(scene_exceptions.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
Exemplo n.º 25
0
    def _get_season_search_strings(self, show, season=None):

        params = {}

        if not show:
            return params

        # search directly by tvrage id
        if show.tvrid:
            params['rid'] = show.tvrid
        # if we can't then fall back on a very basic name search
        else:
            params['q'] = sanitizeSceneName(show.name)

        if season != None:
            # air-by-date means &season=2010&q=2010.03, no other way to do it atm
            if show.air_by_date:
                params['season'] = season.split('-')[0]
                if 'q' in params:
                    params['q'] += '.' + season.replace('-', '.')
                else:
                    params['q'] = season.replace('-', '.')
            else:
                params['season'] = season

        return [params]
Exemplo n.º 26
0
    def _get_season_search_strings(self, show, season, wantedEp, searchSeason=False):

        if not show:
            return [{}]

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(show.tvdbid) + [show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search directly by tvrage id
            if show.tvrid:
                cur_params['rid'] = show.tvrid
            # if we can't then fall back on a very basic name search
            else:
                cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            # air-by-date means &season=2010&q=2010.03, no other way to do it atm
            if show.air_by_date:
                cur_params['season'] = season.split('-')[0]
                if 'q' in cur_params:
                    cur_params['q'] += '.' + season.replace('-', '.')
                else:
                    cur_params['q'] = season.replace('-', '.')
            else:
                cur_params['season'] = season

            # hack to only add a single result if it's a rageid search
            if not ('rid' in cur_params and to_return):
                to_return.append(cur_params)

        return to_return
Exemplo n.º 27
0
    def _season_strings(self, ep_obj, **kwargs):

        search_params = []
        base_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.is_sports:
            # Search for the year of the air by date show
            base_params['name'] = str(ep_obj.airdate).split('-')[0]
        elif ep_obj.show.is_anime:
            base_params['name'] = '%s' % ep_obj.scene_absolute_number
        else:
            base_params['name'] = 'Season %s' % (ep_obj.season, ep_obj.scene_season)[bool(ep_obj.show.is_scene)]

        if 1 == ep_obj.show.indexer:
            base_params['tvdb'] = ep_obj.show.indexerid
            search_params.append(base_params)
        # elif 2 == ep_obj.show.indexer:
        #    current_params['tvrage'] = ep_obj.show.indexerid
        #    search_params.append(current_params)
        else:
            name_exceptions = list(
                set([helpers.sanitizeSceneName(a) for a in
                     scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]]))
            for name in name_exceptions:
                series_param = {'series': name}
                series_param.update(base_params)
                search_params.append(series_param)

        return [dict({'Season': search_params})]
Exemplo n.º 28
0
 def _get_episode_search_strings(self, ep_obj, add_string=''):
     search_string = []
     for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
         ep_string = '+'.join(
             [helpers.sanitizeSceneName(show_name).replace('.', '+'), str(ep_obj.scene_absolute_number).zfill(2)])
         search_string.append(ep_string)
     return search_string
Exemplo n.º 29
0
Arquivo: btn.py Projeto: feld/SickRage
    def _get_episode_search_strings(self, ep_obj, add_string=""):

        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(scene_exceptions.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
Exemplo n.º 30
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        search_string = {'Episode': []}

        if not ep_obj:
            return []

        for show_name in set(show_name_helpers.allPossibleShowNames(
                self.show)):
            for sep in ' ', ' - ':
                ep_string = sanitizeSceneName(show_name) + sep
                if self.show.air_by_date:
                    ep_string += str(ep_obj.airdate).replace('-', '|')
                elif self.show.sports:
                    ep_string += str(ep_obj.airdate).replace(
                        '-', '|') + '|' + ep_obj.airdate.strftime('%b')
                elif self.show.anime:
                    ep_string += '%i' % int(ep_obj.scene_absolute_number)
                else:
                    ep_string += sickbeard.config.naming_ep_type[2] % {
                        'seasonnumber': ep_obj.scene_season,
                        'episodenumber': ep_obj.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]
Exemplo n.º 31
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] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception) + save_q
            to_return.append(dict(params))

        return to_return
Exemplo n.º 32
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []
        cur_params = {}

        # season
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate).split('-')[0]
            cur_params['season'] = date_str
            cur_params['q'] = date_str.replace('-', '.')
        elif ep_obj.show.is_anime:
            cur_params['season'] = "%d" % ep_obj.scene_absolute_number
        else:
            cur_params['season'] = str(ep_obj.scene_season)

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_return = cur_params.copy()
            cur_return['rid'] = rid
            to_return.append(cur_return)

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

        return to_return
Exemplo n.º 33
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] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Exemplo n.º 34
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] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception) + save_q
            to_return.append(dict(params))

        return to_return
Exemplo n.º 35
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        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'] = "{0:d}".format(int(ep_obj.scene_absolute_number))
        else:
            # Do a general name search for the episode, formatted like SXXEYY
            search_params['name'] = "{ep}".format(ep=episode_num(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(scene_exceptions.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
Exemplo n.º 36
0
    def _get_episode_search_strings(self, ep_obj, add_string=""):

        search_string = {"Episode": []}

        if not ep_obj:
            return []

        for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
            for sep in " ", " - ":
                ep_string = sanitizeSceneName(show_name) + sep
                if self.show.air_by_date:
                    ep_string += str(ep_obj.airdate).replace("-", "|")
                elif self.show.sports:
                    ep_string += str(ep_obj.airdate).replace("-", "|") + "|" + ep_obj.airdate.strftime("%b")
                elif self.show.anime:
                    ep_string += "%i" % int(ep_obj.scene_absolute_number)
                else:
                    ep_string += sickbeard.config.naming_ep_type[2] % {
                        "seasonnumber": ep_obj.scene_season,
                        "episodenumber": ep_obj.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]
Exemplo n.º 37
0
def get_scene_exception_by_name(show_name):
    """
    Given a show name, return the indexerid of the exception, None if no exception
    is present.
    """

    myDB = db.DBConnection("cache.db")

    # try the obvious case first
    exception_result = myDB.select(
        "SELECT indexer_id FROM scene_exceptions WHERE LOWER(show_name) = ?", [show_name.lower()]
    )
    if exception_result:
        return int(exception_result[0]["indexer_id"])

    all_exception_results = myDB.select("SELECT show_name, indexer_id 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"])

        if show_name.lower() in (
            cur_exception_name.lower(),
            helpers.sanitizeSceneName(cur_exception_name).lower().replace(".", " "),
        ):
            logger.log(u"Scene exception lookup got indexer id " + str(cur_indexer_id) + u", using that", logger.DEBUG)
            return cur_indexer_id

    return None
Exemplo n.º 38
0
    def _get_episode_search_strings(self,
                                    show,
                                    season,
                                    episode,
                                    abd=False,
                                    add_string=''):

        search_string = {'Episode': []}

        if not episode:
            return []

        if abd:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                ep_string = sanitizeSceneName(show_name) + ' ' + \
                            str(episode).replace('-', '|') + '|' + \
                            helpers.custom_strftime('%b', episode)
                search_string['Episode'].append(ep_string)
        else:
            for show_name in set(show_name_helpers.allPossibleShowNames(show)):
                ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
                            sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
                                                                  'episodenumber': episode}

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

        return [search_string]
Exemplo n.º 39
0
    def _get_season_search_strings(self, ep_obj):
        search_params = []

        name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
        for name in name_exceptions:

            current_params = {}

            if self.show.indexer == 1:
                current_params['tvdb'] = self.show.indexerid
            elif self.show.indexer == 2:
                current_params['tvrage'] = self.show.indexerid
            else:
                # Search by name if we don't have tvdb or tvrage id
                current_params['series'] = sanitizeSceneName(name)

            # Search for entire seasons: no need to do special things for air by date shows
            whole_season_params = current_params.copy()
            partial_season_params = current_params.copy()

            # Search for entire seasons: no need to do special things for air by date shows
            whole_season_params['category'] = 'Season'
            if ep_obj.show.air_by_date or ep_obj.show.sports:
                # Search for the year of the air by date show
                whole_season_params['name'] = str(ep_obj.airdate)[:7]
            else:
                whole_season_params['name'] = 'Season ' + str(ep_obj.scene_season)

            search_params.append(whole_season_params)

        return search_params
Exemplo n.º 40
0
def get_scene_exception_by_name(show_name):
    """
    Given a show name, return the tvdbid of the exception, None if no exception
    is present.
    """

    myDB = db.DBConnection("cache.db")

    # try the obvious case first
    exception_result = myDB.select(u"SELECT tvdb_id FROM scene_exceptions WHERE LOWER(show_name) = ?", [show_name.lower()])
    if exception_result:
        return int(exception_result[0]["tvdb_id"])

    all_exception_results = myDB.select(u"SELECT show_name, tvdb_id FROM scene_exceptions")
    for cur_exception in all_exception_results:

        cur_exception_name = cur_exception["show_name"]
        cur_tvdb_id = int(cur_exception["tvdb_id"])

        if show_name.lower() in (cur_exception_name.lower(), helpers.sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')):
            logger.log(u"Scene exception lookup got tvdb id "+str(cur_tvdb_id)+u", using that", logger.DEBUG)
            return cur_tvdb_id
        
    
    # if we get to here, try custom_exceptions instead
    return get_custom_exception_by_name(show_name)
Exemplo n.º 41
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search
            if ep_obj.show.indexer == 2:
                cur_params['rid'] = ep_obj.show.indexerid
            else:
                cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

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

            if not ('rid' in cur_params and to_return):
                to_return.append(cur_params)

        return to_return
Exemplo n.º 42
0
    def _get_season_search_strings(self, ep_obj):
        search_params = []

        name_exceptions = scene_exceptions.get_scene_exceptions(
            self.show.indexerid) + [self.show.name]
        for name in name_exceptions:

            current_params = {}

            if self.show.indexer == 1:
                current_params['tvdb'] = self.show.indexerid
            elif self.show.indexer == 2:
                current_params['tvrage'] = self.show.indexerid
            else:
                # Search by name if we don't have tvdb or tvrage id
                current_params['series'] = sanitizeSceneName(name)

            # Search for entire seasons: no need to do special things for air by date shows
            whole_season_params = current_params.copy()
            partial_season_params = current_params.copy()

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

            search_params.append(whole_season_params)

        return search_params
Exemplo n.º 43
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        """
        Makes objects to pass to search for manual and backlog season pack searching
        Returns a list containing dicts of search parameters
        """
        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

        name_exceptions = list(set([ep_obj.show.name] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Exemplo n.º 44
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search
            cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            # season
            if not (ep_obj.show.air_by_date or ep_obj.show.sports):
                cur_params['season'] = str(ep_obj.scene_season)

            to_return.append(cur_params)

        cur_params = {}
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            cur_params['season'] = self._get_episode_search_strings(ep_obj)[0]['season']

        #cur_params['episode'] = self._get_episode_search_strings(ep_obj)[0]['ep']

        to_return.append(cur_params)

        return to_return
Exemplo n.º 45
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        to_return = []
        params = {}

        if not ep_obj:
            return [params]

        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('-', '/')
        elif ep_obj.show.anime:
            params['ep'] = "%i" % int(ep_obj.scene_absolute_number)
        else:
            params['season'] = ep_obj.scene_season
            params['ep'] = ep_obj.scene_episode

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_return = params.copy()
            cur_return['rid'] = rid
            to_return.append(cur_return)

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

        return to_return
Exemplo n.º 46
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] + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid)))
        for cur_exception in name_exceptions:
            params['q'] = helpers.sanitizeSceneName(cur_exception)
            if add_string:
                params['q'] += ' ' + add_string

            to_return.append(dict(params))

        return to_return
Exemplo n.º 47
0
    def _get_season_search_strings(self, show, season, wantedEp, searchSeason=False):

        if not show:
            return [{}]

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid) + [show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search

            cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            # air-by-date means &season=2010&q=2010.03, no other way to do it atm
            if show.air_by_date:
                cur_params['season'] = season.split('-')[0]
                if 'q' in cur_params:
                    cur_params['q'] += '.' + season.replace('-', '.')
                else:
                    cur_params['q'] = season.replace('-', '.')
            else:
                cur_params['season'] = str(season)

                to_return.append(cur_params)

        return to_return
Exemplo n.º 48
0
    def _get_season_search_strings(self, ep_obj):
        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)
        elif ep_obj.show.indexer == 2:
            current_params['tvrage'] = ep_obj.show.indexerid
            search_params.append(current_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 or tvrage id
                current_params['series'] = sanitizeSceneName(name)
                search_params.append(current_params)

        return search_params
Exemplo n.º 49
0
    def _get_season_search_strings(self, ep_obj):

        to_return = []
        cur_params = {}
        cur_params['Langcat']=ep_obj.show.audio_lang
        # season
        if ep_obj.show.air_by_date or ep_obj.show.sports:
            date_str = str(ep_obj.airdate).split('-')[0]
            cur_params['season'] = date_str
            cur_params['q'] = date_str.replace('-', '.')
        elif ep_obj.show.is_anime:
            cur_params['season'] = "%d" % ep_obj.scene_absolute_number
        else:
            cur_params['season'] = str(ep_obj.scene_season)

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_return = cur_params.copy()
            cur_return['rid'] = rid
            to_return.append(cur_return)

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

        return to_return
Exemplo n.º 50
0
    def _get_season_search_strings(self, ep_obj):
        search_params = []

        name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
        if not (ep_obj.show.air_by_date or ep_obj.show.sports):
            for name in name_exceptions:

                current_params = {}

                if self.show.indexer == 1:
                    current_params["tvdb"] = self.show.indexerid
                elif self.show.indexer == 2:
                    current_params["tvrage"] = self.show.indexerid
                else:
                    # Search by name if we don't have tvdb or tvrage id
                    current_params["series"] = sanitizeSceneName(name)

                # Search for entire seasons: no need to do special things for air by date shows
                whole_season_params = current_params.copy()
                whole_season_params["category"] = "Season"
                if not (ep_obj.show.air_by_date or ep_obj.show.sports):
                    whole_season_params["name"] = "Season " + str(ep_obj.scene_season)
                elif ep_obj.show.air_by_date or ep_obj.show.sports:
                    whole_season_params["name"] = self._get_episode_search_strings(ep_obj)[0]["name"]
                search_params.append(whole_season_params)

        return search_params
Exemplo n.º 51
0
    def _get_episode_search_strings(self,
                                    show,
                                    season,
                                    episode,
                                    add_string=''):

        params = {}

        if not episode:
            return [params]

        # search
        params['q'] = helpers.sanitizeSceneName(show.name)

        if show.air_by_date:
            date_str = str(episode)

            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        elif show.sports:
            date_str = str(episode)

            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        else:
            params['season'] = season
            params['ep'] = episode

        to_return = [params]

        # only do exceptions if we are searching by name
        if 'q' in params:

            # add new query strings for exceptions
            name_exceptions = scene_exceptions.get_scene_exceptions(
                show.indexerid)
            for cur_exception in name_exceptions:

                # don't add duplicates
                if cur_exception == show.name:
                    continue

                cur_return = params.copy()
                cur_return['q'] = helpers.sanitizeSceneName(cur_exception)
                to_return.append(cur_return)

        return to_return
Exemplo n.º 52
0
    def _get_episode_search_strings(self, ep_obj):

        if not ep_obj:
            return [{}]

        search_params = {'category': 'Episode'}

        if ep_obj.show.tvdbid:
            search_params['tvdb'] = ep_obj.show.tvdbid
        elif ep_obj.show.tvrid:
            search_params['tvrage'] = ep_obj.show.rid
        else:
            search_params['series'] = sanitizeSceneName(ep_obj.show_name)

        if ep_obj.show.air_by_date:
            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('-', '.')

        else:
            # Do a general name search for the episode, formatted like SXXEYY
            search_params['name'] = "S%02dE%02d" % (ep_obj.season,
                                                    ep_obj.episode)

        to_return = [search_params]

        # only do scene exceptions if we are searching by name
        if 'series' in search_params:

            # add new query string for every exception
            name_exceptions = scene_exceptions.get_scene_exceptions(
                ep_obj.show.tvdbid)
            for cur_exception in name_exceptions:

                # don't add duplicates
                if cur_exception == ep_obj.show.name:
                    continue

                # copy all other parameters before setting the show name for this exception
                cur_return = search_params.copy()
                cur_return['series'] = sanitizeSceneName(cur_exception)
                to_return.append(cur_return)

        return to_return
Exemplo n.º 53
0
    def _get_season_search_strings(self, show, season, episode):
        search_string = []

        for show_name in set(show_name_helpers.allPossibleShowNames(show)):
            show_string = sanitizeSceneName(show_name).replace('.', '-').lower()
            search_string.append(show_string)

        return search_string
Exemplo n.º 54
0
    def test_formating(self):
        self.loadFromDB()
        show = sickbeard.helpers.findCertainShow(sickbeard.showList, 24749)
        ep = show.getEpisode(21, 17)
        ep.airdate = datetime.date.today()

        # parse the file name
        pattern = u'%SN - %A-D - %EN'
        title = 'Show.Name.9th.Mar.2010.HDTV.XviD-RLSGROUP'
        try:
            myParser = NameParser(False, 1)
            parse_result = myParser.parse(title, True)
        except InvalidNameException:
            print(u"Unable to parse the filename " + ep.name +
                  " into a valid episode")

        print parse_result

        search_string = {'Episode': []}
        episode = ep.airdate
        str(episode).replace('-', '|')
        ep_string = sanitizeSceneName(show.name) + ' ' + \
                    str(episode).replace('-', '|') + '|' + \
                    episode.strftime('%b')

        search_string['Episode'].append(ep_string)

        scene_ep_string = sanitizeSceneName(show.name) + ' ' + \
                    sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + '|' + \
                    sickbeard.config.naming_ep_type[0] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + '|' + \
                    sickbeard.config.naming_ep_type[3] % {'seasonnumber': ep.scene_season,
                                                          'episodenumber': ep.scene_episode} + ' %s category:tv' % ''

        scene_season_string = show.name + ' S%02d' % int(
            ep.scene_season) + ' -S%02d' % int(
                ep.scene_season) + 'E' + ' category:tv'  #1) ShowName SXX -SXXE

        print(u'Searching "%s" for "%s" as "%s"' %
              (show.name, ep.prettyName(), ep.scene_prettyName()))

        print('Scene episode search strings: %s' % (scene_ep_string))

        print('Scene season search strings: %s' % (scene_season_string))
Exemplo n.º 55
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):
        to_return = []
        params = {}

        if not ep_obj:
            return [params]

        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('-', '/')
        elif ep_obj.show.anime:
            params['ep'] = "%i" % int(ep_obj.scene_absolute_number if int(ep_obj.scene_absolute_number) > 0 else ep_obj.scene_episode)
        else:
            params['season'] = ep_obj.scene_season
            params['ep'] = ep_obj.scene_episode

        # search
        rid = helpers.mapIndexersToShow(ep_obj.show)[2]
        if rid:
            cur_return = params.copy()
            cur_return['rid'] = rid
            to_return.append(cur_return)

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

            if ep_obj.show.anime:
                # Experimental, add a searchstring without search explicitly for the episode!
                # Remove the ?ep=e46 paramater and use add the episode number to the query paramater.
                # Can be usefull for newznab indexers that do not have the episodes 100% parsed.
                # Start with only applying the searchstring to anime shows
                params['q'] = helpers.sanitizeSceneName(cur_exception)
                paramsNoEp = params.copy()

                paramsNoEp['q'] = paramsNoEp['q'] + " " + str(paramsNoEp['ep'])
                if "ep" in paramsNoEp:
                    paramsNoEp.pop("ep")
                to_return.append(paramsNoEp)

        return to_return
Exemplo n.º 56
0
    def _get_episode_search_strings(self, ep_obj):

        params = {}

        if not ep_obj:
            return [params]

        # search directly by tvrage id
        if ep_obj.show.tvrid:
            params['rid'] = ep_obj.show.tvrid
        # if we can't then fall back on a very basic name search
        else:
            params['q'] = helpers.sanitizeSceneName(ep_obj.show.name).replace(
                '.', '_')

        if ep_obj.show.air_by_date:
            date_str = str(ep_obj.airdate)

            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        else:
            params['season'] = ep_obj.season
            params['ep'] = ep_obj.episode

        to_return = [params]

        # only do exceptions if we are searching by name
        if 'q' in params:

            # add new query strings for exceptions
            name_exceptions = scene_exceptions.get_scene_exceptions(
                ep_obj.show.tvdbid)
            for cur_exception in name_exceptions:

                # don't add duplicates
                if cur_exception == ep_obj.show.name:
                    continue

                cur_return = params.copy()
                cur_return['q'] = helpers.sanitizeSceneName(
                    cur_exception).replace('.', '_')
                to_return.append(cur_return)

        return to_return
Exemplo n.º 57
0
    def _season_strings(self, ep_obj):

        search_params = []
        base_params = {}

        # season
        ep_detail = None
        if ep_obj.show.air_by_date or ep_obj.show.is_sports:
            airdate = str(ep_obj.airdate).split('-')[0]
            base_params['season'] = airdate
            base_params['q'] = airdate
            if ep_obj.show.air_by_date:
                ep_detail = '+"%s"' % airdate
        elif ep_obj.show.is_anime:
            base_params['season'] = '%d' % ep_obj.scene_absolute_number
        else:
            base_params['season'] = str(
                (ep_obj.season,
                 ep_obj.scene_season)[bool(ep_obj.show.is_scene)])
            ep_detail = 'S%02d' % helpers.tryInt(base_params['season'], 1)

        # id search
        params = base_params.copy()
        use_id = False
        for i in sickbeard.indexerApi().all_indexers:
            if i in ep_obj.show.ids and 0 < ep_obj.show.ids[i][
                    'id'] and i in self.caps:
                params[self.caps[i]] = ep_obj.show.ids[i]['id']
                use_id = True
        use_id and search_params.append(params)

        # query search and exceptions
        name_exceptions = list(
            set([
                helpers.sanitizeSceneName(a) for a in
                scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) +
                [ep_obj.show.name]
            ]))

        spacer = 'geek' in self.get_id() and ' ' or '.'
        for cur_exception in name_exceptions:
            params = base_params.copy()
            cur_exception = cur_exception.replace('.', spacer)
            if 'q' in params:
                params['q'] = '%s%s%s' % (cur_exception, spacer, params['q'])
                search_params.append(params)

            if ep_detail:
                params = base_params.copy()
                params['q'] = '%s%s%s' % (cur_exception, spacer, ep_detail)
                'season' in params and params.pop('season')
                'ep' in params and params.pop('ep')
                search_params.append(params)

        return [{'Season': search_params}]
Exemplo n.º 58
0
    def _get_season_search_strings(self, show, season=None):

        if not show:
            return [{}]

        to_return = []

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(
            show.tvdbid) + [show.name]
        for cur_exception in name_exceptions:

            cur_params = {}

            # search directly by tvrage id
            if show.tvrid:
                cur_params['rid'] = show.tvrid
            # if we can't then fall back on a very basic name search
            else:
                if show.audio_lang == "fr":
                    cur_params['q'] = helpers.sanitizeSceneName(
                        cur_exception) + " french"
                else:
                    cur_params['q'] = helpers.sanitizeSceneName(cur_exception)

            if season != None:
                # air-by-date means &season=2010&q=2010.03, no other way to do it atm
                if show.air_by_date:
                    cur_params['season'] = season.split('-')[0]
                    if 'q' in cur_params:
                        cur_params['q'] += '.' + season.replace('-', '.')
                    else:
                        cur_params['q'] = season.replace('-', '.')
                else:
                    cur_params['season'] = season

            # hack to only add a single result if it's a rageid search
            if not ('rid' in cur_params and to_return):
                to_return.append(cur_params)

        return to_return
Exemplo n.º 59
0
    def _get_episode_search_strings(self, ep_obj, french=None):

        params = {}

        global lang

        if not ep_obj:
            return [params]

        params['show_name'] = helpers.sanitizeSceneName(
            ep_obj.show.name).replace('.', ' ').replace('!',
                                                        '').encode('utf-8')

        if ep_obj.show.air_by_date:
            params['date'] = str(ep_obj.airdate)
        else:
            params['season'] = ep_obj.scene_season
            params['episode'] = ep_obj.scene_episode

        to_return = [params]

        # add new query strings for exceptions
        name_exceptions = scene_exceptions.get_scene_exceptions(
            ep_obj.show.tvdbid)
        for name_exception in name_exceptions:
            # don't add duplicates
            if name_exception != ep_obj.show.name:
                # only change show name
                cur_return = params.copy()
                cur_return['show_name'] = helpers.sanitizeSceneName(
                    name_exception)
                to_return.append(cur_return)

        logger.log(
            u"KAT _get_episode_search_strings for %s is returning %s" %
            (repr(ep_obj), repr(params)), logger.DEBUG)
        if french:
            lang = 'fr'
        else:
            lang = ep_obj.show.audio_lang
        return to_return
Exemplo n.º 60
0
def addNameToCache(name, indexer_id=0):
    """
    Adds the show & tvdb id to the scene_names table in cache.db.
    
    name: The show name to cache
    indexer_id: the TVDB and TVRAGE id that this show should be cached with (can be None/0 for unknown)
    """

    # standardize the name we're using to account for small differences in providers
    name = sanitizeSceneName(name)
    with db.DBConnection('cache.db') as myDB:
        myDB.action("INSERT INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])