[udemy] Extract formats from outputs

This commit is contained in:
Sergey M․ 2016-03-25 02:27:13 +06:00
parent ff9d5d0938
commit f0e83681d9

View File

@ -180,39 +180,57 @@ class UdemyIE(InfoExtractor):
video_id = asset['id'] video_id = asset['id']
thumbnail = asset.get('thumbnailUrl') or asset.get('thumbnail_url') thumbnail = asset.get('thumbnailUrl') or asset.get('thumbnail_url')
duration = float_or_none(asset.get('data', {}).get('duration')) duration = float_or_none(asset.get('data', {}).get('duration'))
outputs = asset.get('data', {}).get('outputs', {})
formats = [] formats = []
for format_ in asset.get('download_urls', {}).get('Video', []):
video_url = format_.get('file') def extract_output_format(src):
if not video_url: return {
continue 'url': src['url'],
format_id = format_.get('label') 'format_id': '%sp' % (src.get('label') or format_id),
f = { 'width': int_or_none(src.get('width')),
'url': format_['file'], 'height': int_or_none(src.get('height')),
'height': int_or_none(format_id), 'vbr': int_or_none(src.get('video_bitrate_in_kbps')),
'vcodec': src.get('video_codec'),
'fps': int_or_none(src.get('frame_rate')),
'abr': int_or_none(src.get('audio_bitrate_in_kbps')),
'acodec': src.get('audio_codec'),
'asr': int_or_none(src.get('audio_sample_rate')),
'tbr': int_or_none(src.get('total_bitrate_in_kbps')),
'filesize': int_or_none(src.get('file_size_in_bytes')),
} }
if format_id:
# Some videos contain additional metadata (e.g. outputs = asset.get('data', {}).get('outputs')
# https://www.udemy.com/ios9-swift/learn/#/lecture/3383208) if not isinstance(outputs, dict):
output = outputs.get(format_id) outputs = {}
if isinstance(output, dict):
f.update({ for format_id, output in outputs.items():
'format_id': '%sp' % (output.get('label') or format_id), if isinstance(output, dict) and output.get('url'):
'width': int_or_none(output.get('width')), formats.append(extract_output_format(output))
'height': int_or_none(output.get('height')),
'vbr': int_or_none(output.get('video_bitrate_in_kbps')), download_urls = asset.get('download_urls')
'vcodec': output.get('video_codec'), if isinstance(download_urls, dict):
'fps': int_or_none(output.get('frame_rate')), video = download_urls.get('Video')
'abr': int_or_none(output.get('audio_bitrate_in_kbps')), if isinstance(video, list):
'acodec': output.get('audio_codec'), for format_ in video:
'asr': int_or_none(output.get('audio_sample_rate')), video_url = format_.get('file')
'tbr': int_or_none(output.get('total_bitrate_in_kbps')), if not video_url:
'filesize': int_or_none(output.get('file_size_in_bytes')), continue
}) format_id = format_.get('label')
else: f = {
f['format_id'] = '%sp' % format_id 'url': format_['file'],
formats.append(f) 'height': int_or_none(format_id),
}
if format_id:
# Some videos contain additional metadata (e.g.
# https://www.udemy.com/ios9-swift/learn/#/lecture/3383208)
output = outputs.get(format_id)
if isinstance(output, dict):
output_format = extract_output_format(output)
output_format.update(f)
f = output_format
else:
f['format_id'] = '%sp' % format_id
formats.append(f)
self._sort_formats(formats) self._sort_formats(formats)