From 7f9e91da7ac895ed6952e8fb9e7137f23a2250e2 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 16 Feb 2019 14:11:38 -0800 Subject: channel: Don't completely fail if can't retrieve # of vids --- youtube/channel.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'youtube/channel.py') 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') -- cgit v1.2.3