aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-07-03 18:06:53 -0700
committerJames Taylor <user234683@users.noreply.github.com>2018-07-03 18:06:53 -0700
commitdcdf02737a7e44dff238b5ad8c23ee422c270d7a (patch)
treec0a1ca3cf20f1572e051c14f1125ff480f2334f7 /youtube
parentc6dad90d05b09fa7c4c35bb91b84ddc69aa0ecdc (diff)
downloadyt-local-dcdf02737a7e44dff238b5ad8c23ee422c270d7a.tar.lz
yt-local-dcdf02737a7e44dff238b5ad8c23ee422c270d7a.tar.xz
yt-local-dcdf02737a7e44dff238b5ad8c23ee422c270d7a.zip
fix error when getting no content in channel response
Diffstat (limited to 'youtube')
-rw-r--r--youtube/channel.py14
-rw-r--r--youtube/playlist.py4
2 files changed, 13 insertions, 5 deletions
diff --git a/youtube/channel.py b/youtube/channel.py
index b7a4462..205d61f 100644
--- a/youtube/channel.py
+++ b/youtube/channel.py
@@ -80,6 +80,8 @@ def get_channel_tab(channel_id, page="1", sort=3, tab='videos', view=1):
content = common.fetch_url(url, headers_1)
print("Finished recieving channel tab response")
+ '''with open('debug/channel_debug', 'wb') as f:
+ f.write(content)'''
info = json.loads(content)
return info
@@ -131,8 +133,8 @@ def get_number_of_videos(channel_id):
url = 'https://m.youtube.com/playlist?list=' + playlist_id + '&ajax=1&disable_polymer=true'
print("Getting number of videos")
response = common.fetch_url(url, common.mobile_ua + headers_1)
- with open('playlist_debug_metadata', 'wb') as f:
- f.write(response)
+ '''with open('debug/playlist_debug_metadata', 'wb') as f:
+ 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(',',''))
@@ -153,7 +155,13 @@ def channel_videos_html(polymer_json, current_page=1, number_of_videos = 1000, c
try:
items = polymer_json[1]['response']['continuationContents']['gridContinuation']['items']
except KeyError:
- items = polymer_json[1]['response']['contents']['twoColumnBrowseResultsRenderer']['tabs'][1]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['gridRenderer']['items']
+ response = polymer_json[1]['response']
+ try:
+ contents = response['contents']
+ except KeyError:
+ items = []
+ else:
+ items = contents['twoColumnBrowseResultsRenderer']['tabs'][1]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['gridRenderer']['items']
items_html = ''
for video in items:
items_html += grid_video_item_html(grid_video_item_info(video['gridVideoRenderer'], microformat['title']))
diff --git a/youtube/playlist.py b/youtube/playlist.py
index 592d1b4..19f825f 100644
--- a/youtube/playlist.py
+++ b/youtube/playlist.py
@@ -132,8 +132,8 @@ def get_videos_ajax(playlist_id, page):
}
print("Sending playlist ajax request")
content = common.fetch_url(url, headers)
- with open('playlist_debug', 'wb') as f:
- f.write(content)
+ '''with open('debug/playlist_debug', 'wb') as f:
+ f.write(content)'''
content = content[4:]
print("Finished recieving playlist response")