diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-12-20 01:04:43 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-12-20 01:04:43 -0800 |
commit | 9d1c688310849f897c5fc7b3f37ab3ddeac67a9b (patch) | |
tree | f2825481a3f912b84a01b19b89433aefa355d0e2 | |
parent | 4a8bfac2256f3e4abf4513b4b2527eeb36f6dd1f (diff) | |
download | yt-local-9d1c688310849f897c5fc7b3f37ab3ddeac67a9b.tar.lz yt-local-9d1c688310849f897c5fc7b3f37ab3ddeac67a9b.tar.xz yt-local-9d1c688310849f897c5fc7b3f37ab3ddeac67a9b.zip |
Correctly handle case where channel was terminated
-rw-r--r-- | youtube/channel.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/youtube/channel.py b/youtube/channel.py index c712ecf..8c44700 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -181,13 +181,25 @@ def channel_sort_buttons_html(channel_id, tab, current_sort): return result def channel_videos_html(polymer_json, current_page=1, current_sort=3, number_of_videos = 1000, current_query_string=''): - microformat = polymer_json[1]['response']['microformat']['microformatDataRenderer'] + response = polymer_json[1]['response'] + try: + microformat = response['microformat']['microformatDataRenderer'] + + # channel doesn't exist or was terminated + # example terminated channel: https://www.youtube.com/channel/UCnKJeK_r90jDdIuzHXC0Org + except KeyError: + if 'alerts' in response and len(response['alerts']) > 0: + result = '' + for alert in response['alerts']: + result += alert['alertRenderer']['text']['simpleText'] + '\n' + return result + else: + raise channel_url = microformat['urlCanonical'].rstrip('/') channel_id = channel_url[channel_url.rfind('/')+1:] try: - items = polymer_json[1]['response']['continuationContents']['gridContinuation']['items'] + items = response['continuationContents']['gridContinuation']['items'] except KeyError: - response = polymer_json[1]['response'] try: contents = response['contents'] except KeyError: |