commit 2822d47a17d4c922a09e79084f0200d3d1b23759 Author: ksyasuda Date: Wed Jan 29 15:03:31 2025 -0800 initial commit 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