当前位置: 首页>>代码示例>>Python>>正文


Python Language.fromietf方法代码示例

本文整理汇总了Python中babelfish.Language.fromietf方法的典型用法代码示例。如果您正苦于以下问题:Python Language.fromietf方法的具体用法?Python Language.fromietf怎么用?Python Language.fromietf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在babelfish.Language的用法示例。


在下文中一共展示了Language.fromietf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_downloads_for_all_configured_languages

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
 def test_downloads_for_all_configured_languages(self):
     superliminal.env.settings.languages.append(Language.fromietf('pt-BR'))
     self.set_subtitles([{
         'id': 'english_sub',
         'language': Language.fromietf('en'),
         'series': "Series Title",
         'season': 2,
         'episode': 3,
         'title': "The Episode",
         'release_group': "TvRG",
         'resolution': '720p',
         'content': SUBTITLE_CONTENT
     },
     {
         'id': 'brazilian_sub',
         'language': Language.fromietf('pt-BR'),
         'series': "Series Title",
         'season': 2,
         'episode': 3,
         'title': "The Episode",
         'release_group': "TvRG",
         'resolution': '720p',
         'content': SUBTITLE_CONTENT_2
     }])
     request = self.get_add_request(name="Series.Title.S02E03.720p.WEB-DL.H264-TvRG.mkv")
     response = yield self.http_client.fetch(request)
     self.assertEqual(200, response.code)
     yield self.wait_until_processed()
     self.assert_subtitle_contents_matches(expected_content=SUBTITLE_CONTENT, suffix='.en.srt')
     self.assert_subtitle_contents_matches(expected_content=SUBTITLE_CONTENT_2, suffix='.pt-BR.srt')
开发者ID:NigelRook,项目名称:superliminal,代码行数:32,代码来源:test_system.py

示例2: test_downloads_new_sub_if_new_video_added_for_existing_path

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
 def test_downloads_new_sub_if_new_video_added_for_existing_path(self):
     self.set_subtitles([{
         'id': 'new_sub',
         'language': Language.fromietf('en'),
         'series': "Series Title",
         'season': 2,
         'episode': 3,
         'title': "The Episode",
         'release_group': "TvRG",
         'resolution': '720p',
         'content': SUBTITLE_CONTENT
     },
     {
         'id': 'old_sub',
         'language': Language.fromietf('en'),
         'series': "Series Title",
         'season': 2,
         'episode': 3,
         'title': "The Episode",
         'release_group': "OtherRG",
         'resolution': '720p',
         'content': SUBTITLE_CONTENT_2
     }])
     request = self.get_add_request(name="Series.Title.S02E03.720p.WEB-DL.H264-OtherRG.mkv")
     response = yield self.http_client.fetch(request)
     self.assertEqual(200, response.code)
     yield self.wait_until_processed()
     request = self.get_add_request(name="Series.Title.S02E03.720p.WEB-DL.H264-TvRG.mkv")
     response = yield self.http_client.fetch(request)
     self.assertEqual(200, response.code)
     yield self.wait_until_processed()
     self.assert_subtitle_contents_matches()
开发者ID:NigelRook,项目名称:superliminal,代码行数:34,代码来源:test_system.py

示例3: check_missing_subtitle_languages

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
def check_missing_subtitle_languages(dirname, filename):
    log.debug("Checking for missing subtitle")
    missing_subtitles = []
    # Check embedded subtitles
    embedded_subtitles = []
    if autosubliminal.SCANEMBEDDEDSUBS:
        embedded_subtitles = _get_embedded_subtitles(dirname, filename)
    # Check default language
    if autosubliminal.DEFAULTLANGUAGE:
        default_language = Language.fromietf(autosubliminal.DEFAULTLANGUAGE)
        # Check with or without alpha2 code suffix depending on configuration
        if autosubliminal.DEFAULTLANGUAGESUFFIX:
            srtfile = os.path.splitext(filename)[0] + u"." + autosubliminal.DEFAULTLANGUAGE + u".srt"
        else:
            srtfile = os.path.splitext(filename)[0] + u".srt"
        if not os.path.exists(os.path.join(dirname, srtfile)) and default_language not in embedded_subtitles:
            missing_subtitles.append(autosubliminal.DEFAULTLANGUAGE)
    # Check additional languages
    if autosubliminal.ADDITIONALLANGUAGES:
        # Always check with alpha2 code suffix for additional languages
        for language in autosubliminal.ADDITIONALLANGUAGES:
            additional_language = Language.fromietf(language)
            srtfile = os.path.splitext(filename)[0] + u"." + language + u".srt"
            if not os.path.exists(os.path.join(dirname, srtfile)) and additional_language not in embedded_subtitles:
                missing_subtitles.append(language)
    return missing_subtitles
