From f131e6d905d232b8fd7f7af0c96e7b26f3c6ac28 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Fri, 21 Aug 2026 17:22:52 +0200 Subject: [PATCH 1/2] Add keybindings to play URLs from clipboard --- tasks/mpv.yml | 9 +++++++-- templates/mpv/clipboard.lua.j2 | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 templates/mpv/clipboard.lua.j2 diff --git a/tasks/mpv.yml b/tasks/mpv.yml index a7ba1bb..3afcc60 100644 --- a/tasks/mpv.yml +++ b/tasks/mpv.yml @@ -1,9 +1,12 @@ --- -- name: Create configuration directory +- name: Create configuration directories ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/mpv" + path: "{{ item }}" state: directory mode: "0700" + loop: + - "{{ ansible_env.HOME }}/.config/mpv" + - "{{ ansible_env.HOME }}/.config/mpv/scripts" - name: Copy configuration files ansible.builtin.template: @@ -15,3 +18,5 @@ dest: "{{ ansible_env.HOME }}/.config/mpv/input.conf" - src: "templates/mpv/config.j2" dest: "{{ ansible_env.HOME }}/.config/mpv/mpv.conf" + - src: "templates/mpv/clipboard.lua.j2" + dest: "{{ ansible_env.HOME }}/.config/mpv/scripts/clipboard.lua" diff --git a/templates/mpv/clipboard.lua.j2 b/templates/mpv/clipboard.lua.j2 new file mode 100644 index 0000000..0283a78 --- /dev/null +++ b/templates/mpv/clipboard.lua.j2 @@ -0,0 +1,28 @@ +-- {{ ansible_managed }} +-- Note that the mp global is injected by mpv when the script is ran. + +local utils = require 'mp.utils' + +local function paste_from_clipboard(command) + local res = utils.subprocess({ args = { 'wl-paste', '--no-newline' } }) + if res.status == 0 and res.stdout then + local url = res.stdout:gsub("^%s*(.-)%s*$", "%1") -- trim whitespace + if url ~= "" then + mp.commandv("loadfile", url, command) + mp.osd_message("Processed: " .. url) + end + end +end + + +local function append_from_clipboard() + paste_from_clipboard("append") +end + +local function replace_from_clipboard() + paste_from_clipboard("replace") +end + +-- TODO: add keybinding that works with idle screen +mp.add_key_binding("Shift+MBTN_RIGHT", "append_clipboard", append_from_clipboard) +mp.add_key_binding("Shift+MBTN_LEFT", "replace_clipboard", replace_from_clipboard) From 1de2c9378965c1b36719c4158154977a108c79f7 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Fri, 21 Aug 2026 17:23:23 +0200 Subject: [PATCH 2/2] Set default audio/subtitle tracks --- templates/mpv/config.j2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/mpv/config.j2 b/templates/mpv/config.j2 index d9bc854..0c14a71 100644 --- a/templates/mpv/config.j2 +++ b/templates/mpv/config.j2 @@ -8,3 +8,6 @@ keep-open=yes # do not close the window on exit keepaspect-window=no # add black bars if window aspect and video aspect mismatch sub-auto=fuzzy # load all subs containing the media filename + +alang=en,nl +slang=en,nl