From 87c83145671580d85f04305dfb56d1e78e8cd5ed Mon Sep 17 00:00:00 2001 From: RhiobeT Date: Wed, 9 Nov 2022 19:51:05 +0100 Subject: [PATCH] [mpv] steal mugen script from amoethyst --- .config/mpv/mpv.conf | 1 + .config/mpv/scripts/mugen.lua | 34 ++++++++++++++++++++++++++++++++++ .config/rofi/config.rasi | 4 ++++ .config/rofi/modi/mugen | 27 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .config/mpv/scripts/mugen.lua create mode 100755 .config/rofi/modi/mugen diff --git a/.config/mpv/mpv.conf b/.config/mpv/mpv.conf index ae71e0d..b73d361 100644 --- a/.config/mpv/mpv.conf +++ b/.config/mpv/mpv.conf @@ -2,6 +2,7 @@ profile=gpu-hq #gpu-api=vulkan gpu-context=wayland hwdec=none +fullscreen=yes #ao=jack #audio-channels=stereo diff --git a/.config/mpv/scripts/mugen.lua b/.config/mpv/scripts/mugen.lua new file mode 100644 index 0000000..4c970d4 --- /dev/null +++ b/.config/mpv/scripts/mugen.lua @@ -0,0 +1,34 @@ +local utils = require("mp.utils") + +local function get_kdata(kid) + local resp = mp.command_native({ + name = "subprocess", + args = { "curl", "-s", "https://kara.moe/api/karas/" .. kid }, + capture_stdout = true, + }) + + return utils.parse_json(resp.stdout) +end + +local function get_title(kdata) + return kdata.titles[kdata.titles_default_language] +end + +local function on_load() + local path = mp.get_property("path") + local kid = path:match("^https://kara.moe/kara/.-([0-9a-z-]+)$") + if kid == nil then + kid = path:match("^https://live.karaokes.moe/%?video=([0-9a-z-]+)$") + end + if kid ~= nil then + local kdata = get_kdata(kid) + local mediafile = "https://kara.moe/downloads/medias/" .. kdata.mediafile + local subfile = "https://kara.moe/downloads/lyrics/" .. kdata.subfile + mp.set_property("stream-open-filename", mediafile) + mp.set_property("replaygain-fallback", kdata.gain) + mp.set_property("title", get_title(kdata)) + mp.commandv("sub-add", subfile) + end +end + +mp.register_event("start-file", on_load) diff --git a/.config/rofi/config.rasi b/.config/rofi/config.rasi index 2f96dbc..22d4f6e 100644 --- a/.config/rofi/config.rasi +++ b/.config/rofi/config.rasi @@ -1,3 +1,7 @@ +configuration { + modi: "run,mugen:~/.config/rofi/modi/mugen"; +} + * { active-background: #20ABE0; active-foreground: @foreground; diff --git a/.config/rofi/modi/mugen b/.config/rofi/modi/mugen new file mode 100755 index 0000000..afc4555 --- /dev/null +++ b/.config/rofi/modi/mugen @@ -0,0 +1,27 @@ +#!/bin/sh +mugen_host=${MUGEN_HOST:-https://kara.moe} +kara_api="${MUGEN_KARA_API:-$mugen_host/api/karas}" +karamedia="${MUGEN_KARAOKEMEDIA:-$mugen_host/downloads}" + +# karaoke medias and lyrics directories +medias="$karamedia/medias" +lyrics="$karamedia/lyrics" + +kid=$ROFI_INFO + +if [ -z "$@" ]; then + /usr/bin/printf "\0prompt\x1fkaraoke search\n" + exit 0 +else + if [ -z "$kid" ]; then + /usr/bin/printf "\0prompt\x1fmugen\n" + query="$(echo "$@" | tr " " "+")" + curl "https://kara.moe/api/karas/search?collections=dbcf2c22-524d-4708-99bb-601703633927,c7db86a0-ff64-4044-9be4-66dd1ef1d1c1,2fa2fe3f-bb56-45ee-aa38-eae60e76f224,efe171c0-e8a1-4d03-98c0-60ecf741ad52&filter=$query&size=100" | jq -r '.content | .[] | "\(.mediafile)\u0000info\u001f\(.kid)"' + fi +fi + +# choose karaoke +[ -z "$kid" ] && exit + +mpv "https://kara.moe/kara/$kid" > /dev/null 2>&1 & +exec 1>&-