Skip to content

Instantly share code, notes, and snippets.

@Hakkin
Last active May 8, 2024 04:04
Show Gist options
  • Save Hakkin/4f978a5c87c31f7fe3ae to your computer and use it in GitHub Desktop.
Save Hakkin/4f978a5c87c31f7fe3ae to your computer and use it in GitHub Desktop.
-- betterchapters.lua
-- Loads the next or previous playlist entry if there are no more chapters in the seek direction.
-- To bind in input.conf, use: <keybind> script_binding <keybind name>
-- Keybind names: chapter_next, chapter_prev
-- Recommended to use with autoload.lua
function chapter_seek(direction)
local chapters = mp.get_property_number("chapters")
local chapter = mp.get_property_number("chapter")
if chapter == nil then chapter = 0 end
if chapters == nil then chapters = 0 end
if chapter+direction < 0 then
mp.command("playlist_prev")
elseif chapter+direction >= chapters then
mp.command("playlist_next")
else
mp.commandv("osd-msg", "add", "chapter", direction)
end
end
mp.add_key_binding("PGUP", "chapter_next", function() chapter_seek(1) end)
mp.add_key_binding("PGDWN", "chapter_prev", function() chapter_seek(-1) end)
@KonoVitoDa
Copy link

Any way to also go to the previous file if "skip to previous chapter" is used very close to the first chapter? Tto make it act like MPC-HC.
And also to hide the "Chapter (unavailable)" message?

@KonoVitoDa
Copy link

Any way to make it work for files with no chapters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment