mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-10-02 23:47:08 +02:00
Fixed issue with chapters extractions and fixed up formatting issues flagged by flake8
This commit is contained in:
parent
d6a13931c9
commit
4042d2f64f
@ -318,11 +318,11 @@ 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 = traverse_obj(json_data, ('video', 'currentClip', 'mediaId'))
|
mediaID = traverse_obj(json_data, ('video', 'currentClip', 'mediaId')) or None
|
||||||
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']
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
|
self._download_json(info['media']['assets'][0]['key'], video_id)['url'], video_id)
|
||||||
|
|
||||||
def _process_chapters(tp_chapters, duration):
|
def _process_chapters(tp_chapters, duration):
|
||||||
chapters = []
|
chapters = []
|
||||||
@ -338,13 +338,16 @@ def _add_chapter(start_time, end_time, title=None):
|
|||||||
'title': title,
|
'title': title,
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(tp_chapters) == 0 or tp_chapters is None:
|
if tp_chapters is None or len(tp_chapters) == 0:
|
||||||
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'),
|
||||||
or tp_chapters[x + 1].get('startTime'), tp_chapters[x].get('name'))
|
tp_chapters[x].get('endTime') or tp_chapters[x + 1].get('startTime'),
|
||||||
_add_chapter(tp_chapters[-1].get('startTime'), tp_chapters[-1].get('endTime')
|
tp_chapters[x].get('name'))
|
||||||
or duration, tp_chapters[-1].get('name'))
|
_add_chapter(tp_chapters[-1].get('startTime'),
|
||||||
|
tp_chapters[-1].get('endTime') or duration, tp_chapters[-1].get('name'))
|
||||||
|
|
||||||
return chapters
|
return chapters
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -357,7 +360,8 @@ def _add_chapter(start_time, end_time, title=None):
|
|||||||
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) or None,
|
'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'))),
|
traverse_obj(info, ('media', 'duration'))),
|
||||||
'media_type': traverse_obj(info, ('media', 'clipType')),
|
'media_type': traverse_obj(info, ('media', 'clipType')),
|
||||||
'series': info.get('showName'),
|
'series': info.get('showName'),
|
||||||
|
Loading…
Reference in New Issue
Block a user