Example #1
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_names.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 += sickrage.srConfig.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]
Example #2
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_names.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 += sickrage.srConfig.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]
Example #3
0
    def _get_episode_search_strings(self, ep_obj, add_string=""):

        search_string = {"Episode": []}

        if not ep_obj:
            return []

        for show_name in set(allPossibleShowNames(ep_obj.show)):
            ep_string = show_name + " "
            if ep_obj.show.air_by_date:
                ep_string += str(ep_obj.airdate).replace("-", " ")
            elif ep_obj.show.sports:
                ep_string += (
                    str(ep_obj.airdate).replace("-", " ")
                    + ("|", " ")[len(self.proper_strings) > 1]
                    + ep_obj.airdate.strftime("%b")
                )
            elif ep_obj.show.anime:
                ep_string += "%02d" % int(ep_obj.scene_absolute_number)
            else:
                ep_string += sickrage.srConfig.NAMING_EP_TYPE[2] % {
                    "seasonnumber": ep_obj.scene_season,
                    "episodenumber": ep_obj.scene_episode,
                }
            if add_string:
                ep_string = ep_string + " %s" % add_string

            search_string[b"Episode"].append(ep_string.strip())

        return [search_string]
Example #4
0
    def _get_episode_search_strings(self, ep_obj, add_string=''):

        search_string = {'Episode': []}

        if not ep_obj:
            return []

        for show_name in set(allPossibleShowNames(ep_obj.show)):
            ep_string = show_name + ' '
            if ep_obj.show.air_by_date:
                ep_string += str(ep_obj.airdate).replace('-', ' ')
            elif ep_obj.show.sports:
                ep_string += str(ep_obj.airdate).replace('-', ' ') + ('|', ' ')[
                    len(self.proper_strings) > 1] + ep_obj.airdate.strftime('%b')
            elif ep_obj.show.anime:
                ep_string += "%02d" % int(ep_obj.scene_absolute_number)
            else:
                ep_string += sickrage.srConfig.NAMING_EP_TYPE[2] % {'seasonnumber': ep_obj.scene_season,
                                                                   'episodenumber': ep_obj.scene_episode}
            if add_string:
                ep_string = ep_string + ' %s' % add_string

            search_string[b'Episode'].append(ep_string.strip())

        return [search_string]
Example #5
0
    def _test_allPossibleShowNames(self, name, indexerid=0, expected=[]):
        s = TVShow(1, indexerid)
        s.name = name
        s.saveToDB()
        s.loadFromDB(skipNFO=True)

        result = show_names.allPossibleShowNames(s)
        self.assertTrue(
            len(set(expected).intersection(set(result))) == len(expected))
Example #6
0
    def _test_allPossibleShowNames(self, name, indexerid=0, expected=[]):
        s = TVShow(1, indexerid)
        s.name = name
        s.saveToDB()
        s.loadFromDB(skipNFO=True)


        result = show_names.allPossibleShowNames(s)
        self.assertTrue(len(set(expected).intersection(set(result))) == len(expected))
Example #7
0
    def _retrieve_show_images_from_tmdb(show, img_type):
        types = {
            'poster': 'poster_path',
            'banner': None,
            'fanart': 'backdrop_path',
            'poster_thumb': 'poster_path',
            'banner_thumb': None
        }

        from tmdbsimple.base import TMDB

        def _request(self, method, path, params=None, payload=None):
            url = self._get_complete_url(path)
            params = self._get_params(params)

            requests.packages.urllib3.disable_warnings()
            response = requests.request(
                method,
                url,
                params=params,
                data=json.dumps(payload) if payload else payload,
                headers=self.headers,
                verify=False)

            response.raise_for_status()
            response.encoding = 'utf-8'
            return response.json()

        TMDB._request = _request

        # get TMDB configuration info
        tmdb.API_KEY = sickrage.srConfig.TMDB_API_KEY
        config = tmdb.Configuration()
        response = sickrage.srConfig.info()
        base_url = response[b'images'][b'base_url']
        sizes = response[b'images'][b'poster_sizes']

        def size_str_to_int(x):
            return float("inf") if x == 'original' else int(x[1:])

        max_size = max(sizes, key=size_str_to_int)

        try:
            search = tmdb.Search()
            from core.helpers.show_names import allPossibleShowNames
            for show_name in set(allPossibleShowNames(show)):
                for result in search.collection(
                        query=show_name)[b'results'] + search.tv(
                            query=show_name)[b'results']:
                    if types[img_type] and getattr(result, types[img_type]):
                        return "{0}{1}{2}".format(base_url, max_size,
                                                  result[types[img_type]])
        except:
            pass

        sickrage.srLogger.info("Could not find any " + img_type +
                               " images on TMDB for " + show.name)
