diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-02-16 14:11:38 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-02-16 14:11:38 -0800 |
commit | 7f9e91da7ac895ed6952e8fb9e7137f23a2250e2 (patch) | |
tree | e338834321d9e4b07278b39379c2ef305d1b2ebe | |
parent | 0cb61ef4b60e8b32b4242f0f300558c5f12f9413 (diff) | |
download | yt-local-7f9e91da7ac895ed6952e8fb9e7137f23a2250e2.tar.lz yt-local-7f9e91da7ac895ed6952e8fb9e7137f23a2250e2.tar.xz yt-local-7f9e91da7ac895ed6952e8fb9e7137f23a2250e2.zip |
channel: Don't completely fail if can't retrieve # of vids
-rw-r--r-- | youtube/channel.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/youtube/channel.py b/youtube/channel.py index 0dafde5..9577525 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -107,7 +107,16 @@ def get_number_of_videos(channel_id): playlist_id = 'UU' + channel_id[2:] url = 'https://m.youtube.com/playlist?list=' + playlist_id + '&pbj=1' print("Getting number of videos") - response = common.fetch_url(url, common.mobile_ua + headers_pbj) + + # Sometimes retrieving playlist info fails with 403 for no discernable reason + try: + response = common.fetch_url(url, common.mobile_ua + headers_pbj) + except urllib.error.HTTPError as e: + if e.code != 403: + raise + print("Couldn't retrieve number of videos") + return 1000 + '''with open('debug/playlist_debug_metadata', 'wb') as f: f.write(response)''' response = response.decode('utf-8') |