mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-09-27 23:20:23 +09:00
[utils] Fix urlhandle_detect_ext() non-ASCII error in Py2, with test
This commit is contained in:
parent
06d489c522
commit
d87e2ad040
@ -102,6 +102,7 @@ from youtube_dl.utils import (
|
|||||||
url_or_none,
|
url_or_none,
|
||||||
urljoin,
|
urljoin,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
|
urlhandle_detect_ext,
|
||||||
urshift,
|
urshift,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
variadic,
|
variadic,
|
||||||
@ -2039,6 +2040,30 @@ Line 1
|
|||||||
'a', 'b', 'c', 'd',
|
'a', 'b', 'c', 'd',
|
||||||
from_dict={'a': 'c', 'c': [], 'b': 'd', 'd': None}), 'c-d')
|
from_dict={'a': 'c', 'c': [], 'b': 'd', 'd': None}), 'c-d')
|
||||||
|
|
||||||
|
def test_urlhandle_detect_ext(self):
|
||||||
|
|
||||||
|
class UrlHandle(object):
|
||||||
|
_info = {}
|
||||||
|
|
||||||
|
def __init__(self, info):
|
||||||
|
self._info = info
|
||||||
|
|
||||||
|
@property
|
||||||
|
def headers(self):
|
||||||
|
return self._info
|
||||||
|
|
||||||
|
# header with non-ASCII character and contradictory Content-Type
|
||||||
|
urlh = UrlHandle({
|
||||||
|
'Content-Disposition': b'attachment; filename="Epis\xf3dio contains non-ASCI ISO 8859-1 character.mp3"',
|
||||||
|
'Content-Type': b'audio/aac',
|
||||||
|
})
|
||||||
|
self.assertEqual(urlhandle_detect_ext(urlh), 'mp3')
|
||||||
|
# header with no Content-Disposition
|
||||||
|
urlh = UrlHandle({
|
||||||
|
'Content-Type': b'audio/mp3',
|
||||||
|
})
|
||||||
|
self.assertEqual(urlhandle_detect_ext(urlh), 'mp3')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -4743,7 +4743,8 @@ def parse_codecs(codecs_str):
|
|||||||
|
|
||||||
|
|
||||||
def urlhandle_detect_ext(url_handle):
|
def urlhandle_detect_ext(url_handle):
|
||||||
getheader = url_handle.headers.get
|
getheader = lambda x: _decode_compat_str(
|
||||||
|
url_handle.headers.get(x), encoding='iso-8859-1', errors='ignore', or_none=True)
|
||||||
|
|
||||||
cd = getheader('Content-Disposition')
|
cd = getheader('Content-Disposition')
|
||||||
if cd:
|
if cd:
|
||||||
@ -4753,6 +4754,11 @@ def urlhandle_detect_ext(url_handle):
|
|||||||
if e:
|
if e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
# from yt-dlp/2647c933b8: thx bashonly
|
||||||
|
meta_ext = (getheader('x-amz-meta-name') or '').rpartition('.')[2]
|
||||||
|
if meta_ext:
|
||||||
|
return meta_ext
|
||||||
|
|
||||||
return mimetype2ext(getheader('Content-Type'))
|
return mimetype2ext(getheader('Content-Type'))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user