Пример #1
0
    def _scan_country(self, country, strict=False):
        """
        Find a country if it is at the start or end of country string
        """
        words_match = list(iter_words(country.lower()))
        s = ""
        start = None

        for word_match in words_match:
            if not start:
                start = word_match.start(0)
            s += word_match.group(0)
            try:
                return Country.fromguessit(s), (start, word_match.end(0))
            except babelfish.Error:
                continue

        words_match.reverse()
        s = ""
        end = None
        for word_match in words_match:
            if not end:
                end = word_match.end(0)
            s = word_match.group(0) + s
            try:
                return Country.fromguessit(s), (word_match.start(0), end)
            except babelfish.Error:
                continue

        return Country.fromguessit(country), (start, end)
Пример #2
0
 def test_converter_name(self):
     self.assertEqual(Country('US').name, 'UNITED STATES')
     self.assertEqual(Country.fromname('UNITED STATES'), Country('US'))
     self.assertEqual(Country.fromcode('UNITED STATES', 'name'), Country('US'))
     with self.assertRaises(CountryReverseError):
         Country.fromname('ZZZZZ')
     self.assertEqual(len(get_country_converter('name').codes), 249)
Пример #3
0
    def get_country(self, language):
        country_match = re.search('\s*\((\w[\w\s]*\w)\)', language)
        if not country_match:
            return

        country_code = country_match.group(1)

        return Country(country_code) if len(
            country_code) == 2 else Country.fromcode(country_code,
                                                     converter='name')
    def get_country(self, language):
        country_match = re.search('\s*\((\w[\w\s]*\w)\)', language)
        if not country_match:
            return

        country_code = country_match.group(1)

        return Country(country_code) if len(country_code) == 2 else Country.fromcode(country_code, converter='name')
Пример #5
0
def from_country_code_to_name(code):
    """Convert a 2 letter country code to a country name.

    :param code: the 2 letter country code
    :type code: str
    :return: the country name
    :rtype: str
    """
    try:
        return Country(code.upper()).name
    except ValueError:
        return
Пример #6
0
 def process(self, mtree, options=None):
     GuessFinder(self.guess_country, None, self.log, options).process_nodes(mtree.unidentified_leaves())
     for node in mtree.leaves_containing('language'):
         c = node.clean_value.lower()
         if c in self.replace_language:
             node.guess.set('language', None)
             try:
                 country = Country.fromguessit(c)
                 if self.is_valid_country(country, options):
                     guess = Guess(country=country, confidence=0.9, input=node.value, span=node.span)
                     found_guess(node, guess, logger=log)
             except babelfish.Error:
                 pass
Пример #7
0
 def test_converter_name(self):
     self.assertEqual(Country('US').name, 'UNITED STATES')
     self.assertEqual(Country.fromname('UNITED STATES'), Country('US'))
     self.assertEqual(Country.fromcode('UNITED STATES', 'name'),
                      Country('US'))
     self.assertRaises(CountryReverseError,
                       lambda: Country.fromname('ZZZZZ'))
     self.assertEqual(len(country_converters['name'].codes), 249)
Пример #8
0
 def test_with_country(self):
     self.assertTrue(
         Language('Portuguese (BR)').country == Country('Brazil'))
     self.assertTrue(Language('pt_BR').country == Country('Brazil'))
     self.assertTrue(Language('fr - France').country == Country('France'))
     self.assertTrue(
         Language('fra', country='FR').country == Country('France'))
     self.assertTrue(
         Language('fra', country=Country('FRA')).country == Country(
             'France'))
Пример #9
0
 def test_fromietf_country_script(self):
     language = Language.fromietf('fra-FR-Latn')
     self.assertEqual(language.alpha3, 'fra')
     self.assertEqual(language.country, Country('FR'))
     self.assertEqual(language.script, Script('Latn'))
Пример #10
0
 def test_pickle(self):
     for country in [Country('GB'), Country('US')]:
         self.assertEqual(pickle.loads(pickle.dumps(country)), country)
Пример #11
0
 def test_hash(self):
     self.assertEqual(hash(Country('US')), hash('US'))
Пример #12
0
 def test_ne(self):
     self.assertNotEqual(Country('GB'), Country('US'))
     self.assertIsNotNone(Country('US'))
Пример #13
0
 def test_eq(self):
     self.assertEqual(Country('US'), Country('US'))
Пример #14
0
 def test_wrong_country(self):
     self.assertRaises(ValueError, lambda: Country('ZZ'))
Пример #15
0
 def convert(alpha2):
     if alpha2 == 'GB':
         return 'UK'
     return str(Country(alpha2))
