From 19a17d462388b5d10196352e5f9d1491d608783a Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sat, 5 Mar 2016 18:18:28 +0800 Subject: [PATCH 1/3] [utils] Add codec2ext --- youtube_dl/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 22a39a0ab7..dc0bf5627a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1893,6 +1893,19 @@ def mimetype2ext(mt): }.get(res, res) +def codec2ext(codec): + codec_type = codec.split('.')[0] + + # Leave the return value None for unknown values as codec_type + # is not a good fallback for file extensions + return { + 'avc1': 'mp4', + 'mp4a': 'm4a', + 'vorbis': 'webm', + 'vp9': 'webm', + }.get(codec_type) + + def urlhandle_detect_ext(url_handle): try: url_handle.headers From 2def60c5f3426e4f6b7e5f0bc8a92811e5a592b9 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sat, 5 Mar 2016 18:18:39 +0800 Subject: [PATCH 2/3] [common] Use codec2ext for DASH formats (#8764) --- youtube_dl/extractor/common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 07bd2cbe2f..f337caf20e 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -29,6 +29,7 @@ from ..utils import ( age_restricted, bug_reports_message, clean_html, + codec2ext, compiled_regex_type, determine_ext, error_to_compat_str, @@ -1471,6 +1472,7 @@ class InfoExtractor(object): f = { 'format_id': '%s-%s' % (mpd_id, representation_id) if mpd_id else representation_id, 'url': base_url, + 'ext': codec2ext(representation_attrib.get('codecs')), 'width': int_or_none(representation_attrib.get('width')), 'height': int_or_none(representation_attrib.get('height')), 'tbr': int_or_none(representation_attrib.get('bandwidth'), 1000), From 6d210f20905a5c31f72eff16f9f4dbbed7f52c70 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sun, 6 Mar 2016 13:32:03 +0800 Subject: [PATCH 3/3] [utils] Add more codecs to codec2ext BBC uses avc3. Here's an example (thanks to @remitamine for this example) http://rdmedia.bbc.co.uk/dash/ondemand/bbb/2/client_manifest-common_init.mpd See also https://trac.ffmpeg.org/ticket/5217 --- youtube_dl/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index dc0bf5627a..0e04e91a42 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1900,6 +1900,9 @@ def codec2ext(codec): # is not a good fallback for file extensions return { 'avc1': 'mp4', + 'avc2': 'mp4', + 'avc3': 'mp4', + 'avc4': 'mp4', 'mp4a': 'm4a', 'vorbis': 'webm', 'vp9': 'webm',