开发者ID:sdtechz,项目名称:Auto-Subliminal,代码行数:28,代码来源:diskscanner.py

示例4: test_added_subs_are_returned_by_lang

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def test_added_subs_are_returned_by_lang(self):
        path = "/data/Series/Season 1/01 Title.mkv"
        video = Video.fromname("Series.S01E02.Title.720p.WEB-DL.DD5.1.H264-ReleaseGroup.mkv")
        self.datastore.add_video(path, video)

        provider1 = "davessubs"
        sub_id1 = "ABC123"
        lang1 = Language.fromietf("en")
        score1 = 123
        provider2 = "stevesubs"
        sub_id2 = "steve123"
        lang2 = lang1
        score2 = 120
        provider3 = "pablosubs"
        sub_id3 = "umdoistres"
        lang3 = Language.fromietf("pt-BR")
        score3 = 150
        self.datastore.add_download(path, provider1, sub_id1, lang1, score1)
        self.datastore.add_download(path, provider2, sub_id2, lang2, score2)
        self.datastore.add_download(path, provider3, sub_id3, lang3, score3)

        downloads = self.datastore.get_downloads_for_video(path)

        self.assertEqual(
            downloads,
            {
                lang1: [
                    {"provider": provider1, "sub_id": sub_id1, "lang": lang1, "score": score1},
                    {"provider": provider2, "sub_id": sub_id2, "lang": lang2, "score": score2},
                ],
                lang3: [{"provider": provider3, "sub_id": sub_id3, "lang": lang3, "score": score3}],
            },
        )
开发者ID:NigelRook,项目名称:superliminal,代码行数:35,代码来源:test_datastore.py

示例5: test_check_for_better_checks_all_recent_videos

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def test_check_for_better_checks_all_recent_videos(self):
        oktvsub = {
            'id': 'oktvsub',
            'language': Language.fromietf('en'),
            'series': "Series Title",
            'season': 2,
            'episode': 3,
            'title': "The Episode",
            'release_group': "OtherRG",
            'content': SUBTITLE_CONTENT
        }
        yield self.add_video(name="Series.Title.S02E03.720p.WEB-DL.H264-TvRG.mkv", subtitle=oktvsub)
        movie_filename = self.create_video_file()
        okmoviesub = {
            'id': 'okmoviesub',
            'language': Language.fromietf('en'),
            'title': "Movie Title",
            'year': 2016,
            'release_group': "OtherRG",
            'content': SUBTITLE_CONTENT
        }
        yield self.add_video(path=movie_filename,
            name="Movie.Title.2016.720p.WEB-DL.H264-MovieRG.mkv", subtitle=okmoviesub)

        bettertvsub = self.transform_sub(oktvsub, 'bettertvsub',
            release_group="TvRG", content=SUBTITLE_CONTENT_2)
        bettermoviesub = self.transform_sub(okmoviesub, 'bettermoviesub',
            release_group="MovieRG", content=SUBTITLE_CONTENT_3)
        self.set_subtitles([oktvsub, bettertvsub, okmoviesub, bettermoviesub])

        SuperliminalCore.check_for_better()
        yield self.wait_until_processed()
        self.assert_subtitle_contents_matches(expected_content=SUBTITLE_CONTENT_2)
        self.assert_subtitle_contents_matches(video_filename=movie_filename,
            expected_content=SUBTITLE_CONTENT_3)
开发者ID:NigelRook,项目名称:superliminal,代码行数:37,代码来源:test_system.py

