Merge short and video parsing

This commit is contained in:
Jesus E 2023-06-17 16:10:59 -04:00
parent e6fd9b40f4
commit a4299dc917
No known key found for this signature in database
GPG Key ID: 159C8F8BC9AED8B6

View File

@ -251,7 +251,7 @@ def extract_item_info(item, additional_info={}):
info['type'] = 'video' info['type'] = 'video'
elif type_parts[0] == 'reel': # shorts elif type_parts[0] == 'reel': # shorts
info['type'] = 'video' info['type'] = 'video'
primary_type = 'short' primary_type = 'video'
elif primary_type in ('playlist', 'radio', 'show'): elif primary_type in ('playlist', 'radio', 'show'):
info['type'] = 'playlist' info['type'] = 'playlist'
info['playlist_type'] = primary_type info['playlist_type'] = primary_type
@ -323,30 +323,14 @@ def extract_item_info(item, additional_info={}):
# handle case where it is "No views" # handle case where it is "No views"
if not info['approx_view_count']: if not info['approx_view_count']:
if ('No views' in extract_str(item.get('viewCountText', ''))): if ('No views' in item.get('shortViewCountText', '')
or 'no views' in accessibility_label.lower()):
info['view_count'] = 0 info['view_count'] = 0
info['approx_view_count'] = '0' info['approx_view_count'] = '0'
info['duration'] = extract_str(item.get('lengthText')) info['duration'] = extract_str(item.get('lengthText'))
# if it's an item in a playlist, get its index if info['duration'] is None: # shorts
if 'index' in item: # url has wrong index on playlist page
info['index'] = extract_int(item.get('index'))
elif 'indexText' in item:
# Current item in playlist has ▶ instead of the actual index, must
# dig into url
match = re.search(r'index=(\d+)', deep_get(item,
'navigationEndpoint', 'commandMetadata', 'webCommandMetadata',
'url', default=''))
if match is None: # worth a try then
info['index'] = extract_int(item.get('indexText'))
else:
info['index'] = int(match.group(1))
else:
info['index'] = None
elif primary_type == 'short':
info['id'] = item.get('videoId')
if not info['id']: if not info['id']:
info['id'] = deep_get(item,'navigationEndpoint', info['id'] = deep_get(item,'navigationEndpoint',
'reelWatchEndpoint', 'videoId') 'reelWatchEndpoint', 'videoId')
@ -354,8 +338,7 @@ def extract_item_info(item, additional_info={}):
# handle case where it is "No views" # handle case where it is "No views"
if not info['approx_view_count']: if not info['approx_view_count']:
if ('No views' in item.get('shortViewCountText', '') if ('No views' in extract_str(item.get('viewCountText', ''))):
or 'no views' in accessibility_label.lower()):
info['view_count'] = 0 info['view_count'] = 0
info['approx_view_count'] = '0' info['approx_view_count'] = '0'
@ -363,7 +346,6 @@ def extract_item_info(item, additional_info={}):
accessibility_label = multi_deep_get(item, accessibility_label = multi_deep_get(item,
['accessibility', 'accessibilityData', 'label'], ['accessibility', 'accessibilityData', 'label'],
default='') default='')
duration = re.search(r'(\d+) (second|seconds|minute) - play video$', duration = re.search(r'(\d+) (second|seconds|minute) - play video$',
accessibility_label) accessibility_label)
if duration: if duration: