From df1e71a7cc67c079f8012ac2ddd590a851652057 Mon Sep 17 00:00:00 2001 From: yumcookiez Date: Thu, 27 Mar 2025 21:44:28 +1000 Subject: [PATCH] ytdl_hook: add option to extract chapters --- DOCS/interface-changes/ytdl-extract-chapters.txt | 1 + DOCS/man/options.rst | 3 +++ options/options.c | 2 ++ options/options.h | 1 + player/lua/ytdl_hook.lua | 3 ++- 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 DOCS/interface-changes/ytdl-extract-chapters.txt diff --git a/DOCS/interface-changes/ytdl-extract-chapters.txt b/DOCS/interface-changes/ytdl-extract-chapters.txt new file mode 100644 index 0000000000..badb01c740 --- /dev/null +++ b/DOCS/interface-changes/ytdl-extract-chapters.txt @@ -0,0 +1 @@ +add `--ytdl-extract-chapters` option diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 112867f211..1ad03c868f 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1039,6 +1039,9 @@ Program Behavior - ``--ytdl-raw-options=proxy=[http://127.0.0.1:3128]`` - ``--ytdl-raw-options-append=proxy=http://127.0.0.1:3128`` +``--ytdl-extract-chapters=`` + Enable chapter extracting from youtube-dl video description (default: yes). + ``--js-memory-report=`` Enable memory reporting for javascript scripts in the stats overlay. This is disabled by default because it has an overhead and increases diff --git a/options/options.c b/options/options.c index a16e8c05be..58326fb464 100644 --- a/options/options.c +++ b/options/options.c @@ -552,6 +552,7 @@ static const m_option_t mp_opts[] = { {"ytdl", OPT_BOOL(lua_load_ytdl), .flags = UPDATE_BUILTIN_SCRIPTS}, {"ytdl-format", OPT_STRING(lua_ytdl_format)}, {"ytdl-raw-options", OPT_KEYVALUELIST(lua_ytdl_raw_options)}, + {"ytdl-extract-chapters", OPT_BOOL(lua_ytdl_extract_chapters)}, {"load-stats-overlay", OPT_BOOL(lua_load_stats), .flags = UPDATE_BUILTIN_SCRIPTS}, {"load-console", OPT_BOOL(lua_load_console), @@ -991,6 +992,7 @@ static const struct MPOpts mp_default_opts = { .lua_load_ytdl = true, .lua_ytdl_format = NULL, .lua_ytdl_raw_options = NULL, + .lua_ytdl_extract_chapters = true, .lua_load_stats = true, .lua_load_console = true, .lua_load_auto_profiles = -1, diff --git a/options/options.h b/options/options.h index 3fd01545fd..6f16f50c25 100644 --- a/options/options.h +++ b/options/options.h @@ -176,6 +176,7 @@ typedef struct MPOpts { bool lua_load_ytdl; char *lua_ytdl_format; char **lua_ytdl_raw_options; + bool lua_ytdl_extract_chapters; bool lua_load_stats; bool lua_load_console; int lua_load_auto_profiles; diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 7090d89736..1e3efb544d 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -827,7 +827,8 @@ local function add_single_video(json) end table.insert(chapter_list, {time=chapter.start_time, title=title}) end - elseif json.description ~= nil and json.duration ~= nil then + elseif json.description ~= nil and json.duration ~= nil and + mp.get_property_bool("ytdl-extract-chapters") then chapter_list = extract_chapters(json.description, json.duration) end