diff options
Diffstat (limited to 'ar/.config/rmpc/scripts/on_song_change')
| -rwxr-xr-x | ar/.config/rmpc/scripts/on_song_change | 61 |
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 |
