1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-23 00:54:31 +01:00

[arte] Improve language preference (Closes #9401, closes #9162)

This commit is contained in:
Sergey M․ 2016-05-08 06:52:42 +06:00
parent 3e169233da
commit 9c072d38c6
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -161,24 +161,53 @@ class ArteTVPlus7IE(InfoExtractor):
'es': 'E[ESP]', 'es': 'E[ESP]',
} }
langcode = LANGS.get(lang, lang)
formats = [] formats = []
for format_id, format_dict in player_info['VSR'].items(): for format_id, format_dict in player_info['VSR'].items():
f = dict(format_dict) f = dict(format_dict)
versionCode = f.get('versionCode') versionCode = f.get('versionCode')
langcode = LANGS.get(lang, lang) l = re.escape(langcode)
lang_rexs = [r'VO?%s-' % re.escape(langcode), r'VO?.-ST%s$' % re.escape(langcode)]
lang_pref = None # Language preference from most to least priority
if versionCode: # Reference: section 5.6.3 of
matched_lang_rexs = [r for r in lang_rexs if re.match(r, versionCode)] # http://www.arte.tv/sites/en/corporate/files/complete-technical-guidelines-arte-geie-v1-05.pdf
lang_pref = -10 if not matched_lang_rexs else 10 * len(matched_lang_rexs) PREFERENCES = (
source_pref = 0 # original version in requested language, without subtitles
if versionCode is not None: r'VO{0}$'.format(l),
# The original version with subtitles has lower relevance # original version in requested language, with partial subtitles in requested language
if re.match(r'VO-ST(F|A|E)', versionCode): r'VO{0}-ST{0}$'.format(l),
source_pref -= 10 # original version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
# The version with sourds/mal subtitles has also lower relevance r'VO{0}-STM{0}$'.format(l),
elif re.match(r'VO?(F|A|E)-STM\1', versionCode): # non-original (dubbed) version in requested language, without subtitles
source_pref -= 9 r'V{0}$'.format(l),
# non-original (dubbed) version in requested language, with subtitles partial subtitles in requested language
r'V{0}-ST{0}$'.format(l),
# non-original (dubbed) version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
r'V{0}-STM{0}$'.format(l),
# original version in requested language, with partial subtitles in different language
r'VO{0}-ST(?!{0}).+?$'.format(l),
# original version in requested language, with subtitles for the deaf and hard-of-hearing in different language
r'VO{0}-STM(?!{0}).+?$'.format(l),
# original version in different language, with partial subtitles in requested language
r'VO(?:(?!{0}).+?)?-ST{0}$'.format(l),
# original version in different language, with subtitles for the deaf and hard-of-hearing in requested language
r'VO(?:(?!{0}).+?)?-STM{0}$'.format(l),
# original version in different language, without subtitles
r'VO(?:(?!{0}))?$'.format(l),
# original version in different language, with partial subtitles in different language
r'VO(?:(?!{0}).+?)?-ST(?!{0}).+?$'.format(l),
# original version in different language, with subtitles for the deaf and hard-of-hearing in different language
r'VO(?:(?!{0}).+?)?-STM(?!{0}).+?$'.format(l),
)
for pref, p in enumerate(PREFERENCES):
if re.match(p, versionCode):
lang_pref = len(PREFERENCES) - pref
break
else:
lang_pref = -1
format = { format = {
'format_id': format_id, 'format_id': format_id,
'preference': -10 if f.get('videoFormat') == 'M3U8' else None, 'preference': -10 if f.get('videoFormat') == 'M3U8' else None,
@ -188,7 +217,6 @@ class ArteTVPlus7IE(InfoExtractor):
'height': int_or_none(f.get('height')), 'height': int_or_none(f.get('height')),
'tbr': int_or_none(f.get('bitrate')), 'tbr': int_or_none(f.get('bitrate')),
'quality': qfunc(f.get('quality')), 'quality': qfunc(f.get('quality')),
'source_preference': source_pref,
} }
if f.get('mediaType') == 'rtmp': if f.get('mediaType') == 'rtmp':