Example #8
0
    def _get_season_search_strings(self, ep_obj):

        search_string = {"Season": []}
        for show_name in set(allPossibleShowNames(self.show)):
            if ep_obj.show.air_by_date or ep_obj.show.sports:
                ep_string = show_name + " " + str(ep_obj.airdate).split("-")[0]
            elif ep_obj.show.anime:
                ep_string = show_name + " " + "%d" % ep_obj.scene_absolute_number
            else:
                ep_string = show_name + " S%02d" % int(ep_obj.scene_season)  # 1) showName.SXX

            search_string[b"Season"].append(ep_string.encode("utf-8").strip())

        return [search_string]
Example #9
0
    def _get_season_search_strings(self, ep_obj):

        search_string = {'Season': []}
        for show_name in set(allPossibleShowNames(self.show)):
            if ep_obj.show.air_by_date or ep_obj.show.sports:
                ep_string = show_name + ' ' + str(ep_obj.airdate).split('-')[0]
            elif ep_obj.show.anime:
                ep_string = show_name + ' ' + "%d" % ep_obj.scene_absolute_number
            else:
                ep_string = show_name + ' S%02d' % int(ep_obj.scene_season)  # 1) showName.SXX

            search_string[b'Season'].append(ep_string.encode('utf-8').strip())

        return [search_string]
Example #10
0
    def _get_season_search_strings(self, ep_obj):

        search_string = {'Season': []}

        for show_name in set(show_names.allPossibleShowNames(self.show)):
            for sep in ' ', ' - ':
                season_string = show_name + sep + 'Series '
                if ep_obj.show.air_by_date or ep_obj.show.sports:
                    season_string += str(ep_obj.airdate).split('-')[0]
                elif ep_obj.show.anime:
                    season_string += '%d' % ep_obj.scene_absolute_number
                else:
                    season_string += '%d' % int(ep_obj.scene_season)

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

        return [search_string]
Example #11
0
    def _retrieve_show_images_from_tmdb(show, img_type):
        types = {'poster': 'poster_path',
                 'banner': None,
                 'fanart': 'backdrop_path',
                 'poster_thumb': 'poster_path',
                 'banner_thumb': None}

        from tmdbsimple.base import TMDB
        def _request(self, method, path, params=None, payload=None):
            url = self._get_complete_url(path)
            params = self._get_params(params)

            requests.packages.urllib3.disable_warnings()
            response = requests.request(method, url, params=params, data=json.dumps(payload)
            if payload else payload, headers=self.headers, verify=False)

            response.raise_for_status()
            response.encoding = 'utf-8'
            return response.json()

        TMDB._request = _request

        # get TMDB configuration info
        tmdb.API_KEY = sickrage.srConfig.TMDB_API_KEY
        config = tmdb.Configuration()
        response = sickrage.srConfig.info()
        base_url = response[b'images'][b'base_url']
        sizes = response[b'images'][b'poster_sizes']

        def size_str_to_int(x):
            return float("inf") if x == 'original' else int(x[1:])

        max_size = max(sizes, key=size_str_to_int)

        try:
            search = tmdb.Search()
            from core.helpers.show_names import allPossibleShowNames
            for show_name in set(allPossibleShowNames(show)):
                for result in search.collection(query=show_name)[b'results'] + search.tv(query=show_name)[b'results']:
                    if types[img_type] and getattr(result, types[img_type]):
                        return "{0}{1}{2}".format(base_url, max_size, result[types[img_type]])
        except:
            pass

        sickrage.srLogger.info("Could not find any " + img_type + " images on TMDB for " + show.name)
Example #12
0
    def _get_season_search_strings(self, ep_obj):

        search_string = {'Season': []}

        for show_name in set(show_names.allPossibleShowNames(self.show)):
            for sep in ' ', ' - ':
                season_string = show_name + sep + 'Series '
                if ep_obj.show.air_by_date or ep_obj.show.sports:
                    season_string += str(ep_obj.airdate).split('-')[0]
                elif ep_obj.show.anime:
                    season_string += '%d' % ep_obj.scene_absolute_number
                else:
                    season_string += '%d' % int(ep_obj.scene_season)

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

        return [search_string]