From 004e14a53800a5235d850517db8a3b421e804b30 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 18 Dec 2019 20:53:11 -0800 Subject: Extraction: Use accessibility data to get timestamp and to get views for recommended videos --- youtube/yt_data_extract.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'youtube/yt_data_extract.py') diff --git a/youtube/yt_data_extract.py b/youtube/yt_data_extract.py index 6a5e4bb..ac5b78b 100644 --- a/youtube/yt_data_extract.py +++ b/youtube/yt_data_extract.py @@ -386,6 +386,16 @@ def extract_item_info(item, additional_info={}): if primary_type == 'video': info['id'] = item.get('videoId') info['view_count'] = extract_int(item.get('viewCountText')) + + # dig into accessibility data to get view_count for videos marked as recommended, and to get time_published + accessibility_label = deep_get(item, 'title', 'accessibility', 'accessibilityData', 'label', default='') + timestamp = re.search(r'(\d+ \w+ ago)', accessibility_label) + if timestamp: + conservative_update(info, 'time_published', timestamp.group(1)) + view_count = re.search(r'(\d+) views', accessibility_label.replace(',', '')) + if view_count: + conservative_update(info, 'view_count', int(view_count.group(1))) + if info['view_count']: info['approx_view_count'] = '{:,}'.format(info['view_count']) else: -- cgit v1.2.3