diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst index 2c16ae476c550..81d6ea6523b7d 100644 --- a/DOCS/man/mpv.rst +++ b/DOCS/man/mpv.rst @@ -321,6 +321,11 @@ g-l g-d Select an audio device. +g-h + Select a file from the history of files whose playback position has been + saved (see `RESUMING PLAYBACK`_). Requires + ``--write-filename-in-watch-later-config``. + g-b Select a defined input binding. diff --git a/etc/input.conf b/etc/input.conf index 2407e23f44ed6..3046f06fec332 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -186,6 +186,7 @@ #g-e script-binding select/select-edition #g-l script-binding select/select-subtitle-line #g-d script-binding select/select-audio-device +#g-h script-binding select/select-history #g-b script-binding select/select-binding #g-r script-binding select/show-properties diff --git a/player/lua/select.lua b/player/lua/select.lua index 3ac2f00180291..879ef4e01492e 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -345,6 +345,50 @@ mp.add_key_binding(nil, "select-audio-device", function () }) end) +mp.add_key_binding(nil, "select-history", function () + local watch_later_dir = mp.get_property("current-watch-later-dir") + local watch_later_files = {} + + for i, file in ipairs(utils.readdir(watch_later_dir, "files") or {}) do + watch_later_files[i] = watch_later_dir .. "/" .. file + end + + if #watch_later_files == 0 then + show_error("No watch later files found.") + return + end + + table.sort(watch_later_files, function (i, j) + return utils.file_info(i).mtime > utils.file_info(j).mtime + end) + + local recent_files = {} + for _, watch_later_file in ipairs(watch_later_files) do + watch_later_file = io.open(watch_later_file) + if watch_later_file then + local line = watch_later_file:read() + if line and line ~= "# redirect entry" and line:find("^#") then + recent_files[#recent_files + 1] = line:sub(3) + end + watch_later_file:close() + end + end + + if #recent_files == 0 then + show_error("No watch later files with media paths found. " .. + "Enable --write-filename-in-watch-later-config to select recent files.") + return + end + + input.select({ + prompt = "Select a recent file:", + items = recent_files, + submit = function (i) + mp.commandv("loadfile", recent_files[i]) + end, + }) +end) + mp.add_key_binding(nil, "select-binding", function () local bindings = {}