Пример #16
0
def refine(video, **kwargs):
    """Refine a video by searching `TheTVDB <http://thetvdb.com/>`_.

    .. note::

        This refiner only work for instances of :class:`~subliminal.video.Episode`.

    Several attributes can be found:

      * :attr:`~subliminal.video.Episode.series`
      * :attr:`~subliminal.video.Episode.year`
      * :attr:`~subliminal.video.Episode.series_imdb_id`
      * :attr:`~subliminal.video.Episode.series_tvdb_id`
      * :attr:`~subliminal.video.Episode.title`
      * :attr:`~subliminal.video.Video.imdb_id`
      * :attr:`~subliminal.video.Episode.tvdb_id`

    """
    # only deal with Episode videos
    if not isinstance(video, Episode):
        logger.error('Cannot refine episodes')
        return

    # exit if the information is complete
    if video.series_tvdb_id and video.tvdb_id:
        logger.debug('No need to search')
        return

    # search the series
    logger.info('Searching series %r', video.series)
    results = search_series(video.series.lower())
    if not results:
        logger.warning('No results for series')
        return
    logger.debug('Found %d results', len(results))

    # search for exact matches
    matching_results = []
    for result in results:
        matching_result = {}

        # use seriesName and aliases
        series_names = [result['seriesName']]
        series_names.extend(result['aliases'])

        # parse the original series as series + year or country
        original_match = series_re.match(result['seriesName']).groupdict()

        # parse series year
        series_year = None
        if result['firstAired']:
            series_year = datetime.strptime(result['firstAired'],
                                            '%Y-%m-%d').year

        # discard mismatches on year
        if video.year and series_year and video.year != series_year:
            logger.debug('Discarding series %r mismatch on year %d',
                         result['seriesName'], series_year)
            continue

        # iterate over series names
        for series_name in series_names:
            # parse as series, year and country
            series, year, country = series_re.match(series_name).groups()
            if year:
                year = int(year)

            if country:
                country = Country.fromguessit(country)

            # discard mismatches on year
            if year and (video.original_series or video.year != year):
                logger.debug('Discarding series name %r mismatch on year %d',
                             series, year)
                continue

            # discard mismatches on country
            if video.country and video.country != country:
                logger.debug(
                    'Discarding series name %r mismatch on country %r', series,
                    country)
                continue

            # match on sanitized series name
            if sanitize(series) == sanitize(video.series):
                logger.debug('Found exact match on series %r', series_name)
                matching_result['match'] = {
                    'series':
                    original_match['series'],
                    'year':
                    series_year or year,
                    'country':
                    country,
                    'original_series':
                    original_match['year'] is None and country is None
                }
                break

        # add the result on match
        if matching_result:
            matching_result['data'] = result
            matching_results.append(matching_result)

    # exit if we don't have exactly 1 matching result
    if not matching_results:
        logger.error('No matching series found')
        return
    if len(matching_results) > 1:
        logger.error('Multiple matches found')
        return

    # get the series
    matching_result = matching_results[0]
    series = get_series(matching_result['data']['id'])

    # add series information
    logger.debug('Found series %r', series)
    video.series = matching_result['match']['series']
    video.alternative_series.extend(series['aliases'])
    video.year = matching_result['match']['year']
    video.country = matching_result['match']['country']
    video.original_series = matching_result['match']['original_series']
    video.series_tvdb_id = series['id']
    video.series_imdb_id = series['imdbId'] or None

    # get the episode
    logger.info('Getting series episode %dx%d', video.season, video.episode)
    episode = get_series_episode(video.series_tvdb_id, video.season,
                                 video.episode)
    if not episode:
        logger.warning('No results for episode')
        return

    # add episode information
    logger.debug('Found episode %r', episode)
    video.tvdb_id = episode['id']
    video.title = episode['episodeName'] or None
    video.imdb_id = episode['imdbId'] or None
Пример #17
0
 def test_ne_with_country(self):
     self.assertNotEqual(Language('eng', 'US'), Language('eng', Country('GB')))
Пример #18
0
 def test_country(self):
     self.assertEqual(Language('por', 'BR').country, Country('BR'))
     self.assertEqual(Language('eng', Country('US')).country, Country('US'))
