specify youtube error instead of just 500
This commit is contained in:
parent
80fb2decf5
commit
f12157cd02
@ -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 = {
|
||||
|
@ -49,7 +49,8 @@ from ..utils import (
|
||||
uppercase_escape,
|
||||
urlencode_postdata,
|
||||
)
|
||||
|
||||
class YoutubeError(Exception):
|
||||
pass
|
||||
|
||||
class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
"""Provide base functions for Youtube extractors"""
|
||||
@ -1554,6 +1555,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
r'"sts"\s*:\s*(\d+)', embed_webpage, 'sts', default=''),
|
||||
})
|
||||
video_info_url = proto + '://www.youtube.com/get_video_info?' + data
|
||||
|
||||
video_info_webpage = self._download_webpage(
|
||||
video_info_url, video_id,
|
||||
note='Refetching age-gated info webpage',
|
||||
@ -1646,7 +1648,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
unavailable_message = extract_unavailable_message()
|
||||
if unavailable_message:
|
||||
reason = unavailable_message
|
||||
raise ExtractorError(
|
||||
raise YoutubeError(
|
||||
'YouTube said: %s' % reason,
|
||||
expected=True, video_id=video_id)
|
||||
else:
|
||||
@ -1895,7 +1897,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
if not error_message:
|
||||
error_message = extract_unavailable_message()
|
||||
if error_message:
|
||||
raise ExtractorError(error_message, expected=True)
|
||||
raise YoutubeError(error_message)
|
||||
raise ExtractorError('no conn, hlsvp or url_encoded_fmt_stream_map information found in video info')
|
||||
|
||||
# uploader
|
||||
|
Loading…
x
Reference in New Issue
Block a user