diff options
author | Jesús <heckyel@hyperbola.info> | 2021-07-28 23:45:19 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-07-28 23:45:19 -0500 |
commit | f5f9b1c18172327ec310efc9274db30959ba334e (patch) | |
tree | 8a1ba232fef71c76e4c016b7403d9336c3daed3d /youtube | |
parent | d0e3adab0115c547eb58d34337dca7bfce629be2 (diff) | |
download | yt-local-f5f9b1c18172327ec310efc9274db30959ba334e.tar.lz yt-local-f5f9b1c18172327ec310efc9274db30959ba334e.tar.xz yt-local-f5f9b1c18172327ec310efc9274db30959ba334e.zip |
Cleaner channel-checking console error messages when Tor is closed
by James Taylor <user234683@users.noreply.github.com>
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/subscriptions.py | 20 | ||||
-rw-r--r-- | youtube/util.py | 6 |
2 files changed, 17 insertions, 9 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index 503f3fa..afc3df9 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -432,9 +432,8 @@ def autocheck_setting_changed(old_value, new_value): stop_autocheck_system() -settings.add_setting_changed_hook( - 'autocheck_subscriptions', - autocheck_setting_changed) +settings.add_setting_changed_hook('autocheck_subscriptions', + autocheck_setting_changed) if settings.autocheck_subscriptions: start_autocheck_system() # ---------------------------- @@ -455,12 +454,14 @@ def _get_atoma_feed(channel_id): # 404 is expected for terminated channels if e.code in ('404', '429'): return '' + if e.code == '502': + return str(e) raise -def _get_channel_tab(channel_id, channel_status_name): +def _get_channel_videos_first_page(channel_id, channel_status_name): try: - return channel.get_channel_tab(channel_id, print_status=False) + return channel.get_channel_first_page(channel_id=channel_id) except util.FetchError as e: if e.code == '429' and settings.route_tor: error_message = ('Error checking channel ' + channel_status_name @@ -471,6 +472,9 @@ def _get_channel_tab(channel_id, channel_status_name): error_message += ' Exit node IP address: ' + e.ip print(error_message) return None + elif e.code == '502': + print('Error checking channel', channel_status_name + ':', str(e)) + return None raise @@ -484,7 +488,8 @@ def _get_upstream_videos(channel_id): tasks = ( # channel page, need for video duration - gevent.spawn(channel.get_channel_first_page, channel_id=channel_id), + gevent.spawn(_get_channel_videos_first_page, channel_id, + channel_status_name), # need atoma feed for exact published time gevent.spawn(_get_atoma_feed, channel_id) ) @@ -900,8 +905,7 @@ def get_subscriptions_page(): 'muted': muted, }) - return flask.render_template( - 'subscriptions.html', + return flask.render_template('subscriptions.html', header_playlist_names=local_playlist.get_playlist_names(), videos=videos, num_pages=math.ceil(number_of_videos_in_db/60), diff --git a/youtube/util.py b/youtube/util.py index e62d575..daec2df 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -194,7 +194,11 @@ class HTTPAsymmetricCookieProcessor(urllib.request.BaseHandler): class FetchError(Exception): def __init__(self, code, reason='', ip=None, error_message=None): - Exception.__init__(self, 'HTTP error during request: ' + code + ' ' + reason) + if error_message: + string = code + ' ' + reason + ': ' + error_message + else: + string = 'HTTP error during request: ' + code + ' ' + reason + Exception.__init__(self, string) self.code = code self.reason = reason self.ip = ip |