Initial commit

This commit is contained in:
Chl 2024-02-06 01:05:11 +01:00
commit ddc497f68d
3 changed files with 85 additions and 0 deletions

5
LICENSE Normal file
View file

@ -0,0 +1,5 @@
Copyright (C) 2024 by Chl <chl-dev@bugness.org>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

15
README.md Normal file
View file

@ -0,0 +1,15 @@
This is a small script for the media player [mpv](https://github.com/mpv-player/mpv). It delays quitting at the end of the current item by pressing `alt+q`.
## Installation
```
git clone https://code.bugness.org/chl/mpv_delayed_quit ~/.config/mpv/scripts/delayed_quit
```
Or download the Lua file and put it in the directory `~/.config/mpv/scripts/delayed_quit/`.
## Usage
* `alt+q` : make mpv quit at the end of the current file (or the counter-th file) in the playlist, press again to forgo,
* `alt+shift+q` : increment the counter, so mpv will quit one file later,
* `alt+a` : decrement the counter, so mpv will quit one file sooner.

65
main.lua Normal file
View file

@ -0,0 +1,65 @@
require "mp"
require "mp.msg"
local settings = {
delayed_quit_cpt = 0,
delayed_quit_activating_when_modifying = true
}
(require "mp.options").read_options(settings, "delayed_quit")
local delayed_quit = false
local delayed_quit_cpt = settings.delayed_quit_cpt
-- Functions for the key bindings
function delayed_quit_decrease()
-- Decrease (minimum is 0)
delayed_quit_cpt = math.max(delayed_quit_cpt - 1, 0)
-- Eventually activate the delayed_quit
delayed_quit = delayed_quit or settings.delayed_quit_activating_when_modifying
delayed_quit_little_debug()
end
function delayed_quit_increase()
-- Increment the delayed counter
delayed_quit_cpt = delayed_quit_cpt + 1
-- Eventually activate the delayed_quit
delayed_quit = delayed_quit or settings.delayed_quit_activating_when_modifying
delayed_quit_little_debug()
end
function delayed_quit_switch()
delayed_quit = not delayed_quit
delayed_quit_little_debug()
end
-- Little debug
function delayed_quit_little_debug()
mp.osd_message((delayed_quit and "" or "(disabled) ") .. "Quitting after " .. delayed_quit_cpt .. " file(s).")
end
-- Hooks
function hook_should_we_quit()
if delayed_quit then
if delayed_quit_cpt <= 0 then
mp.command("quit")
-- Little debug
mp.msg.log("info", "As requested, quitting now.")
else
delayed_quit_cpt = delayed_quit_cpt - 1
end
end
end
-- Register our little hook
mp.add_hook("on_after_end_file", 50, hook_should_we_quit)
-- Add the key binding
-- We add a name so a user can remap it in its input.conf like this :
-- y script-binding delayed_quit_switch
mp.add_key_binding("alt+q", "delayed_quit_switch", delayed_quit_switch)
mp.add_key_binding("alt+shift+q", "delayed_quit_increase", delayed_quit_increase)
mp.add_key_binding("alt+a", "delayed_quit_decrease", delayed_quit_decrease)