Extraction: Proper error handling for terminated or non-existant channels
This commit is contained in:
parent
bd343ed71f
commit
216231f9a6
@ -186,6 +186,8 @@ def get_channel_page(channel_id, tab='videos'):
|
|||||||
|
|
||||||
|
|
||||||
info = yt_data_extract.extract_channel_info(json.loads(polymer_json), tab)
|
info = yt_data_extract.extract_channel_info(json.loads(polymer_json), tab)
|
||||||
|
if info['errors']:
|
||||||
|
return flask.render_template('error.html', error_message = '\n'.join(info['errors']))
|
||||||
post_process_channel_info(info)
|
post_process_channel_info(info)
|
||||||
if tab in ('videos', 'search'):
|
if tab in ('videos', 'search'):
|
||||||
info['number_of_videos'] = number_of_videos
|
info['number_of_videos'] = number_of_videos
|
||||||
@ -226,6 +228,9 @@ def get_channel_page_general_url(base_url, tab, request):
|
|||||||
|
|
||||||
|
|
||||||
info = yt_data_extract.extract_channel_info(json.loads(polymer_json), tab)
|
info = yt_data_extract.extract_channel_info(json.loads(polymer_json), tab)
|
||||||
|
if info['errors']:
|
||||||
|
return flask.render_template('error.html', error_message = '\n'.join(info['errors']))
|
||||||
|
|
||||||
post_process_channel_info(info)
|
post_process_channel_info(info)
|
||||||
if tab in ('videos', 'search'):
|
if tab in ('videos', 'search'):
|
||||||
info['number_of_videos'] = 1000
|
info['number_of_videos'] = 1000
|
||||||
|
@ -455,7 +455,12 @@ def _get_upstream_videos(channel_id):
|
|||||||
print('Failed to read atoma feed for ' + channel_status_name)
|
print('Failed to read atoma feed for ' + channel_status_name)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
videos = yt_data_extract.extract_channel_info(json.loads(channel_tab), 'videos')['items']
|
channel_info = yt_data_extract.extract_channel_info(json.loads(channel_tab), 'videos')
|
||||||
|
if channel_info['errors']:
|
||||||
|
print('Error checking channel ' + channel_status_name + ': ' + ', '.join(channel_info['errors']))
|
||||||
|
return
|
||||||
|
|
||||||
|
videos = channel_info['items']
|
||||||
for i, video_item in enumerate(videos):
|
for i, video_item in enumerate(videos):
|
||||||
if 'description' not in video_item:
|
if 'description' not in video_item:
|
||||||
video_item['description'] = ''
|
video_item['description'] = ''
|
||||||
|
@ -281,6 +281,7 @@ def parse_info_prepare_for_html(renderer, additional_info={}):
|
|||||||
|
|
||||||
|
|
||||||
def extract_channel_info(polymer_json, tab):
|
def extract_channel_info(polymer_json, tab):
|
||||||
|
info = {'errors': []}
|
||||||
response = polymer_json[1]['response']
|
response = polymer_json[1]['response']
|
||||||
try:
|
try:
|
||||||
microformat = response['microformat']['microformatDataRenderer']
|
microformat = response['microformat']['microformatDataRenderer']
|
||||||
@ -289,18 +290,18 @@ def extract_channel_info(polymer_json, tab):
|
|||||||
# example terminated channel: https://www.youtube.com/channel/UCnKJeK_r90jDdIuzHXC0Org
|
# example terminated channel: https://www.youtube.com/channel/UCnKJeK_r90jDdIuzHXC0Org
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if 'alerts' in response and len(response['alerts']) > 0:
|
if 'alerts' in response and len(response['alerts']) > 0:
|
||||||
result = ''
|
|
||||||
for alert in response['alerts']:
|
for alert in response['alerts']:
|
||||||
result += alert['alertRenderer']['text']['simpleText'] + '\n'
|
info['errors'].append(alert['alertRenderer']['text']['simpleText'])
|
||||||
flask.abort(200, result)
|
return info
|
||||||
elif 'errors' in response['responseContext']:
|
elif 'errors' in response['responseContext']:
|
||||||
for error in response['responseContext']['errors']['error']:
|
for error in response['responseContext']['errors']['error']:
|
||||||
if error['code'] == 'INVALID_VALUE' and error['location'] == 'browse_id':
|
if error['code'] == 'INVALID_VALUE' and error['location'] == 'browse_id':
|
||||||
flask.abort(404, 'This channel does not exist')
|
info['errors'].append('This channel does not exist')
|
||||||
raise
|
return info
|
||||||
|
info['errors'].append('Failure getting microformat')
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
info = {}
|
|
||||||
info['current_tab'] = tab
|
info['current_tab'] = tab
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user