diff --git a/src/you_get/common.py b/src/you_get/common.py index b78ae0e3..ceb07646 100644 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -85,7 +85,10 @@ def parse_query_param(url, param): 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): 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) diff --git a/src/you_get/extractor/youtube.py b/src/you_get/extractor/youtube.py index 1b766cc2..96f6987b 100644 --- a/src/you_get/extractor/youtube.py +++ b/src/you_get/extractor/youtube.py @@ -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) diff --git a/tests/test.py b/tests/test.py index 452fbcd8..9ecf4d68 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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" ])