From 4b3792be11393c5097442c303c78215701f992c3 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Tue, 6 Oct 2020 20:38:15 +0300 Subject: [PATCH] Accumulated changes while server was down --- home/.config/mimeo/associations.txt | 20 +++---- root/boot/loader/entries/kodi.conf | 2 +- root/etc/mkinitcpio.conf | 2 +- root/usr/local/bin/sway-run | 1 + root/usr/local/bin/umpv | 84 +++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 12 deletions(-) create mode 100755 root/usr/local/bin/umpv diff --git a/home/.config/mimeo/associations.txt b/home/.config/mimeo/associations.txt index 0c35054..27e0d1a 100644 --- a/home/.config/mimeo/associations.txt +++ b/home/.config/mimeo/associations.txt @@ -1,31 +1,31 @@ -mpvq %U +umpv %U ^https?://invidio.us/.* -mpvq %U +umpv %U ^https?://(m.)?(www.)?youtube.com/watch\?.*v= -mpvq %U +umpv %U ^https?://(www.)?youtube.com/playlist\?.*list= -mpvq %U +umpv %U ^https?://(www.)?youtu.be/ -mpvq %U +umpv %U ^https?://(www.)?(m.)?twitch.tv/ -mpvq %U +umpv %U ^https?://(?:[a-z0-9\-]+\.)+[a-z]{2,6}(?:/[^/#?]+)+\.(?:mp4|mkv|webm|avi|3gp|gif|gifv) -mpvq %U +umpv %U ^https?://www.facebook.com/.*/videos/ -mpvq %U +umpv %U ^https?://gfycat.com/.* -mpvq %U +umpv %U ^https?://vimeo.com/.* -mpvq %U +umpv %U ^https?://v.redd.it/.* imgurviewer %U diff --git a/root/boot/loader/entries/kodi.conf b/root/boot/loader/entries/kodi.conf index 97a4627..5a86d92 100755 --- a/root/boot/loader/entries/kodi.conf +++ b/root/boot/loader/entries/kodi.conf @@ -2,4 +2,4 @@ title Kodi initrd /amd-ucode.img initrd /initramfs-linux.img linux /vmlinuz-linux -options rd.luks.uuid=19fa8fab-c5fe-454a-9a17-b7185ce975ea rd.luks.name=19fa8fab-c5fe-454a-9a17-b7185ce975ea=cryptroot rd.luks.options=allow-discards root=/dev/mapper/cryptroot rootflags=subvol=root resume=/dev/mapper/cryptroot resume_offset=7345408 rw quiet splash vga=current idle=nomwait video=eDP-1:d +options rd.luks.uuid=19fa8fab-c5fe-454a-9a17-b7185ce975ea rd.luks.name=19fa8fab-c5fe-454a-9a17-b7185ce975ea=cryptroot rd.luks.options=allow-discards root=/dev/mapper/cryptroot rootflags=subvol=root resume=/dev/mapper/cryptroot resume_offset=10530935 rw quiet splash vga=current idle=nomwait video=eDP-1:d video=1920x1080@60 diff --git a/root/etc/mkinitcpio.conf b/root/etc/mkinitcpio.conf index de3c350..12d768e 100644 --- a/root/etc/mkinitcpio.conf +++ b/root/etc/mkinitcpio.conf @@ -2,7 +2,7 @@ MODULES=(amdgpu) FILES=() {%@@ if profile == "Mirkwood" @@%} BINARIES=("/usr/bin/btrfs") -HOOKS=(base autodetect modconf block filesystems keyboard fsck systemd sd-welcomemessage sd-encrypt) +HOOKS=(base autodetect modconf block filesystems keyboard fsck systemd sd-colors sd-vconsole sd-encrypt) {%@@ else @@%} BINARIES=() HOOKS=(colors consolefont base udev autodetect modconf block filesystems keyboard fsck) diff --git a/root/usr/local/bin/sway-run b/root/usr/local/bin/sway-run index 819221c..762d6e1 100755 --- a/root/usr/local/bin/sway-run +++ b/root/usr/local/bin/sway-run @@ -9,6 +9,7 @@ export MOZ_WEBRENDER=1 # Enable xdg-desktop-portal-wlr export XDG_CURRENT_DESKTOP=sway +export XDG_SESSION_TYPE=wayland # Fix java on wayland export _JAVA_AWT_WM_NONREPARENTING=1 diff --git a/root/usr/local/bin/umpv b/root/usr/local/bin/umpv new file mode 100755 index 0000000..37a00a6 --- /dev/null +++ b/root/usr/local/bin/umpv @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +""" +This script emulates "unique application" functionality on Linux. When starting +playback with this script, it will try to reuse an already running instance of +mpv (but only if that was started with umpv). Other mpv instances (not started +by umpv) are ignored, and the script doesn't know about them. +This only takes filenames as arguments. Custom options can't be used; the script +interprets them as filenames. If mpv is already running, the files passed to +umpv are appended to mpv's internal playlist. If a file does not exist or is +otherwise not playable, mpv will skip the playlist entry when attempting to +play it (from the GUI perspective, it's silently ignored). +If mpv isn't running yet, this script will start mpv and let it control the +current terminal. It will not write output to stdout/stderr, because this +will typically just fill ~/.xsession-errors with garbage. +mpv will terminate if there are no more files to play, and running the umpv +script after that will start a new mpv instance. +Note: you can supply custom mpv path and options with the MPV environment + variable. The environment variable will be split on whitespace, and the + first item is used as path to mpv binary and the rest is passed as options + _if_ the script starts mpv. If mpv is not started by the script (i.e. mpv + is already running), this will be ignored. +""" + +import sys +import os +import socket +import errno +import subprocess +import fcntl +import stat +import string + +files = sys.argv[1:] + +# this is the same method mpv uses to decide this +def is_url(filename): + parts = filename.split("://", 1) + if len(parts) < 2: + return False + # protocol prefix has no special characters => it's an URL + allowed_symbols = string.ascii_letters + string.digits + '_' + prefix = parts[0] + return all(map(lambda c: c in allowed_symbols, prefix)) + +# make them absolute; also makes them safe against interpretation as options +def make_abs(filename): + if not is_url(filename): + return os.path.abspath(filename) + return filename +files = [make_abs(f) for f in files] + +SOCK = os.path.join(os.getenv("HOME"), ".umpv_socket") + +sock = None +try: + sock = socket.socket(socket.AF_UNIX) + sock.connect(SOCK) +except socket.error as e: + if e.errno == errno.ECONNREFUSED: + sock = None + pass # abandoned socket + elif e.errno == errno.ENOENT: + sock = None + pass # doesn't exist + else: + raise e + +if sock: + # Unhandled race condition: what if mpv is terminating right now? + for f in files: + # escape: \ \n " + f = f.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + f = "\"" + f + "\"" + sock.send(("raw loadfile " + f + " append\n").encode("utf-8")) +else: + # Let mpv recreate socket if it doesn't already exist. + + opts = (os.getenv("MPV") or "mpv").split() + opts.extend(["--no-terminal", "--force-window", "--input-ipc-server=" + SOCK, + "--"]) + opts.extend(files) + + subprocess.check_call(opts)