From 2822d47a17d4c922a09e79084f0200d3d1b23759 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Wed, 29 Jan 2025 15:03:31 -0800 Subject: [PATCH] initial commit --- mpv-add.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 mpv-add.sh diff --git a/mpv-add.sh b/mpv-add.sh new file mode 100755 index 0000000..9fd0805 --- /dev/null +++ b/mpv-add.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +URL="${1:-$(wl-paste -p)}" +MPV_SOCKET=/tmp/mpvsocket + +if [[ -z "$URL" ]]; then + notify-send -i mpv "No URL provided" + exit 1 +fi + +if ! [[ -f "$URL" ]] && ! yt-dlp --simulate "$URL"; then + notify-send -i mpv "Invalid URL" + exit 1 +fi + +if ! pgrep -x mpv &>/dev/null; then + mpv "$URL" &>/dev/null & + notify-send -i mpv "Playing $URL" +else + if echo "{ \"command\": [\"script-message\", \"add_to_queue\", \"$URL\" ] }" | socat - "$MPV_SOCKET" &>/dev/null; then + notify-send -i mpv "Added $URL to queue" + else + notify-send -i mpv "Failed to add $URL to queue" + fi +fi