Пример #19
0
    def _show_data(self, show_obj):
        """
        Creates an elementTree XML structure for an KODI-style tvshow.nfo and
        returns the resulting data object.

        show_obj: a TVShow instance to create the NFO for
        """

        show_ID = show_obj.indexerid

        indexer_lang = show_obj.lang
        lINDEXER_API_PARMS = sickbeard.indexerApi(
            show_obj.indexer).api_params.copy()

        lINDEXER_API_PARMS['actors'] = True

        if indexer_lang and not indexer_lang == sickbeard.INDEXER_DEFAULT_LANGUAGE:
            lINDEXER_API_PARMS['language'] = indexer_lang

        if show_obj.dvdorder != 0:
            lINDEXER_API_PARMS['dvdorder'] = True

        t = sickbeard.indexerApi(
            show_obj.indexer).indexer(**lINDEXER_API_PARMS)

        tv_node = etree.Element("tvshow")

        try:
            myShow = t[int(show_ID)]
        except sickbeard.indexer_shownotfound:
            logger.log(
                u"Unable to find show with id " + str(show_ID) + " on " +
                sickbeard.indexerApi(show_obj.indexer).name + ", skipping it",
                logger.ERROR)
            raise

        except sickbeard.indexer_error:
            logger.log(
                u"" + sickbeard.indexerApi(show_obj.indexer).name +
                " is down, can't use its data to add this show", logger.ERROR)
            raise

        # check for title and id
        if not (getattr(myShow, 'seriesname', None)
                and getattr(myShow, 'id', None)):
            logger.log(u"Incomplete info for show with id " + str(show_ID) +
                       " on " + sickbeard.indexerApi(show_obj.indexer).name +
                       ", skipping it")
            return False

        title = etree.SubElement(tv_node, "title")
        title.text = myShow["seriesname"]

        if getattr(myShow, 'rating', None):
            rating = etree.SubElement(tv_node, "rating")
            rating.text = myShow["rating"]

        if getattr(myShow, 'firstaired', None):
            try:
                year_text = str(
                    datetime.datetime.strptime(myShow["firstaired"],
                                               dateFormat).year)
                if year_text:
                    year = etree.SubElement(tv_node, "year")
                    year.text = year_text
            except Exception:
                pass

        if getattr(myShow, 'overview', None):
            plot = etree.SubElement(tv_node, "plot")
            plot.text = myShow["overview"]

        if getattr(myShow, 'id', None):
            episodeguide = etree.SubElement(tv_node, "episodeguide")
            episodeguideurl = etree.SubElement(episodeguide, "url")
            episodeguideurl.text = sickbeard.indexerApi(
                show_obj.indexer).config['base_url'] + str(
                    myShow["id"]) + '/all/en.zip'

        if getattr(myShow, 'contentrating', None):
            mpaa = etree.SubElement(tv_node, "mpaa")
            mpaa.text = myShow["contentrating"]

        if getattr(myShow, 'id', None):
            indexerid = etree.SubElement(tv_node, "id")
            indexerid.text = str(myShow["id"])

        if getattr(myShow, 'genre', None) and isinstance(
                myShow["genre"], basestring):
            for genre in self._split_info(myShow["genre"]):
                cur_genre = etree.SubElement(tv_node, "genre")
                cur_genre.text = genre

        if 'country_codes' in show_obj.imdb_info:
            for country in self._split_info(
                    show_obj.imdb_info['country_codes']):
                try:
                    cur_country_name = Country(country.upper()).name.title()
                except Exception:
                    continue

                cur_country = etree.SubElement(tv_node, "country")
                cur_country.text = cur_country_name

        if getattr(myShow, 'firstaired', None):
            premiered = etree.SubElement(tv_node, "premiered")
            premiered.text = myShow["firstaired"]

        if getattr(myShow, 'network', None):
            studio = etree.SubElement(tv_node, "studio")
            studio.text = myShow["network"].strip()

        if getattr(myShow, 'writer', None) and isinstance(
                myShow['writer'], basestring):
            for writer in self._split_info(myShow['writer']):
                cur_writer = etree.SubElement(tv_node, "credits")
                cur_writer.text = writer

        if getattr(myShow, 'director', None) and isinstance(
                myShow['director'], basestring):
            for director in self._split_info(myShow['director']):
                cur_director = etree.SubElement(tv_node, "director")
                cur_director.text = director

        if getattr(myShow, '_actors', None):
            for actor in myShow['_actors']:
                cur_actor = etree.SubElement(tv_node, "actor")

                if 'name' in actor and actor['name'].strip():
                    cur_actor_name = etree.SubElement(cur_actor, "name")
                    cur_actor_name.text = actor['name'].strip()
                else:
                    continue

                if 'role' in actor and actor['role'].strip():
                    cur_actor_role = etree.SubElement(cur_actor, "role")
                    cur_actor_role.text = actor['role'].strip()

                if 'image' in actor and actor['image'].strip():
                    cur_actor_thumb = etree.SubElement(cur_actor, "thumb")
                    cur_actor_thumb.text = actor['image'].strip()

        # Make it purdy
        helpers.indentXML(tv_node)

        data = etree.ElementTree(tv_node)

        return data
