diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-07-04 21:56:53 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-07-04 21:56:53 -0700 |
commit | 5c4c21bfd33bdf06a49f1d43c60cbb845593f756 (patch) | |
tree | c79ec27245e3b15f5b4f337d0ba8e5ff1b4c20bf | |
parent | dcdf02737a7e44dff238b5ad8c23ee422c270d7a (diff) | |
download | yt-local-5c4c21bfd33bdf06a49f1d43c60cbb845593f756.tar.lz yt-local-5c4c21bfd33bdf06a49f1d43c60cbb845593f756.tar.xz yt-local-5c4c21bfd33bdf06a49f1d43c60cbb845593f756.zip |
fix exception when channel has no videos
-rw-r--r-- | youtube/channel.py | 6 |
1 files changed, 5 insertions, 1 deletions
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): |