summaryrefslogtreecommitdiff
path: root/ar/.config/rmpc/scripts/on_song_change
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-02-17 22:19:16 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-02-17 22:19:16 +0900
commitba6a11651f6ab23e62ceab18e3fd383318fe02d2 (patch)
treed492a99af564d5990be4f01976571b1405033f70 /ar/.config/rmpc/scripts/on_song_change
parenteec577616f0f23949030c36e2a5061974c9bfe45 (diff)
updates
Diffstat (limited to 'ar/.config/rmpc/scripts/on_song_change')
-rwxr-xr-xar/.config/rmpc/scripts/on_song_change61
1 files changed, 61 insertions, 0 deletions
diff --git a/ar/.config/rmpc/scripts/on_song_change b/ar/.config/rmpc/scripts/on_song_change
new file mode 100755
index 0000000..72a68ae
--- /dev/null
+++ b/ar/.config/rmpc/scripts/on_song_change
@@ -0,0 +1,61 @@
+#!/usr/bin/env sh
+
+# ── dwmblocks signal ─────────────────────────────────────────────────────────
+pkill -RTMIN+21 dwmblocks
+
+# ── Desktop notification ──────────────────────────────────────────────────────
+TMP_DIR="/tmp/rmpc"
+mkdir -p "$TMP_DIR"
+ALBUM_ART_PATH="$TMP_DIR/notification_cover"
+
+if ! rmpc albumart --output "$ALBUM_ART_PATH"; then
+ ALBUM_ART_PATH=""
+fi
+
+if [ -n "$ALBUM_ART_PATH" ]; then
+ notify-send -i "$ALBUM_ART_PATH" "Now Playing" "$ARTIST - $TITLE"
+else
+ notify-send "Now Playing" "$ARTIST - $TITLE"
+fi
+
+# ── Play count ────────────────────────────────────────────────────────────────
+sticker=$(rmpc sticker get "$FILE" "playCount" 2>/dev/null | jq -r '.value')
+if [ -z "$sticker" ]; then
+ rmpc sticker set "$FILE" "playCount" "1"
+else
+ rmpc sticker set "$FILE" "playCount" "$((sticker + 1))"
+fi
+
+# ── Auto lyrics download ──────────────────────────────────────────────────────
+LRCLIB_INSTANCE="https://lrclib.net"
+
+if [ "$HAS_LRC" = "false" ]; then
+ mkdir -p "$(dirname "$LRC_FILE")"
+
+ LYRICS="$(curl -X GET -sG \
+ -H "Lrclib-Client: rmpc-$VERSION" \
+ --data-urlencode "artist_name=$ARTIST" \
+ --data-urlencode "track_name=$TITLE" \
+ --data-urlencode "album_name=$ALBUM" \
+ "$LRCLIB_INSTANCE/api/get" | jq -r '.syncedLyrics')"
+
+ if [ -z "$LYRICS" ]; then
+ rmpc remote --pid "$PID" status "Failed to download lyrics for $ARTIST - $TITLE" --level error
+ exit
+ fi
+
+ if [ "$LYRICS" = "null" ]; then
+ rmpc remote --pid "$PID" status "Lyrics for $ARTIST - $TITLE not found" --level warn
+ exit
+ fi
+
+ echo "[ar:$ARTIST]" >"$LRC_FILE"
+ {
+ echo "[al:$ALBUM]"
+ echo "[ti:$TITLE]"
+ } >>"$LRC_FILE"
+ echo "$LYRICS" | sed -E '/^\[(ar|al|ti):/d' >>"$LRC_FILE"
+
+ rmpc remote --pid "$PID" indexlrc --path "$LRC_FILE"
+ rmpc remote --pid "$PID" status "Downloaded lyrics for $ARTIST - $TITLE" --level info
+fi