Пример #20
0
    def _show_data(self, series_obj):
        """
        Creates an elementTree XML structure for an KODI-style tvshow.nfo and
        returns the resulting data object.

        show_obj: a Series instance to create the NFO for
        """

        my_show = self._get_show_data(series_obj)

        # If by any reason it couldn't get the shows indexer data let's not go throught the rest of this method
        # as that pretty useless.
        if not my_show:
            return False

        tv_node = etree.Element('tvshow')

        title = etree.SubElement(tv_node, 'title')
        title.text = my_show['seriesname']

        if getattr(my_show, 'rating', None):
            rating = etree.SubElement(tv_node, 'rating')
            rating.text = text_type(my_show['rating'])

        if getattr(my_show, 'firstaired', None):
            try:
                year_text = text_type(
                    datetime.datetime.strptime(my_show['firstaired'],
                                               dateFormat).year)
                if year_text:
                    year = etree.SubElement(tv_node, 'year')
                    year.text = year_text
            except Exception:
                pass

        if getattr(my_show, 'overview', None):
            plot = etree.SubElement(tv_node, 'plot')
            plot.text = my_show['overview']

        # For now we're only using this for tvdb indexed shows. We should come with a proper strategy as how to use the
        # metadata for TMDB/TVMAZE shows. We could try to map it a tvdb show. Or keep mixing it.
        if series_obj.indexer == INDEXER_TVDBV2 and getattr(
                my_show, 'id', None):
            episode_guide = etree.SubElement(tv_node, 'episodeguide')
            episode_guide_url = etree.SubElement(episode_guide,
                                                 'url',
                                                 cache='auth.json',
                                                 post='yes')
            episode_guide_url.text = '{url}/login?{{"apikey":"{apikey}","id":{id}}}' \
                                     '|Content-Type=application/json'.format(url=API_BASE_TVDB,
                                                                             apikey=TVDB_API_KEY,
                                                                             id=my_show['id'])

        if getattr(my_show, 'contentrating', None):
            mpaa = etree.SubElement(tv_node, 'mpaa')
            mpaa.text = my_show['contentrating']

        # Add main indexer
        uniqueid = etree.SubElement(tv_node, 'uniqueid')
        uniqueid.set('default', 'true')
        uniqueid.set('type', series_obj.identifier.indexer.slug)
        uniqueid.text = str(series_obj.identifier.id)

        for indexer_slug in ('tvdb', 'tmdb', 'imdb', 'tvmaze', 'anidb'):
            if indexer_slug == series_obj.identifier.indexer.slug:
                continue

            external_id = series_obj.externals.get(f'{indexer_slug}_id')
            if not external_id:
                continue

            uniqueid = etree.SubElement(tv_node, 'uniqueid')
            uniqueid.set('default', 'false')
            uniqueid.set('type', indexer_slug)
            uniqueid.text = str(external_id)

        if getattr(my_show, 'genre', None) and isinstance(
                my_show['genre'], string_types):
            for genre in self._split_info(my_show['genre']):
                cur_genre = etree.SubElement(tv_node, 'genre')
                cur_genre.text = genre

        if 'country_codes' in series_obj.imdb_info:
            for country in self._split_info(
                    series_obj.imdb_info['country_codes']):
                try:
                    cur_country_name = Country(country.upper()).name.title()
                except Exception:
                    continue

                cur_country = etree.SubElement(tv_node, 'country')
                cur_country.text = cur_country_name

        if getattr(my_show, 'firstaired', None):
            premiered = etree.SubElement(tv_node, 'premiered')
            premiered.text = my_show['firstaired']

        if getattr(my_show, 'network', None):
            studio = etree.SubElement(tv_node, 'studio')
            studio.text = my_show['network'].strip()

        if getattr(my_show, 'writer', None) and isinstance(
                my_show['writer'], string_types):
            for writer in self._split_info(my_show['writer']):
                cur_writer = etree.SubElement(tv_node, 'credits')
                cur_writer.text = writer

        if getattr(my_show, 'director', None) and isinstance(
                my_show['director'], string_types):
            for director in self._split_info(my_show['director']):
                cur_director = etree.SubElement(tv_node, 'director')
                cur_director.text = director

        if getattr(my_show, '_actors', None):
            for actor in my_show['_actors']:
                cur_actor = etree.SubElement(tv_node, 'actor')

                if 'name' in actor and actor['name'].strip():
                    cur_actor_name = etree.SubElement(cur_actor, 'name')
                    cur_actor_name.text = actor['name'].strip()
                else:
                    continue

                if 'role' in actor and actor['role'].strip():
                    cur_actor_role = etree.SubElement(cur_actor, 'role')
                    cur_actor_role.text = actor['role'].strip()

                if 'image' in actor and actor['image'].strip():
                    cur_actor_thumb = etree.SubElement(cur_actor, 'thumb')
                    cur_actor_thumb.text = actor['image'].strip()

        # Make it purdy
        helpers.indent_xml(tv_node)

        data = etree.ElementTree(tv_node)

        return data
Пример #21
0
 def test_fromietf_no_country_no_script(self):
     language = Language.fromietf('fra-FR')
     self.assertEqual(language.alpha3, 'fra')
     self.assertEqual(language.country, Country('FR'))
     self.assertIsNone(language.script)