示例6: test_check_for_better_checks_languages_with_no_current_subs

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def test_check_for_better_checks_languages_with_no_current_subs(self):
        superliminal.env.settings.languages.append(Language.fromietf('pt-BR'))
        okensub = {
            'id': 'okensub',
            'language': Language.fromietf('en'),
            'series': "Series Title",
            'season': 2,
            'episode': 3,
            'title': "The Episode",
            'release_group': "OtherRG",
            'content': SUBTITLE_CONTENT
        }
        self.set_subtitles([okensub])
        self.add_video(name="Series.Title.S02E03.720p.WEB-DL.H264-TvRG.mkv")
        yield self.wait_until_processed()

        betterensub = self.transform_sub(okensub, 'betterensub',
            release_group="TvRG", content=SUBTITLE_CONTENT_2)
        okbrsub = self.transform_sub(okensub, 'okbrsub',
            language=Language.fromietf('pt-BR'), content=SUBTITLE_CONTENT_3)
        self.set_subtitles([okensub, betterensub, okbrsub])

        SuperliminalCore.check_for_better()
        yield self.wait_until_processed()
        self.assert_subtitle_contents_matches(expected_content=SUBTITLE_CONTENT_2, suffix='.en.srt')
        self.assert_subtitle_contents_matches(expected_content=SUBTITLE_CONTENT_3, suffix='.pt-BR.srt')
开发者ID:NigelRook,项目名称:superliminal,代码行数:28,代码来源:test_system.py

示例7: _detect_subtitle_language

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
def _detect_subtitle_language(srt_path):
    log.debug('Detecting subtitle language')

    # Load srt file (try first iso-8859-1 with fallback to utf-8)
    try:
        subtitle = pysrt.open(path=srt_path, encoding='iso-8859-1')
    except Exception:
        try:
            subtitle = pysrt.open(path=srt_path, encoding='utf-8')
        except Exception:
            # If we can't read it, we can't detect, so return
            return None

    # Read first 5 subtitle lines to determine the language
    if len(subtitle) >= 5:
        text = ''
        for sub in subtitle[0:5]:
            text += sub.text

        # Detect the language with highest probability and return it if it's more than the required minimum probability
        detected_languages = langdetect.detect_langs(text)
        log.debug('Detected subtitle language(s): %s', detected_languages)
        if len(detected_languages) > 0:
            # Get first detected language (list is sorted according to probability, highest first)
            detected_language = detected_languages[0]
            language_probability = detected_language.prob
            if language_probability >= autosubliminal.DETECTEDLANGUAGEPROBABILITY:
                log.debug('Probability of detected subtitle language accepted: %s', detected_language)
                return Language.fromietf(detected_language.lang)
            else:
                log.debug('Probability of detected subtitle language too low: %s', detected_language)

    return None
开发者ID:h3llrais3r,项目名称:Auto-Subliminal,代码行数:35,代码来源:filesystem.py

示例8: search_external_subtitles

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
def search_external_subtitles(path):
    """Search for external subtitles from a video `path` and their associated language.

    :param str path: path to the video.
    :return: found subtitles with their languages.
    :rtype: dict

    """
    dirpath, filename = os.path.split(path)
    dirpath = dirpath or '.'
    fileroot, fileext = os.path.splitext(filename)
    subtitles = {}
    for p in os.listdir(dirpath):
        # keep only valid subtitle filenames
        if not p.startswith(fileroot) or not p.endswith(SUBTITLE_EXTENSIONS):
            continue

        # extract the potential language code
        language_code = p[len(fileroot):-len(os.path.splitext(p)[1])].replace(fileext, '').replace('_', '-')[1:]

        # default language is undefined
        language = Language('und')

        # attempt to parse
        if language_code:
            try:
                language = Language.fromietf(language_code)
            except ValueError:
                logger.error('Cannot parse language code %r', language_code)

        subtitles[p] = language

    logger.debug('Found subtitles %r', subtitles)

    return subtitles
开发者ID:BreizhCat,项目名称:SickRage,代码行数:37,代码来源:video.py

示例9: make_lang_list

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
def make_lang_list(languages, session=None):
    if not isinstance(languages, list):
        languages = [languages]
    # TODO: find better way of enforcing uniqueness without catching exceptions or doing dumb shit like this
    languages = set([unicode(Language.fromietf(l)) for l in languages])

    result = set()
    for language in languages:
        lang = get_lang(language, session=session) or SubtitleLanguages(unicode(language))
        result.add(lang)
    return list(result)
开发者ID:MikeyCanuck,项目名称:Flexget,代码行数:13,代码来源:subtitle_queue.py

示例10: to_entry

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
 def to_entry(self):
     entry = Entry()
     entry['title'] = self.title
     entry['url'] = 'mock://localhost/subtitle_list/%d' % self.id
     entry['location'] = self.location
     entry['remove_after'] = self.remove_after
     entry['added'] = self.added
     entry['subtitle_languages'] = []
     for subtitle_language in self.languages:
         entry['subtitle_languages'].append(Language.fromietf(subtitle_language.language))
     return entry
