diff options
author | remitamine <remitamine@gmail.com> | 2016-03-16 18:48:06 +0100 |
---|---|---|
committer | Remita Amine <remitamine@gmail.com> | 2016-06-26 14:03:58 +0100 |
commit | 4f3c5e062715bb8c2084bda139ddcd9a2036f267 (patch) | |
tree | 635303c308485ea0ce02113eb6ac0e8cc0c3dc26 /youtube_dl/utils.py | |
parent | 1ac5705f62aa3f6fdb6f2a97fbd24594010b7598 (diff) |
[utils] add helper function for parsing codecs
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 562031fe1..fe175e82c 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -2060,6 +2060,42 @@ def mimetype2ext(mt): }.get(res, res) +def parse_codecs(codecs_str): + # http://tools.ietf.org/html/rfc6381 + if not codecs_str: + return {} + splited_codecs = list(filter(None, map( + lambda str: str.strip(), codecs_str.strip().strip(',').split(',')))) + vcodec, acodec = None, None + for full_codec in splited_codecs: + codec = full_codec.split('.')[0] + if codec in ('avc1', 'avc2', 'avc3', 'avc4', 'vp9', 'vp8', 'hev1', 'hev2', 'h263', 'h264', 'mp4v'): + if not vcodec: + vcodec = full_codec + elif codec in ('mp4a', 'opus', 'vorbis', 'mp3', 'aac'): + if not acodec: + acodec = full_codec + else: + write_string('WARNING: Unknown codec %s' % full_codec, sys.stderr) + if not vcodec and not acodec: + if len(splited_codecs) == 2: + return { + 'vcodec': vcodec, + 'acodec': acodec, + } + elif len(splited_codecs) == 1: + return { + 'vcodec': 'none', + 'acodec': vcodec, + } + else: + return { + 'vcodec': vcodec or 'none', + 'acodec': acodec or 'none', + } + return {} + + def urlhandle_detect_ext(url_handle): getheader = url_handle.headers.get |