Пример #22
0
    def _show_data(self, show_obj):
        """
        Creates an elementTree XML structure for an KODI-style tvshow.nfo and
        returns the resulting data object.

        show_obj: a TVShow instance to create the NFO for
        """

        show_id = show_obj.indexerid

        indexer_lang = show_obj.lang
        l_indexer_api_params = app.indexerApi(
            show_obj.indexer).api_params.copy()

        l_indexer_api_params['actors'] = True

        if indexer_lang and not indexer_lang == app.INDEXER_DEFAULT_LANGUAGE:
            l_indexer_api_params['language'] = indexer_lang

        if show_obj.dvdorder != 0:
            l_indexer_api_params['dvdorder'] = True

        t = app.indexerApi(show_obj.indexer).indexer(**l_indexer_api_params)

        tv_node = etree.Element('tvshow')

        try:
            my_show = t[int(show_id)]
        except app.indexer_shownotfound:
            logger.log(
                u'Unable to find {indexer} show {id}, skipping it'.format(
                    indexer=app.indexerApi(show_obj.indexer).name, id=show_id),
                logger.ERROR)
            raise

        except app.indexer_error:
            logger.log(
                u'{indexer} is down, can\'t use its data to add this show'.
                format(indexer=app.indexerApi(show_obj.indexer).name),
                logger.ERROR)
            raise

        # check for title and id
        if not (getattr(my_show, 'seriesname', None)
                and getattr(my_show, 'id', None)):
            logger.log(
                u'Incomplete info for {indexer} show {id}, skipping it'.format(
                    indexer=app.indexerApi(show_obj.indexer).name, id=show_id),
                logger.ERROR)
            return False

        title = etree.SubElement(tv_node, 'title')
        title.text = my_show['seriesname']

        if getattr(my_show, 'rating', None):
            rating = etree.SubElement(tv_node, 'rating')
            rating.text = my_show['rating']

        if getattr(my_show, 'firstaired', None):
            try:
                year_text = str(
                    datetime.datetime.strptime(my_show['firstaired'],
                                               dateFormat).year)
                if year_text:
                    year = etree.SubElement(tv_node, 'year')
                    year.text = year_text
            except Exception:
                pass

        if getattr(my_show, 'overview', None):
            plot = etree.SubElement(tv_node, 'plot')
            plot.text = my_show['overview']

        if getattr(my_show, 'id', None):
            episode_guide = etree.SubElement(tv_node, 'episodeguide')
            episode_guide_url = etree.SubElement(episode_guide, 'url')
            episode_guide_url.text = '{url}{id}/all/en.zip'.format(
                url=app.indexerApi(show_obj.indexer).config['base_url'],
                id=my_show['id'])

        if getattr(my_show, 'contentrating', None):
            mpaa = etree.SubElement(tv_node, 'mpaa')
            mpaa.text = my_show['contentrating']

        if getattr(my_show, 'id', None):
            indexer_id = etree.SubElement(tv_node, 'id')
            indexer_id.text = str(my_show['id'])

        if getattr(my_show, 'genre', None) and isinstance(
                my_show['genre'], string_types):
            for genre in self._split_info(my_show['genre']):
                cur_genre = etree.SubElement(tv_node, 'genre')
                cur_genre.text = genre

        if 'country_codes' in show_obj.imdb_info:
            for country in self._split_info(
                    show_obj.imdb_info['country_codes']):
                try:
                    cur_country_name = Country(country.upper()).name.title()
                except Exception:
                    continue

                cur_country = etree.SubElement(tv_node, 'country')
                cur_country.text = cur_country_name

        if getattr(my_show, 'firstaired', None):
            premiered = etree.SubElement(tv_node, 'premiered')
            premiered.text = my_show['firstaired']

        if getattr(my_show, 'network', None):
            studio = etree.SubElement(tv_node, 'studio')
            studio.text = my_show['network'].strip()

        if getattr(my_show, 'writer', None) and isinstance(
                my_show['writer'], string_types):
            for writer in self._split_info(my_show['writer']):
                cur_writer = etree.SubElement(tv_node, 'credits')
                cur_writer.text = writer

        if getattr(my_show, 'director', None) and isinstance(
                my_show['director'], string_types):
            for director in self._split_info(my_show['director']):
                cur_director = etree.SubElement(tv_node, 'director')
                cur_director.text = director

        if getattr(my_show, '_actors', None):
            for actor in my_show['_actors']:
                cur_actor = etree.SubElement(tv_node, 'actor')

                if 'name' in actor and actor['name'].strip():
                    cur_actor_name = etree.SubElement(cur_actor, 'name')
                    cur_actor_name.text = actor['name'].strip()
                else:
                    continue

                if 'role' in actor and actor['role'].strip():
                    cur_actor_role = etree.SubElement(cur_actor, 'role')
                    cur_actor_role.text = actor['role'].strip()

                if 'image' in actor and actor['image'].strip():
                    cur_actor_thumb = etree.SubElement(cur_actor, 'thumb')
                    cur_actor_thumb.text = actor['image'].strip()

        # Make it purdy
        helpers.indentXML(tv_node)

        data = etree.ElementTree(tv_node)

        return data
Пример #23
0
 def test_country_hasattr(self):
     self.assertTrue(hasattr(Country('US'), 'name'))
     self.assertTrue(hasattr(Country('FR'), 'alpha2'))
     self.assertFalse(hasattr(Country('BE'), 'none'))
