1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-10-04 16:37:09 +02:00

Fixed up more and adapted to yt-dlp coding practices

This commit is contained in:
Benjamin Krausse 2024-06-27 01:25:36 +02:00
parent 9378600ef2
commit d6a13931c9

View File

@ -22,7 +22,6 @@
base_url, base_url,
urljoin, urljoin,
remove_end, remove_end,
unified_timestamp,
) )
@ -319,7 +318,7 @@ def _real_extract(self, url):
json_data = self._search_json( json_data = self._search_json(
r'window\.__INITIAL_STATE__\s*=', webpage, r'window\.__INITIAL_STATE__\s*=', webpage,
'initial state', video_id) 'initial state', video_id)
mediaID = json_data['video']['currentClip'].get('mediaId') # switch to traverse_obj, including later mediaID = traverse_obj(json_data, ('video', 'currentClip', 'mediaId'))
if mediaID is None: if mediaID is None:
info = json_data['video']['currentClip'] info = json_data['video']['currentClip']
m3u8_url = self._download_json(info['media']['assets'][0]['key'], video_id)['url'] m3u8_url = self._download_json(info['media']['assets'][0]['key'], video_id)['url']
@ -339,35 +338,35 @@ def _add_chapter(start_time, end_time, title=None):
'title': title, 'title': title,
}) })
if len(tp_chapters) == 0: if len(tp_chapters) == 0 or tp_chapters is None:
return [] return []
for x in range(len(tp_chapters) - 1): for x in range(len(tp_chapters) - 1):
_add_chapter(tp_chapters[x].get('startTime'), tp_chapters[x].get('endTime') _add_chapter(tp_chapters[x].get('startTime'), tp_chapters[x].get('endTime')
or tp_chapters[x + 1].get('startTime'), tp_chapters[x].get('name')) or tp_chapters[x + 1].get('startTime'), tp_chapters[x].get('name'))
_add_chapter(tp_chapters[-1].get('startTime'), tp_chapters[-1].get('endTime') _add_chapter(tp_chapters[-1].get('startTime'), tp_chapters[-1].get('endTime')
or duration, tp_chapters[-1].get('name')) or duration, tp_chapters[-1].get('name'))
return chapters return chapters
return { return {
'id': video_id, # switch to media ID? 'id': video_id, # switch to media ID?
'title': info.get('title'), 'title': info.get('title'),
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
'description': remove_end(info.get('description'),' \n'), 'description': remove_end(info.get('description'), ' \n'),
'thumbnail': urljoin(base_url( 'thumbnail': urljoin(base_url(
info.get('image').get('url')), info.get('image').get('url')),
url_basename(info.get('image').get('url'))), # strip the arguments from the URL to remove the crop url_basename(info.get('image').get('url'))), # strip the arguments from the URL to remove the crop
'timestamp': int_or_none(info.get('publishedAt'))/1000, # unified_timestamp(info.get('publishedAt')), 'timestamp': int_or_none(info.get('publishedAt'), 1000) or None,
'chapters': _process_chapters(info['media'].get('chapters'), info['media'].get('duration')) if 'chapters': _process_chapters(traverse_obj(info, ('media', 'chapters')),
info['media'].get('chapters') is not None and info['media'].get('duration') is not None else None, traverse_obj(info, ('media', 'duration'))),
'media_type': info['media'].get('clipType'), 'media_type': traverse_obj(info, ('media', 'clipType')),
'series': info.get('showName'), 'series': info.get('showName'),
'duration': info['media'].get('duration'), 'duration': traverse_obj(info, ('media', 'duration')),
'tags': traverse_obj(info, ( 'tags': traverse_obj(info, (
'tags', lambda _, v: v.get('label') in ('tags', None), 'name', {str})) or None, 'tags', lambda _, v: v.get('label') in ('tags', None), 'name', {str})) or None,
'location': info['media'].get('region'), 'location': traverse_obj(info, ('media', 'region')),
'genres': [info['media'].get('genre')], 'genres': [traverse_obj(info, ('media', 'genre'))],
'is_live': True if (info['media'].get('streamType') == 'Live') else False, 'is_live': True if (traverse_obj(info, ('media', 'streamType')) == 'Live') else False,
'categories': traverse_obj(info, ( 'categories': traverse_obj(info, (
'categories', lambda _, v: v.get('label') in ('category', None), 'name', {str})) or None, 'categories', lambda _, v: v.get('label') in ('category', None), 'name', {str})) or None,
} }