YouTube: fix #252

This commit is contained in:
Mort Yao 2013-10-18 14:49:29 +02:00
parent 51c56e540a
commit bf5d2dfbce
3 changed files with 8 additions and 2 deletions

View File

@ -85,7 +85,10 @@ def parse_query_param(url, param):
The value of the parameter.
"""
try:
return parse.parse_qs(parse.urlparse(url).query)[param][0]
except:
return None
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)

View File

@ -107,7 +107,9 @@ def youtube_download(url, output_dir='.', merge=True, info_only=False):
"""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
youtube_download_by_id(id, title=None, output_dir=output_dir, merge=merge, info_only=info_only)

View File

@ -38,4 +38,5 @@ class YouGetTests(unittest.TestCase):
test_urls([
"http://www.youtube.com/watch?v=pzKerr0JIPA",
"http://youtu.be/pzKerr0JIPA",
"http://www.youtube.com/attribution_link?u=/watch?v%3DldAKIzq7bvs%26feature%3Dshare"
])