本文整理汇总了Python中babelfish.Language.fromcode方法的典型用法代码示例。如果您正苦于以下问题:Python Language.fromcode方法的具体用法?Python Language.fromcode怎么用?Python Language.fromcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babelfish.Language
的用法示例。
在下文中一共展示了Language.fromcode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_converter_opensubtitles
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def test_converter_opensubtitles(self):
self.assertEqual(Language('fra').opensubtitles, Language('fra').alpha3b)
self.assertEqual(Language('por', 'BR').opensubtitles, 'pob')
self.assertEqual(Language.fromopensubtitles('fre'), Language('fra'))
self.assertEqual(Language.fromopensubtitles('pob'), Language('por', 'BR'))
self.assertEqual(Language.fromopensubtitles('pb'), Language('por', 'BR'))
# Montenegrin is not recognized as an ISO language (yet?) but for now it is
# unofficially accepted as Serbian from Montenegro
self.assertEqual(Language.fromopensubtitles('mne'), Language('srp', 'ME'))
self.assertEqual(Language.fromcode('pob', 'opensubtitles'), Language('por', 'BR'))
self.assertRaises(LanguageReverseError, lambda: Language.fromopensubtitles('zzz'))
self.assertRaises(LanguageConvertError, lambda: Language('aaa').opensubtitles)
self.assertEqual(len(language_converters['opensubtitles'].codes), 607)
# test with all the LANGUAGES from the opensubtitles api
# downloaded from: http://www.opensubtitles.org/addons/export_languages.php
f = resource_stream('babelfish', 'data/opensubtitles_languages.txt')
f.readline()
for l in f:
idlang, alpha2, _, upload_enabled, web_enabled = l.decode('utf-8').strip().split('\t')
if not int(upload_enabled) and not int(web_enabled):
# do not test LANGUAGES that are too esoteric / not widely available
continue
self.assertEqual(Language.fromopensubtitles(idlang).opensubtitles, idlang)
if alpha2:
self.assertEqual(Language.fromopensubtitles(idlang), Language.fromopensubtitles(alpha2))
f.close()
示例2: test_converter_alpha3t
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [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)
示例3: test_converter_name
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def test_converter_name(self):
self.assertEqual(Language('eng').name, 'English')
self.assertEqual(Language.fromname('English'), Language('eng'))
self.assertEqual(Language.fromcode('English', 'name'), Language('eng'))
with self.assertRaises(LanguageReverseError):
Language.fromname('Zzzzzzzzz')
self.assertEqual(len(get_language_converter('name').codes), 7874)
示例4: test_converter_alpha2
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def test_converter_alpha2(self):
self.assertEqual(Language('eng').alpha2, 'en')
self.assertEqual(Language.fromalpha2('en'), Language('eng'))
self.assertEqual(Language.fromcode('en', 'alpha2'), Language('eng'))
self.assertRaises(LanguageReverseError, lambda: Language.fromalpha2('zz'))
self.assertRaises(LanguageConvertError, lambda: Language('aaa').alpha2)
self.assertEqual(len(language_converters['alpha2'].codes), 184)
示例5: test_converter_alpha3t
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [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)
示例6: test_converter_alpha2
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def test_converter_alpha2(self):
self.assertEqual(Language('eng').alpha2, 'en')
self.assertEqual(Language.fromalpha2('en'), Language('eng'))
self.assertEqual(Language.fromcode('en', 'alpha2'), Language('eng'))
with self.assertRaises(LanguageReverseError):
Language.fromalpha2('zz')
with self.assertRaises(LanguageConvertError):
Language('aaa').alpha2
self.assertEqual(len(get_language_converter('alpha2').codes), 184)
示例7: from_english
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def from_english(self, language):
if language in EXCEPTIONS:
return Language.fromietf(EXCEPTIONS[language])
language_match = re.search('(\w[\w\s]*\w)', language)
if not language_match:
return
language_english = language_match.group(1)
language_alpha3 = xbmc.convertLanguage(language_english, format=xbmc.ISO_639_2)
if not language_alpha3:
return
result = Language.fromcode(language_alpha3, 'alpha3b')
result.country = self.get_country(language)
return result
示例8: test_converter_name
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def test_converter_name(self):
self.assertEqual(Language('eng').name, 'English')
self.assertEqual(Language.fromname('English'), Language('eng'))
self.assertEqual(Language.fromcode('English', 'name'), Language('eng'))
self.assertRaises(LanguageReverseError, lambda: Language.fromname('Zzzzzzzzz'))
self.assertEqual(len(language_converters['name'].codes), 7874)
示例9: subtitles_download_in_pp
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def subtitles_download_in_pp(): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)
providers = enabled_service_list()
pool = SubtitleProviderPool()
# Search for all wanted languages
languages = {from_code(language) for language in wanted_languages()}
if not languages:
return
# Dict of language exceptions to use with subliminal
language_exceptions = {'pt-br': 'pob'}
run_post_process = False
# Check if PP folder is set
if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):
for dirpath, dirnames_, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
rar_files = [rar_file for rar_file in files if isRarFile(rar_file)]
if rar_files and sickbeard.UNPACK:
video_files = [video_file for video_file in files if isMediaFile(video_file)]
if u'_UNPACK' not in dirpath and (not video_files or dirpath == sickbeard.TV_DOWNLOAD_DIR):
logger.log(u'Found rar files in post-process folder: {0}'.format(rar_files), logger.DEBUG)
result = processTV.ProcessResult()
processTV.unRAR(dirpath, rar_files, False, result)
elif rar_files and not sickbeard.UNPACK:
logger.log(u'Unpack is disabled. Skipping: {0}'.format(rar_files), logger.WARNING)
for dirpath, dirnames_, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
for filename in sorted(files):
try:
# Remove non release groups from video file. Needed to match subtitles
new_filename = remove_non_release_groups(filename)
if new_filename != filename:
os.rename(filename, new_filename)
filename = new_filename
except Exception as error:
logger.log(u"Couldn't remove non release groups from video file. Error: {0}".format
(ex(error)), logger.DEBUG)
# Delete unwanted subtitles before downloading new ones
if sickbeard.SUBTITLES_MULTI and sickbeard.SUBTITLES_KEEP_ONLY_WANTED and filename.rpartition('.')[2] in subtitle_extensions:
subtitle_language = filename.rsplit('.', 2)[1].lower()
if len(subtitle_language) == 2 and subtitle_language in language_converters['opensubtitles'].codes:
subtitle_language = Language.fromcode(subtitle_language, 'alpha2').opensubtitles
elif subtitle_language in language_exceptions:
subtitle_language = language_exceptions.get(subtitle_language, subtitle_language)
elif subtitle_language not in language_converters['opensubtitles'].codes:
subtitle_language = 'unknown'
if subtitle_language not in sickbeard.SUBTITLES_LANGUAGES:
try:
os.remove(os.path.join(dirpath, filename))
logger.log(u"Deleted '{0}' because we don't want subtitle language '{1}'. We only want '{2}' language(s)".format
(filename, subtitle_language, ','.join(sickbeard.SUBTITLES_LANGUAGES)), logger.DEBUG)
except Exception as error:
logger.log(u"Couldn't delete subtitle: {0}. Error: {1}".format(filename, ex(error)), logger.DEBUG)
if isMediaFile(filename) and processTV.subtitles_enabled(filename):
try:
video = get_video(os.path.join(dirpath, filename), subtitles=False, embedded_subtitles=False)
subtitles_list = pool.list_subtitles(video, languages)
for provider in providers:
if provider in pool.discarded_providers:
logger.log(u'Could not search in {0} provider. Discarding for now'.format(provider), logger.DEBUG)
if not subtitles_list:
logger.log(u'No subtitles found for {0}'.format
(os.path.join(dirpath, filename)), logger.DEBUG)
continue
logger.log(u'Found subtitle(s) canditate(s) for {0}'.format(filename), logger.INFO)
hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 198
found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
hearing_impaired=hearing_impaired,
min_score=user_score,
only_one=not sickbeard.SUBTITLES_MULTI)
for subtitle in subtitles_list:
score = subliminal.score.compute_score(subtitle, video, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED)
logger.log(u'[{0}] Subtitle score for {1} is: {2} (min={3})'.format
(subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)
downloaded_languages = set()
for subtitle in found_subtitles:
logger.log(u'Found subtitle for {0} in {1} provider with language {2}'.format
(os.path.join(dirpath, filename), subtitle.provider_name,
subtitle.language.opensubtitles), logger.INFO)
subliminal.save_subtitles(video, found_subtitles, directory=dirpath,
single=not sickbeard.SUBTITLES_MULTI)
subtitles_multi = not sickbeard.SUBTITLES_MULTI
subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
None if subtitles_multi else
subtitle.language)
if dirpath is not None:
subtitle_path = os.path.join(dirpath, os.path.split(subtitle_path)[1])
sickbeard.helpers.chmodAsParent(subtitle_path)
#.........这里部分代码省略.........
示例10: fromcode
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromcode [as 别名]
def fromcode(cls, code, converter):
return Language(*Language_.fromcode(code, converter).__getstate__())