aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-05-29 01:00:41 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-05-29 01:00:41 +0530
commit0fe51254cb878cf5f65801e2b62424a185665639 (patch)
tree8a778990b19457284d43e64c954fd600fe3e6780
parent52023f129199152fa6da1caad76c1dac0421715d (diff)
downloadhypervideo-pre-0fe51254cb878cf5f65801e2b62424a185665639.tar.lz
hypervideo-pre-0fe51254cb878cf5f65801e2b62424a185665639.tar.xz
hypervideo-pre-0fe51254cb878cf5f65801e2b62424a185665639.zip
[extractor/youtube] Bring back `_extract_chapters_from_description`
Closes #3886
-rw-r--r--yt_dlp/extractor/youtube.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
index e41e74648..245778dff 100644
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -2715,6 +2715,21 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
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 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
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(