From 506dbb552a97ec4cc70538fc8e13ef9bfa901a4c Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 30 Dec 2019 16:18:38 -0800 Subject: Extraction: Correctly extract view_count for vids with 0 views. Also change superfluous use of multi_get to item.get nearby --- youtube/yt_data_extract/common.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'youtube/yt_data_extract') diff --git a/youtube/yt_data_extract/common.py b/youtube/yt_data_extract/common.py index 8d91f26..dfccdd1 100644 --- a/youtube/yt_data_extract/common.py +++ b/youtube/yt_data_extract/common.py @@ -258,7 +258,15 @@ def extract_item_info(item, additional_info={}): if info['view_count']: info['approx_view_count'] = '{:,}'.format(info['view_count']) else: - info['approx_view_count'] = extract_approx_int(multi_get(item, 'shortViewCountText')) + info['approx_view_count'] = extract_approx_int(item.get('shortViewCountText')) + + # handle case where it is "No views" + if not info['approx_view_count']: + if ('No views' in item.get('shortViewCountText', '') + or 'no views' in accessibility_label.lower()): + info['view_count'] = 0 + info['approx_view_count'] = '0' + info['duration'] = extract_str(item.get('lengthText')) elif primary_type == 'playlist': info['id'] = item.get('playlistId') -- cgit v1.2.3