[youtube] fix chapter extraction fallback
This commit is contained in:
parent
159a3d48df
commit
efef4ddf51
|
@ -1753,22 +1753,25 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def chapter_time(mmlir):
|
def chapter_time(mmlir):
|
||||||
return parse_duration(mmlir.get(
|
return parse_duration(
|
||||||
get_text(mmlir.get('timeDescription'))))
|
get_text(mmlir.get('timeDescription')))
|
||||||
|
|
||||||
|
chapters = []
|
||||||
for next_num, content in enumerate(contents, start=1):
|
for next_num, content in enumerate(contents, start=1):
|
||||||
mmlir = content.get('macroMarkersListItemRenderer') or {}
|
mmlir = content.get('macroMarkersListItemRenderer') or {}
|
||||||
start_time = chapter_time(mmlir)
|
start_time = chapter_time(mmlir)
|
||||||
end_time = chapter_time(try_get(
|
end_time = chapter_time(try_get(
|
||||||
contents, lambda x: x[next_num]['macroMarkersListItemRenderer'])) \
|
contents, lambda x: x[next_num]['macroMarkersListItemRenderer'])) \
|
||||||
if next_num < len(contents) else duration
|
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
|
continue
|
||||||
chapters.append({
|
chapters.append({
|
||||||
'start_time': start_time,
|
'start_time': start_time,
|
||||||
'end_time': end_time,
|
'end_time': end_time,
|
||||||
'title': get_text(mmlir.get('title')),
|
'title': get_text(mmlir.get('title')),
|
||||||
})
|
})
|
||||||
|
if chapters:
|
||||||
|
break
|
||||||
if chapters:
|
if chapters:
|
||||||
info['chapters'] = chapters
|
info['chapters'] = chapters
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue