diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-08-11 19:47:37 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-08-11 19:47:37 -0700 |
commit | 81ff5ab99ca05c4559c604ba7517d17f4bc79ea8 (patch) | |
tree | f096f79bb6fd885f9f600c9cf7b62072fd592553 /youtube | |
parent | 804ed093ee2a18f72b4e393664459a3b74186412 (diff) | |
download | yt-local-81ff5ab99ca05c4559c604ba7517d17f4bc79ea8.tar.lz yt-local-81ff5ab99ca05c4559c604ba7517d17f4bc79ea8.tar.xz yt-local-81ff5ab99ca05c4559c604ba7517d17f4bc79ea8.zip |
extract_channel_info: Improve error extraction
Use extract_str function since it's not always 'simpleText'
Make sure we don't output an empty error message if we don't
know what it is.
channel.py: Don't check if error message is empty, check if it's
None
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/channel.py | 2 | ||||
-rw-r--r-- | youtube/yt_data_extract/everything_else.py | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/youtube/channel.py b/youtube/channel.py index 394ce1b..153760b 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -203,7 +203,7 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None): info = yt_data_extract.extract_channel_info(json.loads(polymer_json), tab) - if info['error']: + if info['error'] is not None: return flask.render_template('error.html', error_message = info['error']) post_process_channel_info(info) diff --git a/youtube/yt_data_extract/everything_else.py b/youtube/yt_data_extract/everything_else.py index ac1ab7d..d1389c6 100644 --- a/youtube/yt_data_extract/everything_else.py +++ b/youtube/yt_data_extract/everything_else.py @@ -21,10 +21,13 @@ def extract_channel_info(polymer_json, tab): # example terminated channel: https://www.youtube.com/channel/UCnKJeK_r90jDdIuzHXC0Org except KeyError: if response.get('alerts'): - return {'error': ' '.join( - deep_get(alert, 'alertRenderer', 'text', 'simpleText', default='') + error_string = ' '.join( + extract_str(deep_get(alert, 'alertRenderer', 'text'), default='') for alert in response['alerts'] - )} + ) + if not error_string: + error_string = 'Failed to extract error' + return {'error': error_string} elif deep_get(response, 'responseContext', 'errors'): for error in response['responseContext']['errors'].get('error', []): if error.get('code') == 'INVALID_VALUE' and error.get('location') == 'browse_id': |