YouTube: Better error message for protected videos

YouTube protects pages that contain violence, etc.. by
requiring users to login to prove they are over 18. We
can't determine the fmt_url_map in that case, so this
patch adds a better error message to the failed download.
This commit is contained in:
Thomas Perl 2010-12-18 14:32:33 +01:00
parent bbd5720775
commit 8f167f89a0
1 changed files with 7 additions and 1 deletions

View File

@ -41,6 +41,8 @@ supported_formats = [
(5, '5/320x240/7/0/0', '320x240 (FLV)'),
]
class YouTubeError(Exception): pass
def get_real_download_url(url, preferred_fmt_id=18):
vid = get_youtube_id(url)
if vid is not None:
@ -68,7 +70,11 @@ def get_real_download_url(url, preferred_fmt_id=18):
fmt_id_url_map = sorted(find_urls(page), reverse=True)
# Default to the highest fmt_id if we don't find a match below
default_fmt_id, default_url = fmt_id_url_map[0]
if fmt_id_url_map:
default_fmt_id, default_url = fmt_id_url_map[0]
else:
raise YouTubeError('fmt_url_map not found for video ID "%s"' % vid)
formats_available = set(fmt_id for fmt_id, url in fmt_id_url_map)
fmt_id_url_map = dict(fmt_id_url_map)