Пример #24
0
    def _show_data(self, show_obj):
        """
        Creates an elementTree XML structure for an KODI-style tvshow.nfo and
        returns the resulting data object.

        show_obj: a Series instance to create the NFO for
        """

        my_show = self._get_show_data(show_obj)

        # If by any reason it couldn't get the shows indexer data let's not go throught the rest of this method
        # as that pretty useless.
        if not my_show:
            return False

        tv_node = etree.Element('tvshow')

        title = etree.SubElement(tv_node, 'title')
        title.text = my_show['seriesname']

        if getattr(my_show, 'rating', None):
            rating = etree.SubElement(tv_node, 'rating')
            rating.text = my_show['rating']

        if getattr(my_show, 'firstaired', None):
            try:
                year_text = str(
                    datetime.datetime.strptime(my_show['firstaired'],
                                               dateFormat).year)
                if year_text:
                    year = etree.SubElement(tv_node, 'year')
                    year.text = year_text
            except Exception:
                pass

        if getattr(my_show, 'overview', None):
            plot = etree.SubElement(tv_node, 'plot')
            plot.text = my_show['overview']

        if getattr(my_show, 'id', None):
            episode_guide = etree.SubElement(tv_node, 'episodeguide')
            episode_guide_url = etree.SubElement(episode_guide,
                                                 'url',
                                                 cache='auth.json',
                                                 post='yes')
            episode_guide_url.text = '{url}/login?{{"apikey":"{apikey}","id":{id}}}' \
                                     '|Content-Type=application/json'.format(url=API_BASE_TVDB,
                                                                             apikey=TVDB_API_KEY,
                                                                             id=my_show['id'])

        if getattr(my_show, 'contentrating', None):
            mpaa = etree.SubElement(tv_node, 'mpaa')
            mpaa.text = my_show['contentrating']

        if getattr(my_show, 'id', None):
            indexer_id = etree.SubElement(tv_node, 'id')
            indexer_id.text = str(my_show['id'])

        if getattr(my_show, 'genre', None) and isinstance(
                my_show['genre'], string_types):
            for genre in self._split_info(my_show['genre']):
                cur_genre = etree.SubElement(tv_node, 'genre')
                cur_genre.text = genre

        if 'country_codes' in show_obj.imdb_info:
            for country in self._split_info(
                    show_obj.imdb_info['country_codes']):
                try:
                    cur_country_name = Country(country.upper()).name.title()
                except Exception:
                    continue

                cur_country = etree.SubElement(tv_node, 'country')
                cur_country.text = cur_country_name

        if getattr(my_show, 'firstaired', None):
            premiered = etree.SubElement(tv_node, 'premiered')
            premiered.text = my_show['firstaired']

        if getattr(my_show, 'network', None):
            studio = etree.SubElement(tv_node, 'studio')
            studio.text = my_show['network'].strip()

        if getattr(my_show, 'writer', None) and isinstance(
                my_show['writer'], string_types):
            for writer in self._split_info(my_show['writer']):
                cur_writer = etree.SubElement(tv_node, 'credits')
                cur_writer.text = writer

        if getattr(my_show, 'director', None) and isinstance(
                my_show['director'], string_types):
            for director in self._split_info(my_show['director']):
                cur_director = etree.SubElement(tv_node, 'director')
                cur_director.text = director

        if getattr(my_show, '_actors', None):
            for actor in my_show['_actors']:
                cur_actor = etree.SubElement(tv_node, 'actor')

                if 'name' in actor and actor['name'].strip():
                    cur_actor_name = etree.SubElement(cur_actor, 'name')
                    cur_actor_name.text = actor['name'].strip()
                else:
                    continue

                if 'role' in actor and actor['role'].strip():
                    cur_actor_role = etree.SubElement(cur_actor, 'role')
                    cur_actor_role.text = actor['role'].strip()

                if 'image' in actor and actor['image'].strip():
                    cur_actor_thumb = etree.SubElement(cur_actor, 'thumb')
                    cur_actor_thumb.text = actor['image'].strip()

        # Make it purdy
        helpers.indent_xml(tv_node)

        data = etree.ElementTree(tv_node)

        return data
Пример #25
0
 def test_eq_with_country(self):
     self.assertEqual(Language('eng', 'US'), Language('eng', Country('US')))
Пример #26
0
    def _show_data(self, show_obj):
        """
        Creates an elementTree XML structure for an KODI-style tvshow.nfo and
        returns the resulting data object.

        show_obj: a TVShow instance to create the NFO for
        """
        tv_node = etree.Element("tvshow")

        myShow = sickchill.indexer.series(show_obj)
        if not myShow:
            logger.log("Unable to find show with id {} on {}, skipping it".format(
                show_obj.indexerid, show_obj.idxr.name.name))
            return False

        # check for title and id
        if not (getattr(myShow, 'seriesName', None) and getattr(myShow, 'id', None)):
            logger.log("Incomplete info for show with id {} on {}, skipping it".format(
                show_obj.indexerid, show_obj.idxr.name.name))
            return False

        title = etree.SubElement(tv_node, "title")
        title.text = myShow.seriesName

        if getattr(myShow, 'rating', None):
            rating = etree.SubElement(tv_node, "rating")
            rating.text = str(myShow.rating)
            mpaa = etree.SubElement(tv_node, "mpaa")
            mpaa.text = str(myShow.rating)

        if getattr(myShow, 'firstAired', None):
            try:
                year_text = str(datetime.datetime.strptime(myShow.firstAired, dateFormat).year)
                if year_text:
                    year = etree.SubElement(tv_node, "year")
                    year.text = year_text
            except Exception:
                pass

        if getattr(myShow, 'overview', None):
            plot = etree.SubElement(tv_node, "plot")
            plot.text = myShow.overview

        if getattr(myShow, 'id', None):
            episodeguide = etree.SubElement(tv_node, "episodeguide")
            episodeguideurl = etree.SubElement(episodeguide, "url")
            episodeguideurl.text = show_obj.idxr.base_url + str(myShow.id) + '/all/en.zip'

            indexerid = etree.SubElement(tv_node, "id")
            indexerid.text = str(myShow.id)

            indexerid = etree.SubElement(tv_node, "tvdbid")
            indexerid.text = str(myShow.id)

        if getattr(myShow, 'genre', None) and isinstance(myShow.genre, list):
            for genre in myShow.genre:
                cur_genre = etree.SubElement(tv_node, "genre")
                cur_genre.text = genre

        if show_obj.imdb_info.get('country_codes'):
            for country in self._split_info(show_obj.imdb_info['country_codes']):
                try:
                    cur_country_name = Country(country.upper()).name.title()
                except Exception:
                    continue

                cur_country = etree.SubElement(tv_node, "country")
                cur_country.text = cur_country_name

        if getattr(myShow, 'firstAired', None):
            premiered = etree.SubElement(tv_node, "premiered")
            premiered.text = myShow.firstAired

        if getattr(myShow, 'network', None):
            studio = etree.SubElement(tv_node, "studio")
            studio.text = myShow.network.strip()

        data = show_obj.idxr.actors(myShow)
        if data:
            for actor in data:
                cur_actor = etree.SubElement(tv_node, "actor")

                if 'name' in actor and actor['name'].strip():
                    cur_actor_name = etree.SubElement(cur_actor, "name")
                    cur_actor_name.text = actor['name'].strip()
                else:
                    continue

                if 'role' in actor and actor['role'].strip():
                    cur_actor_role = etree.SubElement(cur_actor, "role")
                    cur_actor_role.text = actor['role'].strip()

                if 'image' in actor and actor['image'].strip():
                    cur_actor_thumb = etree.SubElement(cur_actor, "thumb")
                    cur_actor_thumb.text = show_obj.idxr.complete_image_url(actor['image'])

        # Make it purdy
        helpers.indentXML(tv_node)

        data = etree.ElementTree(tv_node)

        return data
