diff options
Diffstat (limited to 'ar/.config/rmpc')
| -rw-r--r-- | ar/.config/rmpc/config.ron | 33 | ||||
| -rwxr-xr-x | ar/.config/rmpc/scripts/on_song_change | 119 | ||||
| -rwxr-xr-x | ar/.config/rmpc/scripts/onresize | 4 |
3 files changed, 118 insertions, 38 deletions
diff --git a/ar/.config/rmpc/config.ron b/ar/.config/rmpc/config.ron index aaed946..892c7c7 100644 --- a/ar/.config/rmpc/config.ron +++ b/ar/.config/rmpc/config.ron @@ -5,8 +5,8 @@ address: "/tmp/mpd_socket", password: None, theme: "~/.config/rmpc/themes/catppuccin-mocha.ron", - cache_dir: "~/.cache/rmpc", - lyrics_dir: "~/.local/share/lyrics", + cache_dir: Some("~/.cache/rmpc"), + lyrics_dir: Some("~/.local/share/lyrics"), on_song_change: ["~/.config/rmpc/scripts/on_song_change"], on_resize: ["~/.config/rmpc/scripts/onresize"], extra_yt_dlp_args: ["--audio-quality", "0"], @@ -44,6 +44,7 @@ "3": SwitchToTab("Albums"), "4": SwitchToTab("Library"), "5": SwitchToTab("Playlists"), + "6": SwitchToTab("Lyrics"), "F": SwitchToTab("Search"), ":": CommandMode, "<": PreviousTrack, @@ -159,7 +160,7 @@ direction: Horizontal, panes: [ ( - size: "75%", + size: "65%", pane: Split( direction: Vertical, panes: [ @@ -203,7 +204,7 @@ ) ), ( - size: "25%", + size: "35%", pane: Split( direction: Vertical, panes: [ @@ -218,7 +219,7 @@ borders: "ALL", border_symbols: Inherited(parent: Rounded, top_left: "├", top_right: "┤",), border_title: [(kind: Text(" Lyrics "))], - border_title_alignment: Right, + border_title_alignment: Center, pane: Pane(Lyrics) ), ], @@ -278,6 +279,28 @@ ) ), ( + name: "Lyrics", + borders: "ALL", + border_symbols: Rounded, + pane: Split( + direction: Vertical, + panes: [ + ( + size: "30%", + pane: Split( + direction: Horizontal, + panes: [ + (pane: Pane(Empty()), size: "43%"), + (pane: Pane(AlbumArt), size: "14%"), + (pane: Pane(Empty()), size: "43%"), + ], + ), + ), + (pane: Pane(Lyrics), size: "70%", vertical_align: Bottom), + ], + ), + ), + ( name: "Search", borders: "ALL", border_symbols: Rounded, diff --git a/ar/.config/rmpc/scripts/on_song_change b/ar/.config/rmpc/scripts/on_song_change index 72a68ae..2899ab8 100755 --- a/ar/.config/rmpc/scripts/on_song_change +++ b/ar/.config/rmpc/scripts/on_song_change @@ -9,53 +9,110 @@ mkdir -p "$TMP_DIR" ALBUM_ART_PATH="$TMP_DIR/notification_cover" if ! rmpc albumart --output "$ALBUM_ART_PATH"; then - ALBUM_ART_PATH="" + ALBUM_ART_PATH="" fi if [ -n "$ALBUM_ART_PATH" ]; then - notify-send -i "$ALBUM_ART_PATH" "Now Playing" "$ARTIST - $TITLE" + notify-send -i "$ALBUM_ART_PATH" " Now Playing" "$ARTIST - $TITLE" else - notify-send "Now Playing" "$ARTIST - $TITLE" + 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" + rmpc sticker set "$FILE" "playCount" "1" else - rmpc sticker set "$FILE" "playCount" "$((sticker + 1))" + rmpc sticker set "$FILE" "playCount" "$((sticker + 1))" +fi + +# ── Auto album tag ─────────────────────────────────────────────────────────── +if [ -z "$ALBUM" ] && [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then + MUSIC_DIR="$HOME/Music" + SONG_PATH="$MUSIC_DIR/$FILE" + + result=$(curl -sG \ + --data-urlencode "term=$ARTIST $TITLE" \ + --data-urlencode "entity=song" \ + --data-urlencode "limit=1" \ + "https://itunes.apple.com/search") + + found_album=$(echo "$result" | jq -r '.results[0].collectionName') + found_artist=$(echo "$result" | jq -r '.results[0].artistName') + + if [ -n "$found_album" ] && [ "$found_album" != "null" ]; then + eyeD3 -A "$found_album" -a "$found_artist" "$SONG_PATH" 2>/dev/null + rmpc remote --pid "$PID" status "Set album: $found_album" --level info + else + rmpc remote --pid "$PID" status "Album not found for $ARTIST - $TITLE" --level warn + fi +fi + +# ── Auto album art download ────────────────────────────────────────────────── +if [ -z "$ALBUM_ART_PATH" ] && [ -n "$ALBUM" ] && [ -n "$ARTIST" ]; then + MUSIC_DIR="$HOME/Music" + SONG_PATH="$MUSIC_DIR/$FILE" + COVER_PATH="$TMP_DIR/cover.jpg" + + ARTWORK_URL=$(curl -sG \ + --data-urlencode "term=$ARTIST $ALBUM" \ + --data-urlencode "entity=album" \ + --data-urlencode "limit=1" \ + "https://itunes.apple.com/search" | jq -r '.results[0].artworkUrl100' | sed 's/100x100bb/600x600bb/') + + if [ -n "$ARTWORK_URL" ] && [ "$ARTWORK_URL" != "null" ]; then + curl -s -o "$COVER_PATH" "$ARTWORK_URL" + eyeD3 --add-image="$COVER_PATH:FRONT_COVER" "$SONG_PATH" 2>/dev/null + rmpc remote --pid "$PID" status "Downloaded album art for $ARTIST - $ALBUM" --level info + else + rmpc remote --pid "$PID" status "Album art not found for $ARTIST - $ALBUM" --level warn + fi fi # ── Auto lyrics download ────────────────────────────────────────────────────── LRCLIB_INSTANCE="https://lrclib.net" if [ "$HAS_LRC" = "false" ]; then - mkdir -p "$(dirname "$LRC_FILE")" + mkdir -p "$(dirname "$LRC_FILE")" + + # 1) /api/get with artist + title + album (exact match) + 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 // empty')" + + # 2) /api/get without album + if [ -z "$LYRICS" ]; then + LYRICS="$(curl -X GET -sG \ + -H "Lrclib-Client: rmpc-$VERSION" \ + --data-urlencode "artist_name=$ARTIST" \ + --data-urlencode "track_name=$TITLE" \ + "$LRCLIB_INSTANCE/api/get" | jq -r '.syncedLyrics // empty')" + fi + # 3) /api/search (fuzzy fallback) + if [ -z "$LYRICS" ]; then 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 + -H "Lrclib-Client: rmpc-$VERSION" \ + --data-urlencode "artist_name=$ARTIST" \ + --data-urlencode "track_name=$TITLE" \ + "$LRCLIB_INSTANCE/api/search" | jq -r '.[0].syncedLyrics // empty')" + fi + + if [ -z "$LYRICS" ]; 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 diff --git a/ar/.config/rmpc/scripts/onresize b/ar/.config/rmpc/scripts/onresize index 36462ce..183c210 100755 --- a/ar/.config/rmpc/scripts/onresize +++ b/ar/.config/rmpc/scripts/onresize @@ -1,7 +1,7 @@ #!/usr/bin/env bash if [[ $COLS -gt 100 ]]; then - rmpc remote --pid "$PID" set theme ~/.config/rmpc/themes/catppuccin-mocha.ron + rmpc remote --pid "$PID" set theme ~/.config/rmpc/themes/catppuccin-mocha.ron else - rmpc remote --pid "$PID" set theme ~/.config/rmpc/themes/catppuccin-mocha-small.ron + rmpc remote --pid "$PID" set theme ~/.config/rmpc/themes/catppuccin-mocha-small.ron fi |
