ytdl_hook: add pre-parsed chapters, if available

Available since 2017.05.07 but only on certain extractors.
This commit is contained in:
Ricardo Constantino 2017-07-02 21:15:15 +01:00
parent 4a084c0df8
commit 41b3b11669
No known key found for this signature in database
GPG Key ID: EFD16019AE4FF531
1 changed files with 13 additions and 3 deletions

View File

@ -193,8 +193,18 @@ local function add_single_video(json)
end
end
-- add chapters from description
if not (json.description == nil) and not (json.duration == nil) then
-- add chapters
if json.chapters then
msg.debug("Adding pre-parsed chapters")
for i = 1, #json.chapters do
local chapter = json.chapters[i]
local title = chapter.title or ""
if title == "" then
title = string.format('Chapter %02d', i)
end
table.insert(chapter_list, {time=chapter.start_time, title=title})
end
elseif not (json.description == nil) and not (json.duration == nil) then
chapter_list = extract_chapters(json.description, json.duration)
end
@ -419,7 +429,7 @@ end)
mp.add_hook("on_preloaded", 10, function ()
if next(chapter_list) ~= nil then
msg.verbose("Setting chapters from video's description")
msg.verbose("Setting chapters")
mp.set_property_native("chapter-list", chapter_list)
chapter_list = {}