开发者ID:Flexget,项目名称:Flexget,代码行数:13,代码来源:subtitle_list.py

示例11: test_get_incomplete_videos

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def test_get_incomplete_videos(self, name, videos, expected):
        for video in videos:
            added = datetime.utcnow() - video["age"] if "age" in video else timedelta(0)
            self.datastore.add_video(video["path"], Video.fromname(video["name"]), added)
            for provider, sub_id, lang, score in video["downloads"]:
                self.datastore.add_download(video["path"], provider, sub_id, Language.fromietf(lang), score)

        lang1 = Language.fromietf("en")
        lang2 = Language.fromietf("pt-BR")
        incomplete = self.datastore.get_incomplete_videos(
            [lang1, lang2], 80, 100, datetime.utcnow() - timedelta(days=1)
        )

        self.assertEqual(len(incomplete), len(expected))
        for video_idx, needs in expected:
            actual = next(video for video in incomplete if video["path"] == videos[video_idx]["path"])
            self.assertEqual(actual["video"].name, videos[video_idx]["name"])
            self.assertEqual(len(actual["needs"]), len(needs))
            for lang, score in needs:
                actual_need = next(need for need in actual["needs"] if str(need["lang"]) == lang)
                self.assertEqual(actual_need["current_score"], score)
开发者ID:NigelRook,项目名称:superliminal,代码行数:23,代码来源:test_datastore.py

示例12: set_langs

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def set_langs(self, langs):
        langs_set = set()
        for lang in langs:
            # Using a more flexible standard (ietf), allowing both fr et fra (e.g.)
            langs_set.add(Language.fromietf(lang))

        self.langs = langs_set

        if len(langs_set) > 1:
            self.isSingle = False

        return self
开发者ID:vaginessa,项目名称:pydebrid,代码行数:14,代码来源:subtitle.py

示例13: test_added_sub_is_returned

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
    def test_added_sub_is_returned(self):
        path = "/data/Series/Season 1/01 Title.mkv"
        video = Video.fromname("Series.S01E02.Title.720p.WEB-DL.DD5.1.H264-ReleaseGroup.mkv")
        self.datastore.add_video(path, video)
        provider = "davessubs"
        sub_id = "ABC123"
        lang = Language.fromietf("en")
        score = 123
        self.datastore.add_download(path, provider, sub_id, lang, score)

        downloads = self.datastore.get_downloads_for_video(path)

        self.assertEqual(downloads, {lang: [{"provider": provider, "sub_id": sub_id, "lang": lang, "score": score}]})
开发者ID:NigelRook,项目名称:superliminal,代码行数:15,代码来源:test_datastore.py

示例14: setUp

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
 def setUp(self):
     super(CouchPotatoTests, self).setUp()
     self.cp = fakecouchpotato.FakeCouchPotato(self.video_filename)
     self.set_subtitles([{
         'id': 'theonlysub',
         'language': Language.fromietf('en'),
         'title': fakecouchpotato.MOVIE_TITLE,
         'year': fakecouchpotato.MOVIE_YEAR,
         'release_group': fakecouchpotato.MOVIE_RELEASE_GROUP,
         'content': SUBTITLE_CONTENT
     }])
     superliminal.env.settings.couchpotato_url = self.cp.url
     superliminal.env.settings.couchpotato_api_key = fakecouchpotato.API_KEY
开发者ID:NigelRook,项目名称:superliminal,代码行数:15,代码来源:test_system.py

示例15: test_add_movie

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromietf [as 别名]
 def test_add_movie(self):
     self.set_subtitles([{
         'id': 'theonlysub',
         'language': Language.fromietf('en'),
         'title': "Movie Title",
         'year': 2016,
         'release_group': "MovieRG",
         'content': SUBTITLE_CONTENT
     }])
     request = self.get_add_request(name="Movie.Title.2016.720p.WEB-DL.H264-MovieRG.mkv")
     response = yield self.http_client.fetch(request)
     self.assertEqual(200, response.code)
     yield self.wait_until_processed()
     self.assert_subtitle_contents_matches()
开发者ID:NigelRook,项目名称:superliminal,代码行数:16,代码来源:test_system.py


注:本文中的babelfish.Language.fromietf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。