ncmpcpp-ueberzug icon indicating copy to clipboard operation
ncmpcpp-ueberzug copied to clipboard

Support for Mopidy-Spotify cover art

Open avma opened this issue 4 years ago • 5 comments

I like what you did very much! Thank you for that... I was using conky to grab lyrics and coverart with ncmpcpp, but what you did is much cooler ; ).

Attach is a piece of code I added ( not very professional I'm afraid but works) to yours that grabs covers through mpris, you might want to consider to better incorporate it :

# Determain audio source; Local or Spotify
MOD="$(mpc --format %file% current | cut -c1-7)"

find_cover_image() {
    # If audio source is 'potify' we grab cocer art using mpris
    IMGURL=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.mopidy /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | grep -E -A 1 "artUrl" | grep -E -v "artUrl"| cut -b 44- | cut -d '"' -f 1)


    if [ "$MOD" = "spotify" ]; then
        wget -q -O "/tmp/mpd_cover.jpg" "$IMGURL" &&
        cover_path="/tmp/mpd_cover.jpg" && return
    fi

    # we check if the audio file has an embedded album art
    ext="$(mpc --format %file% current | sed 's/^.*\.//')"
    if [ "$ext" = "flac" ]; then
        # since FFMPEG cannot export embedded FLAC art we use metaflac
        metaflac --export-picture-to=/tmp/mpd_cover.jpg \
            "$(mpc --format "$music_library"/%file% current)" &&
            cover_path="/tmp/mpd_cover.jpg" && return
    else
        ffmpeg -y -i "$(mpc --format "$music_library"/%file% | head -n 1)" \
            /tmp/mpd_cover.jpg &&
            cover_path="/tmp/mpd_cover.jpg" && return
    fi

    # If no embedded art was found we look inside the music file's directory
    album="$(mpc --format %album% current)"
    file="$(mpc --format %file% current)"
    album_dir="${file%/*}"
    album_dir="$music_library/$album_dir"
    found_covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f \
    -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\\(jpe?g\|png\|gif\|bmp\)" \; )"
    cover_path="$(echo "$found_covers" | head -n1)"
    if [ -n "$cover_path" ]; then
        return
    fi

    # If we still failed to find a cover image, we use the fallback
    if [ -z "$cover_path" ]; then
        cover_path=$fallback_image
    fi
}

avma avatar Dec 21 '20 11:12 avma

That's an amazing Idea. Maybe you open a pull request for him to merge your idea. It's morge the git way :)

dj-bauer avatar May 01 '21 17:05 dj-bauer

That's awesome!! Thanks for sharing @avma !

Barbaross93 avatar May 19 '21 03:05 Barbaross93

Just in case anyone else use this block of code and happens to have the same problem, the album art wouldn't always update. In fact, for certain albums, I can see the file in the tmp directory, but it wasn't updating in ncmpcpp. Changing wget -q -O... to curl -q --output... Solved it for me. No idea why this would matter. Maybe download speeds make a difference?

Barbaross93 avatar Jun 09 '21 14:06 Barbaross93

Not sure, they both works for me just fine and my download speeds is nothing to write hoe about ;-
anyway I do hope ncmpcpp officially adds something like this to their package.

avma avatar Jun 24 '21 16:06 avma

@avma Sorry for not attending to this repo but thank you so much for making this.

tam-carre avatar Mar 08 '22 16:03 tam-carre