1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-07-03 02:35:28 +02:00

Fixed issue with chapters extractions and fixed up formatting issues flagged by flake8

This commit is contained in:
Benjamin Krausse 2024-06-29 18:26:11 +02:00
parent d6a13931c9
commit 4042d2f64f

View File

@ -318,11 +318,11 @@ def _real_extract(self, url):
json_data = self._search_json(
r'window\.__INITIAL_STATE__\s*=', webpage,
'initial state', video_id)
mediaID = traverse_obj(json_data, ('video', 'currentClip', 'mediaId'))
mediaID = traverse_obj(json_data, ('video', 'currentClip', 'mediaId')) or None
if mediaID is None:
info = json_data['video']['currentClip']
m3u8_url = self._download_json(info['media']['assets'][0]['key'], video_id)['url']
formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
self._download_json(info['media']['assets'][0]['key'], video_id)['url'], video_id)
def _process_chapters(tp_chapters, duration):
chapters = []
@ -338,13 +338,16 @@ def _add_chapter(start_time, end_time, title=None):
'title': title,
})
if len(tp_chapters) == 0 or tp_chapters is None:
if tp_chapters is None or len(tp_chapters) == 0:
return []
for x in range(len(tp_chapters) - 1):
_add_chapter(tp_chapters[x].get('startTime'), tp_chapters[x].get('endTime')
or tp_chapters[x + 1].get('startTime'), tp_chapters[x].get('name'))
_add_chapter(tp_chapters[-1].get('startTime'), tp_chapters[-1].get('endTime')
or duration, tp_chapters[-1].get('name'))
_add_chapter(tp_chapters[x].get('startTime'),
tp_chapters[x].get('endTime') or tp_chapters[x + 1].get('startTime'),
tp_chapters[x].get('name'))
_add_chapter(tp_chapters[-1].get('startTime'),
tp_chapters[-1].get('endTime') or duration, tp_chapters[-1].get('name'))
return chapters
return {
@ -357,7 +360,8 @@ def _add_chapter(start_time, end_time, title=None):
info.get('image').get('url')),
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) or None,
'chapters': _process_chapters(traverse_obj(info, ('media', 'chapters')),
'chapters': _process_chapters(
traverse_obj(info, ('media', 'chapters')),
traverse_obj(info, ('media', 'duration'))),
'media_type': traverse_obj(info, ('media', 'clipType')),
'series': info.get('showName'),