1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-15 19:43:30 +01:00

[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,10 +180,38 @@ 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', []):
def extract_output_format(src):
return {
'url': src['url'],
'format_id': '%sp' % (src.get('label') or format_id),
'width': int_or_none(src.get('width')),
'height': int_or_none(src.get('height')),
'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')),
}
outputs = asset.get('data', {}).get('outputs')
if not isinstance(outputs, dict):
outputs = {}
for format_id, output in outputs.items():
if isinstance(output, dict) and output.get('url'):
formats.append(extract_output_format(output))
download_urls = asset.get('download_urls')
if isinstance(download_urls, dict):
video = download_urls.get('Video')
if isinstance(video, list):
for format_ in video:
video_url = format_.get('file') video_url = format_.get('file')
if not video_url: if not video_url:
continue continue
@ -197,19 +225,9 @@ class UdemyIE(InfoExtractor):
# https://www.udemy.com/ios9-swift/learn/#/lecture/3383208) # https://www.udemy.com/ios9-swift/learn/#/lecture/3383208)
output = outputs.get(format_id) output = outputs.get(format_id)
if isinstance(output, dict): if isinstance(output, dict):
f.update({ output_format = extract_output_format(output)
'format_id': '%sp' % (output.get('label') or format_id), output_format.update(f)
'width': int_or_none(output.get('width')), f = output_format
'height': int_or_none(output.get('height')),
'vbr': int_or_none(output.get('video_bitrate_in_kbps')),
'vcodec': output.get('video_codec'),
'fps': int_or_none(output.get('frame_rate')),
'abr': int_or_none(output.get('audio_bitrate_in_kbps')),
'acodec': output.get('audio_codec'),
'asr': int_or_none(output.get('audio_sample_rate')),
'tbr': int_or_none(output.get('total_bitrate_in_kbps')),
'filesize': int_or_none(output.get('file_size_in_bytes')),
})
else: else:
f['format_id'] = '%sp' % format_id f['format_id'] = '%sp' % format_id
formats.append(f) formats.append(f)