[noco] Extract all variations of audio/subtitles media

pull/5616/head
Sergey M․ 10 years ago
parent f943b7ddce
commit 6568382d6f

@ -103,9 +103,6 @@ class NocoIE(InfoExtractor):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') video_id = mobj.group('id')
options = self._call_api('users/init', None, 'Downloading user options JSON')['options']
audio_lang = options.get('audio_language', 'fr')
medias = self._call_api( medias = self._call_api(
'shows/%s/medias' % video_id, 'shows/%s/medias' % video_id,
video_id, 'Downloading video JSON') video_id, 'Downloading video JSON')
@ -114,12 +111,17 @@ class NocoIE(InfoExtractor):
'shows/by_id/%s' % video_id, 'shows/by_id/%s' % video_id,
video_id, 'Downloading show JSON')[0] video_id, 'Downloading show JSON')[0]
if audio_lang == 'original': options = self._call_api(
audio_lang = show['original_lang'] 'users/init', video_id,
'Downloading user options JSON')['options']
audio_lang_pref = options.get('audio_language') or options.get('language', 'fr')
if audio_lang_pref == 'original':
audio_lang_pref = show['original_lang']
if len(medias) == 1: if len(medias) == 1:
audio_lang = list(medias.keys())[0] audio_lang_pref = list(medias.keys())[0]
elif not audio_lang in medias: elif audio_lang_pref not in medias:
audio_lang = 'fr' audio_lang_pref = 'fr'
qualities = self._call_api( qualities = self._call_api(
'qualities', 'qualities',
@ -127,34 +129,37 @@ class NocoIE(InfoExtractor):
formats = [] formats = []
for lang, lang_dict in medias[audio_lang]['video_list'].items(): for audio_lang, audio_lang_dict in medias.items():
for format_id, fmt in lang_dict['quality_list'].items(): preference = 1 if audio_lang == audio_lang_pref else 0
format_id_extended = '%s-%s' % (lang, format_id) if lang != 'none' else format_id for sub_lang, lang_dict in audio_lang_dict['video_list'].items():
for format_id, fmt in lang_dict['quality_list'].items():
video = self._call_api( format_id_extended = 'audio-%s_sub-%s_%s' % (audio_lang, sub_lang, format_id)
'shows/%s/video/%s/%s' % (video_id, format_id.lower(), audio_lang),
video_id, 'Downloading %s video JSON' % format_id_extended, video = self._call_api(
lang if lang != 'none' else None) 'shows/%s/video/%s/%s' % (video_id, format_id.lower(), audio_lang),
video_id, 'Downloading %s video JSON' % format_id_extended,
file_url = video['file'] sub_lang if sub_lang != 'none' else None)
if not file_url:
continue file_url = video['file']
if not file_url:
if file_url in ['forbidden', 'not found']: continue
popmessage = video['popmessage']
self._raise_error(popmessage['title'], popmessage['message']) if file_url in ['forbidden', 'not found']:
popmessage = video['popmessage']
formats.append({ self._raise_error(popmessage['title'], popmessage['message'])
'url': file_url,
'format_id': format_id_extended, formats.append({
'width': fmt['res_width'], 'url': file_url,
'height': fmt['res_lines'], 'format_id': format_id_extended,
'abr': fmt['audiobitrate'], 'width': fmt['res_width'],
'vbr': fmt['videobitrate'], 'height': fmt['res_lines'],
'filesize': fmt['filesize'], 'abr': fmt['audiobitrate'],
'format_note': qualities[format_id]['quality_name'], 'vbr': fmt['videobitrate'],
'preference': qualities[format_id]['priority'], 'filesize': fmt['filesize'],
}) 'format_note': qualities[format_id]['quality_name'],
'quality': qualities[format_id]['priority'],
'preference': preference,
})
self._sort_formats(formats) self._sort_formats(formats)

Loading…
Cancel
Save