Skip to content

Commit

Permalink
YouTube: Parse error messages, improve downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Sep 23, 2012
1 parent 1c4020a commit 3f67cef
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/gpodder/youtube.py
Expand Up @@ -54,7 +54,7 @@ def get_real_download_url(url, preferred_fmt_id=18):
vid = get_youtube_id(url)
if vid is not None:
page = None
url = 'http://www.youtube.com/get_video_info?&video_id=' + vid
url = 'http://www.youtube.com/get_video_info?&el=detailpage&video_id=' + vid

while page is None:
req = util.http_request(url, method='GET')
Expand All @@ -72,6 +72,10 @@ def find_urls(page):
for fmt_url_encoded in fmt_url_map.split(','):
video_info = parse_qs(fmt_url_encoded)
yield int(video_info['itag'][0]), video_info['url'][0]
else:
error_info = parse_qs(page)
error_message = util.remove_html_tags(error_info['reason'][0])
raise YouTubeError('Cannot download video: %s' % error_message)

fmt_id_url_map = sorted(find_urls(page), reverse=True)
# Default to the highest fmt_id if we don't find a match below
Expand Down

0 comments on commit 3f67cef

Please sign in to comment.