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


Python Language.fromalpha3t方法代码示例

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


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

示例1: test_converter_alpha3t

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromalpha3t [as 别名]
 def test_converter_alpha3t(self):
     self.assertEqual(Language('fra').alpha3t, 'fra')
     self.assertEqual(Language.fromalpha3t('fra'), Language('fra'))
     self.assertEqual(Language.fromcode('fra', 'alpha3t'), Language('fra'))
     self.assertRaises(LanguageReverseError, lambda: Language.fromalpha3t('zzz'))
     self.assertRaises(LanguageConvertError, lambda: Language('aaa').alpha3t)
     self.assertEqual(len(language_converters['alpha3t'].codes), 418)
开发者ID:Diaoul,项目名称:babelfish,代码行数:9,代码来源:tests.py

示例2: test_converter_alpha3t

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromalpha3t [as 别名]
 def test_converter_alpha3t(self):
     self.assertEqual(Language('fra').alpha3t, 'fra')
     self.assertEqual(Language.fromalpha3t('fra'), Language('fra'))
     self.assertEqual(Language.fromcode('fra', 'alpha3t'), Language('fra'))
     with self.assertRaises(LanguageReverseError):
         Language.fromalpha3t('zzz')
     with self.assertRaises(LanguageConvertError):
         Language('aaa').alpha3t
     self.assertEqual(len(get_language_converter('alpha3t').codes), 418)
开发者ID:nvbn,项目名称:babelfish,代码行数:11,代码来源:tests.py

示例3: getAlpha3TCode

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromalpha3t [as 别名]
def getAlpha3TCode(code):  # We need to make sure that language codes are alpha3T
    """
        :param    code: Alpha2, Alpha3, or Alpha3b code.
        :type     code: C{str}

        :return: Alpha3t language code (ISO 639-2/T) as C{str}
    """
    lang = 'und'
    code = code.strip().lower()

    if len(code) == 3:
        try:
            lang = Language(code).alpha3t
        except:
            try:
                lang = Language.fromalpha3b(code).alpha3t
            except:
                try:
                    lang = Language.fromalpha3t(code).alpha3t
                except:
                    pass

    elif len(code) == 2:
        lang = Language.fromalpha2(code).alpha3t

    return lang
开发者ID:phtagn,项目名称:sickbeard_mp4_automator,代码行数:28,代码来源:languagecode.py

示例4: generateOptions

# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromalpha3t [as 别名]

#.........这里部分代码省略.........

                        try:
                            extension = subtitle_codec_extensions[codec]
                        except:
                            self.log.info("Wasn't able to determine subtitle file extension, defaulting to '.srt'.")
                            extension = 'srt'

                        forced = ".forced" if s.sub_forced else ""

                        input_dir, filename, input_extension = self.parseFile(inputfile)
                        output_dir = input_dir if self.output_dir is None else self.output_dir
                        outputfile = os.path.join(output_dir, filename + "." + s.metadata['language'] + forced + "." + extension)

                        i = 2
                        while os.path.isfile(outputfile):
                            self.log.debug("%s exists, appending %s to filename." % (outputfile, i))
                            outputfile = os.path.join(output_dir, filename + "." + s.metadata['language'] + forced + "." + str(i) + "." + extension)
                            i += 1
                        try:
                            self.log.info("Ripping %s subtitle from source stream %s into external file." % (s.metadata['language'], s.index))
                            conv = Converter(self.FFMPEG_PATH, self.FFPROBE_PATH).convert(inputfile, outputfile, options, timeout=None)
                            for timecode in conv:
                                    pass

                            self.log.info("%s created." % outputfile)
                        except:
                            self.log.exception("Unabled to create external subtitle file for stream %s." % (s.index))

        # Attempt to download subtitles if they are missing using subliminal
        languages = set()
        try:
            if self.swl != 'und':
                for alpha3t in self.swl:
                    languages.add(Language.fromalpha3t(alpha3t))
            elif self.sdl != 'und':
                languages.add(Language.fromalpha3t(self.sdl))
            else:
                self.downloadsubs = False
                self.log.error("No valid subtitle language specified, cannot download subtitles.")
        except:
            self.log.exception("Unable to verify subtitle languages for download.")
            self.downloadsubs = False

        if self.downloadsubs:
            import subliminal
            self.log.info("Attempting to download subtitles.")

            # Attempt to set the dogpile cache
            try:
                subliminal.region.configure('dogpile.cache.memory')
            except:
                pass

            try:
                video = subliminal.scan_video(os.path.abspath(inputfile), subtitles=True, embedded_subtitles=True)
                subtitles = subliminal.download_best_subtitles([video], languages, hearing_impaired=False, providers=self.subproviders)
                try:
                    subliminal.save_subtitles(video, subtitles[video])
                except:
                    # Support for older versions of subliminal
                    subliminal.save_subtitles(subtitles)
                    self.log.info("Please update to the latest version of subliminal.")
            except Exception as e:
                self.log.info("Unable to download subtitles.", exc_info=True)
                self.log.debug("Unable to download subtitles.", exc_info=True)
        # External subtitle import
开发者ID:phtagn,项目名称:sickbeard_mp4_automator,代码行数:70,代码来源:mkvtomp4.py


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