diff options
author | Remita Amine <remitamine@gmail.com> | 2021-02-01 16:49:52 +0100 |
---|---|---|
committer | Remita Amine <remitamine@gmail.com> | 2021-02-01 16:49:52 +0100 |
commit | efef4ddf51c375c3a9eb12355a61a21d69aec33f (patch) | |
tree | d96ff7bc77699ea58c327fc5b0f3713060aa6f54 | |
parent | 159a3d48dfb2b4ed77dc691433e420506c9340c3 (diff) |
[youtube] fix chapter extraction fallback
-rw-r--r-- | youtube_dl/extractor/youtube.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index ed844e2a3..65fa777e4 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1753,22 +1753,25 @@ class YoutubeIE(YoutubeBaseInfoExtractor): continue def chapter_time(mmlir): - return parse_duration(mmlir.get( - get_text(mmlir.get('timeDescription')))) + return parse_duration( + get_text(mmlir.get('timeDescription'))) + chapters = [] for next_num, content in enumerate(contents, start=1): mmlir = content.get('macroMarkersListItemRenderer') or {} start_time = chapter_time(mmlir) end_time = chapter_time(try_get( contents, lambda x: x[next_num]['macroMarkersListItemRenderer'])) \ if next_num < len(contents) else duration - if not (start_time and end_time): + if start_time is None or end_time is None: continue chapters.append({ 'start_time': start_time, 'end_time': end_time, 'title': get_text(mmlir.get('title')), }) + if chapters: + break if chapters: info['chapters'] = chapters |