diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-07-20 00:44:18 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-07-20 00:44:18 -0700 |
commit | f12157cd0203d61bd5ee4f6142562da17f3109a7 (patch) | |
tree | 95cc2cd2dd5582ace68538fbed71200e9d08c618 /youtube | |
parent | 80fb2decf50f353a1988feeafcde7d47894ddbfb (diff) | |
download | yt-local-f12157cd0203d61bd5ee4f6142562da17f3109a7.tar.lz yt-local-f12157cd0203d61bd5ee4f6142562da17f3109a7.tar.xz yt-local-f12157cd0203d61bd5ee4f6142562da17f3109a7.zip |
specify youtube error instead of just 500
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/watch.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/youtube/watch.py b/youtube/watch.py index 94e1e78..c669f5e 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -1,4 +1,5 @@ from youtube_dl.YoutubeDL import YoutubeDL +from youtube_dl.extractor.youtube import YoutubeError import json import urllib from string import Template @@ -289,12 +290,18 @@ more_comments_template = Template('''<a class="page-button more-comments" href=" download_link_template = Template(''' <a href="$url"> <span>$ext</span> <span>$resolution</span> <span>$note</span></a>''') +def extract_info(downloader, *args, **kwargs): + try: + return downloader.extract_info(*args, **kwargs) + except YoutubeError as e: + return str(e) + def get_watch_page(query_string): id = urllib.parse.parse_qs(query_string)['v'][0] downloader = YoutubeDL(params={'youtube_include_dash_manifest':False}) tasks = ( gevent.spawn(comments.video_comments, id ), - gevent.spawn(downloader.extract_info, "https://www.youtube.com/watch?v=" + id, download=False) + gevent.spawn(extract_info, downloader, "https://www.youtube.com/watch?v=" + id, download=False) ) gevent.joinall(tasks) comments_info, info = tasks[0].value, tasks[1].value @@ -308,6 +315,15 @@ def get_watch_page(query_string): #info = YoutubeDL().extract_info(url, download=False) #chosen_format = choose_format(info) + + if isinstance(info, str): # youtube error + return common.yt_basic_template.substitute( + page_title = "Error", + style = "", + header = common.get_header(), + page = html.escape(info), + ) + sorted_formats = sort_formats(info) video_info = { |