diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-09-08 17:48:02 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-09-08 17:48:02 -0700 |
commit | 216231f9a6ca9ed48389e797a0c30d7d3b01e379 (patch) | |
tree | 1fed2d2b6b4cce1db21f7a27809282b4ac95e4a1 /youtube/yt_data_extract.py | |
parent | bd343ed71f628e0f1dd1eb3f45fb4e04887f223f (diff) | |
download | yt-local-216231f9a6ca9ed48389e797a0c30d7d3b01e379.tar.lz yt-local-216231f9a6ca9ed48389e797a0c30d7d3b01e379.tar.xz yt-local-216231f9a6ca9ed48389e797a0c30d7d3b01e379.zip |
Extraction: Proper error handling for terminated or non-existant channels
Diffstat (limited to 'youtube/yt_data_extract.py')
-rw-r--r-- | youtube/yt_data_extract.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/youtube/yt_data_extract.py b/youtube/yt_data_extract.py index c666ede..f0c89cb 100644 --- a/youtube/yt_data_extract.py +++ b/youtube/yt_data_extract.py @@ -281,6 +281,7 @@ def parse_info_prepare_for_html(renderer, additional_info={}): def extract_channel_info(polymer_json, tab): + info = {'errors': []} response = polymer_json[1]['response'] try: 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 except KeyError: if 'alerts' in response and len(response['alerts']) > 0: - result = '' for alert in response['alerts']: - result += alert['alertRenderer']['text']['simpleText'] + '\n' - flask.abort(200, result) + info['errors'].append(alert['alertRenderer']['text']['simpleText']) + return info elif 'errors' in response['responseContext']: for error in response['responseContext']['errors']['error']: if error['code'] == 'INVALID_VALUE' and error['location'] == 'browse_id': - flask.abort(404, 'This channel does not exist') - raise + info['errors'].append('This channel does not exist') + return info + info['errors'].append('Failure getting microformat') + return info - info = {} info['current_tab'] = tab |