From 41b3b116695bcad3fdb3129b133e2a97d9a76847 Mon Sep 17 00:00:00 2001 From: Ricardo Constantino Date: Sun, 2 Jul 2017 21:15:15 +0100 Subject: ytdl_hook: add pre-parsed chapters, if available Available since 2017.05.07 but only on certain extractors. --- player/lua/ytdl_hook.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'player') diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index d8476d86e3..c7049f1b85 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -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 = {} -- cgit v1.2.3