mirror of
https://github.com/soimort/you-get.git
synced 2025-03-15 04:13:58 +03:00
YouTube: fix #252
This commit is contained in:
parent
51c56e540a
commit
bf5d2dfbce
@ -85,7 +85,10 @@ def parse_query_param(url, param):
|
|||||||
The value of the parameter.
|
The value of the parameter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return parse.parse_qs(parse.urlparse(url).query)[param][0]
|
try:
|
||||||
|
return parse.parse_qs(parse.urlparse(url).query)[param][0]
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def unicodize(text):
|
def unicodize(text):
|
||||||
return re.sub(r'\\u([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])', lambda x: chr(int(x.group(0)[2:], 16)), text)
|
return re.sub(r'\\u([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])', lambda x: chr(int(x.group(0)[2:], 16)), text)
|
||||||
|
@ -107,7 +107,9 @@ def youtube_download(url, output_dir='.', merge=True, info_only=False):
|
|||||||
"""Downloads YouTube videos by URL.
|
"""Downloads YouTube videos by URL.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id = match1(url, r'youtu.be/([^/]+)') or parse_query_param(url, 'v')
|
id = match1(url, r'youtu.be/([^/]+)') or \
|
||||||
|
parse_query_param(url, 'v') or \
|
||||||
|
parse_query_param(parse_query_param(url, 'u'), 'v')
|
||||||
assert id
|
assert id
|
||||||
|
|
||||||
youtube_download_by_id(id, title=None, output_dir=output_dir, merge=merge, info_only=info_only)
|
youtube_download_by_id(id, title=None, output_dir=output_dir, merge=merge, info_only=info_only)
|
||||||
|
@ -38,4 +38,5 @@ class YouGetTests(unittest.TestCase):
|
|||||||
test_urls([
|
test_urls([
|
||||||
"http://www.youtube.com/watch?v=pzKerr0JIPA",
|
"http://www.youtube.com/watch?v=pzKerr0JIPA",
|
||||||
"http://youtu.be/pzKerr0JIPA",
|
"http://youtu.be/pzKerr0JIPA",
|
||||||
|
"http://www.youtube.com/attribution_link?u=/watch?v%3DldAKIzq7bvs%26feature%3Dshare"
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user