From 5c4c21bfd33bdf06a49f1d43c60cbb845593f756 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 4 Jul 2018 21:56:53 -0700 Subject: fix exception when channel has no videos --- youtube/channel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'youtube') diff --git a/youtube/channel.py b/youtube/channel.py index 205d61f..3cec09d 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -137,7 +137,11 @@ def get_number_of_videos(channel_id): f.write(response)''' response = response.decode('utf-8') print("Got response for number of videos") - return int(re.search(r'"num_videos_text":\s*{(?:"item_type":\s*"formatted_string",)?\s*"runs":\s*\[{"text":\s*"([\d,]*) videos"', response).group(1).replace(',','')) + match = re.search(r'"num_videos_text":\s*{(?:"item_type":\s*"formatted_string",)?\s*"runs":\s*\[{"text":\s*"([\d,]*) videos"', response) + if match: + return int(match.group(1).replace(',','')) + else: + return 0 @functools.lru_cache(maxsize=128) def get_channel_id(username): -- cgit v1.2.3