mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
[extractor/youtube] Bring back _extract_chapters_from_description
Closes #3886
This commit is contained in:
parent
52023f1291
commit
0fe51254cb
1 changed files with 16 additions and 0 deletions
|
@ -2715,6 +2715,21 @@ def _extract_chapters_from_engagement_panel(self, data, duration):
|
|||
for contents in content_list
|
||||
))), [])
|
||||
|
||||
@staticmethod
|
||||
def _extract_chapters_from_description(description, duration):
|
||||
chapters = [{'start_time': 0}]
|
||||
for timestamp, title in re.findall(
|
||||
r'(?m)^((?:\d+:)?\d{1,2}:\d{2})\b\W*\s(.+?)\s*$', description or ''):
|
||||
start = parse_duration(timestamp)
|
||||
if start and title and chapters[-1]['start_time'] < start < duration:
|
||||
chapters[-1]['end_time'] = start
|
||||
chapters.append({
|
||||
'start_time': start,
|
||||
'title': title,
|
||||
})
|
||||
chapters[-1]['end_time'] = duration
|
||||
return chapters[1:]
|
||||
|
||||
def _extract_chapters(self, chapter_list, chapter_time, chapter_title, duration):
|
||||
chapters = []
|
||||
last_chapter = {'start_time': 0}
|
||||
|
@ -3668,6 +3683,7 @@ def process_language(container, base_url, lang_code, sub_name, query):
|
|||
info['chapters'] = (
|
||||
self._extract_chapters_from_json(initial_data, duration)
|
||||
or self._extract_chapters_from_engagement_panel(initial_data, duration)
|
||||
or self._extract_chapters_from_description(video_description, duration)
|
||||
or None)
|
||||
|
||||
contents = traverse_obj(
|
||||
|
|
Loading…
Reference in a new issue