mpv-add/mpv-add.sh

28 lines
641 B
Bash
Raw Normal View History

2025-01-29 15:03:31 -08:00
#!/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