From 1eecc5a880a460ebe18d513a94010b265303d567 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 6 Jul 2018 18:12:41 -0700 Subject: fix video length not being gotten for grid renderers --- youtube/channel.py | 4 ++-- youtube/common.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'youtube') diff --git a/youtube/channel.py b/youtube/channel.py index f04ac45..96e85c8 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -80,8 +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)''' + with open('debug/channel_debug', 'wb') as f: + f.write(content) info = json.loads(content) return info diff --git a/youtube/common.py b/youtube/common.py index 6994064..d9429a2 100644 --- a/youtube/common.py +++ b/youtube/common.py @@ -360,7 +360,18 @@ def renderer_info(renderer): info['views'] = get_text(renderer['viewCountText']) elif 'shortViewCountText' in renderer: info['views'] = get_text(renderer['shortViewCountText']) - + try: + overlays = renderer['thumbnailOverlays'] + except KeyError: + pass + else: + for overlay in overlays: + try: + info['duration'] = get_text(overlay['thumbnailOverlayTimeStatusRenderer']['text']) + except KeyError: + pass + else: + break for key, node in renderer.items(): if key in ('longBylineText', 'shortBylineText'): info['author'] = get_text(node) -- cgit v1.2.3