Пример #27
0
 def test_ne_with_country_and_script(self):
     self.assertNotEqual(Language('srp', 'SR', 'Latn'), Language('srp', Country('SR'), Script('Cyrl')))
Пример #28
0
def episodes():
    return {'bbt_s07e05':
            Episode(os.path.join('The Big Bang Theory', 'Season 07',
                                 'The.Big.Bang.Theory.S07E05.720p.HDTV.X264-DIMENSION.mkv'),
                    'The Big Bang Theory', 7, 5, title='The Workplace Proximity', year=2007, tvdb_id=4668379,
                    series_tvdb_id=80379, series_imdb_id='tt0898266', source='HDTV', release_group='DIMENSION',
                    resolution='720p', video_codec='H.264', audio_codec='Dolby Digital',
                    imdb_id='tt3229392', size=501910737,
                    hashes={'napiprojekt': '6303e7ee6a835e9fcede9fb2fb00cb36',
                            'opensubtitles': '6878b3ef7c1bd19e',
                            'shooter': 'c13e0e5243c56d280064d344676fff94;cd4184d1c0c623735f6db90841ce15fc;'
                                       '3faefd72f92b63f2504269b4f484a377;8c68d1ef873afb8ba0cc9f97cbac41c1',
                            'thesubdb': '9dbbfb7ba81c9a6237237dae8589fccc'}),
            'got_s03e10':
            Episode(os.path.join('Game of Thrones', 'Season 03',
                                 'Game.of.Thrones.S03E10.Mhysa.720p.WEB-DL.DD5.1.H.264-NTb.mkv'),
                    'Game of Thrones', 3, 10, title='Mhysa', tvdb_id=4517466, series_tvdb_id=121361,
                    series_imdb_id='tt0944947', source='Web', release_group='NTb', resolution='720p',
                    video_codec='H.264', audio_codec='Dolby Digital', imdb_id='tt2178796', size=2142810931,
                    hashes={'napiprojekt': '6303e7ee6a835e9fcede9fb2fb00cb36',
                            'opensubtitles': 'b850baa096976c22',
                            'shooter': 'b02d992c04ad74b31c252bd5a097a036;ef1b32f873b2acf8f166fc266bdf011a;'
                                       '82ce34a3bcee0c66ed3b26d900d31cca;78113770551f3efd1e2d4ec45898c59c',
                            'thesubdb': 'b1f899c77f4c960b84b8dbf840d4e42d'}),
            'dallas_s01e03':
            Episode('Dallas.S01E03.mkv', 'Dallas', 1, 3, title='Spy in the House', year=1978, tvdb_id=228224,
                    series_tvdb_id=77092, series_imdb_id='tt0077000'),
            'dallas_2012_s01e03':
            Episode('Dallas.2012.S01E03.mkv', 'Dallas', 1, 3, title='The Price You Pay', year=2012,
                    original_series=False, tvdb_id=4199511, series_tvdb_id=242521, series_imdb_id='tt1723760',
                    imdb_id='tt2205526'),
            'marvels_agents_of_shield_s02e06':
            Episode('Marvels.Agents.of.S.H.I.E.L.D.S02E06.720p.HDTV.x264-KILLERS.mkv',
                    'Marvel\'s Agents of S.H.I.E.L.D.', 2, 6, year=2013, source='HDTV', release_group='KILLERS',
                    resolution='720p', video_codec='H.264'),
            'csi_cyber_s02e03':
            Episode('CSI.Cyber.S02E03.hdtv-lol.mp4', 'CSI: Cyber', 2, 3, source='HDTV', release_group='lol'),
            'the_x_files_s10e02':
            Episode('The.X-Files.S10E02.HDTV.x264-KILLERS.mp4', 'The X-Files', 10, 2, source='HDTV',
                    release_group='KILLERS', video_codec='H.264'),
            'colony_s01e09':
            Episode('Colony.S01E09.720p.HDTV.x264-KILLERS.mkv', 'Colony', 1, 9, title='Zero Day', year=2016,
                    tvdb_id=5463229, series_tvdb_id=284210, series_imdb_id='tt4209256', source='HDTV',
                    release_group='KILLERS', resolution='720p', video_codec='H.264', imdb_id='tt4926022'),
            'the_jinx_e05':
            Episode('The.Jinx-The.Life.and.Deaths.of.Robert.Durst.E05.BDRip.x264-ROVERS.mkv',
                    'The Jinx: The Life and Deaths of Robert Durst', 1, 5, year=2015, original_series=True,
                    source='Blu-ray', release_group='ROVERS', video_codec='H.264'),
            'the_100_s03e09':
            Episode('The.100.S03E09.720p.HDTV.x264-AVS.mkv', 'The 100', 3, 9, title='Stealing Fire', year=2014,
                    tvdb_id=5544536, series_tvdb_id=268592, series_imdb_id='tt2661044', source='HDTV',
                    release_group='AVS', resolution='720p', video_codec='H.264', imdb_id='tt4799896'),
            'the fall':
            Episode('the_fall.3x01.720p_hdtv_x264-fov.mkv', 'The Fall', 3, 1, title='The Fall', year=2013,
                    tvdb_id=5749493, series_tvdb_id=258107, series_imdb_id='tt2294189', source='HDTV',
                    release_group='fov', resolution='720p', video_codec='H.264', imdb_id='tt4516230'),
            'csi_s15e18':
            Episode('CSI.S15E18.720p.HDTV.X264.DIMENSION.mkv', 'CSI: Crime Scene Investigation', 15, 18,
                    title='The End Game', year=2000, tvdb_id=5104359, series_tvdb_id=72546, series_imdb_id='tt0247082',
                    source='HDTV', release_group='DIMENSION', resolution='720p', video_codec='H.264',
                    imdb_id='tt4145952'),
            'turn_s04e03':
            Episode('Turn.S04E03.720p.HDTV.x264-AVS.mkv', "TURN: Washington's Spies", 4, 3,
                    title='Blood for Blood', year=2014, tvdb_id=6124360, series_tvdb_id=272135,
                    series_imdb_id='tt2543328',
                    source='HDTV', release_group='AVS', resolution='720p', video_codec='H.264',
                    imdb_id='tt6137686', alternative_series=['Turn']),
            'turn_s03e01':
            Episode('Turn.S03E01.720p.HDTV.x264-AVS.mkv', "TURN: Washington's Spies", 3, 1,
                    title='Valediction', year=2014, tvdb_id=5471384, series_tvdb_id=272135,
                    series_imdb_id='tt2543328',
                    source='HDTV', release_group='AVS', resolution='720p', video_codec='H.264',
                    imdb_id='tt4909774', alternative_series=['Turn']),
            'marvels_jessica_jones_s01e13':
            Episode('Marvels.Jessica.Jones.S01E13.720p.WEBRip.x264-2HD', "Marvels Jessica Jones", 1, 13,
                    title='AKA Smile', year=2015, tvdb_id=5311273, series_tvdb_id=284190,
                    series_imdb_id='tt2357547',
                    source='Web', release_group='2HD', resolution='720p', video_codec='H.264',
                    imdb_id='tt4162096', alternative_series=['Jessica Jones']),
            'fear_walking_dead_s03e10':
            Episode('Fear.the.Walking.Dead.S03E10.1080p.WEB-DL.DD5.1.H264-RARBG', 'Fear the Walking Dead', 3, 10,
                    resolution='1080p', source='Web', video_codec='H.264', release_group='RARBG'),
            'the_end_of_the_fucking_world':
            Episode('the.end.of.the.f*****g.world.s01e04.720p.web.x264-skgtv.mkv', 'The End of the F*****g World', 1, 4,
                    resolution='720p', source='Web', video_codec='H.264', release_group='skgtv',
                    alternative_series=['The end of the f***ing world']),
            'Marvels.Agents.of.S.H.I.E.L.D.S05E01-E02':
            Episode('Marvels.Agents.of.S.H.I.E.L.D.S05E01-E02.720p.HDTV.x264-AVS', 'Marvels.Agents.of.S.H.I.E.L.D', 5,
                    1, resolution='720p', source='HDTV', video_codec='H.264', release_group='AVS'),
            'alex_inc_s01e04':
            Episode('Alex.Inc.S01E04.HDTV.x264-SVA.mkv', 'Alex, Inc.', 1, 4, source='HDTV', video_codec='H.264',
                    release_group='SVA', year=2018, title='The Nanny', series_imdb_id='tt6466948', tvdb_id=6627151,
                    series_tvdb_id=328635),
            'shameless_us_s08e01':
            Episode('Shameless.US.s08e01.web.h264-convoy', 'Shameless', 8, 1, source='Web', video_codec='H.264',
                    country=Country('US'), original_series=False, release_group='convoy', year=2011,
                    alternative_series=['Shameless US'], title='We Become What We... Frank!',
                    series_imdb_id='tt1586680', series_tvdb_id=161511, imdb_id='tt6347410', tvdb_id=6227949),
            'house_of_cards_us_s06e01':
            Episode('house.of.cards.us.s06e01.720p.web-dl.x264', 'House of Cards', 6, 1, source='Web',
                    video_codec='H.264', country=Country('US'), year=2013, original_series=False,
                    alternative_series=['House of Cards (2013)'], title='Chapter 66', series_imdb_id='tt1856010',
                    series_tvdb_id=262980, imdb_id='tt7538918', tvdb_id=6553109),
            'walking_dead_s08e07':
            Episode('The Walking Dead - 08x07 - Time for After.AMZN.WEB-DL-CasStudio.mkv', 'The Walking Dead',
                    8, 7, source='Web', streaming_service='Amazon Prime', release_group='CasStudio')
            }