Page 1 of 2

backdropper

Posted: Thu Aug 20, 2015 12:48 pm
by tenkainen
So, mpd being broken in sid repos I reverted back to my old favourite cmus.
Having purged myself a while ago from the bloatness of conky I now had no album art visible anywhere.
Decided to make something out of the cmus's status_display_program, so I made this little script.
It downloads (glyrc) backdrop (if one does now already exist) of the artist currently playing
(and album art if needed) and uses feh to make a nice wallpaper automanically.
I first tried setting album art tiled as background, but that was too psychedelic even for me.

So, heres a taste (sorry for quite speedy delivery): https://u.teknik.io/h0C2Pn.webm

Dependencies: glyrc, feh and imagemagick. (I tried to compensate for the lack of bloat with conky gone)
And here's the script itself:

Code: Select all

#!/bin/bash
# By tenkainen
# Makes the wallpaper from backdrops of artist currently playing, uses glyrc for it.
# Also fetches albumart if needed. Albumart in the same folder as track playing is used.
# --- This script only makes sense, if you use separate folder for different albums ---
# Other paths for albumart needs to be hacked together themself by the nutter using it and this script.
# Folder for backdrop can be adjusted in variables.
# Please, fill in the user defined variable below!

if [[ -z $(which glyrc) || -z $(which mogrify) || -z $(which feh) ]]
then
    echo -e "\e[31mGlyrc, imagemagick and feh needed to operate, smoothly.\e[00m"
    echo -e "\e[33mOn Debian: (sudo) apt install glyrc imagemagick feh\e[00m"
    exit 0
fi

# User defined variables
tmpdir="~/tmp"
genericbd="$tmpdir/generic_backdrop.jpg" # Used for albums glyrc can't find backdrop for
albumart="Folder.jpg"
player="cmus"
resolution="1920x1200"
wplocation="~/"
bdfolder="../" # ../ used the logic of Music/Artist/Artist-Album1/tracks.mp3 etc, so only one backdrop per artist
# ./ or empty can be used for backdrop.jpg for every album. Wasteful for large music collections.
# The actual existence of the folder in question is never checked. As not to make empty folders in some cases.

# ---------- ONLY CMUS SUPPORTED ATM, write your own below, if you really want -------------------
# Needed from the player: a means to get artist and album of the track playing and path to the actual file
# On Cmus, you can assign this script to the status_display_program variable
# so it updates the wallpaper automatically when playing music

if [[ "$player" == "cmus" && ! -z $(pgrep cmus) ]]
then
    artist=$(cmus-remote -Q | grep "tag artist" | cut -d ' ' -f 3-)
    album=$(cmus-remote -Q | grep "tag album" | cut -d ' ' -f 3-)
    npfile=$(cmus-remote -Q | grep file | cut -d ' ' -f 2-)
else
    echo -e "\e[31mNo compatible players found active.\e[00m"
    echo -e "\e[33mAlso, only Cmus supported, for now.\e[00m"
    exit 0
fi

npdir=$(dirname "${npfile}")
edartist=$(cat "$tmpdir"/npartist.txt | head -n 1)
edalbum=$(cat "$tmpdir"/npalbum.txt | head -n 1)
echo "$artist" > "$tmpdir"/npartist.txt
echo "$album" > "$tmpdir"/npalbum.txt


if [[ ! -a "$npdir/$bdfolder/backdrop.jpg" ]]
then
    glyrc backdrops -a "$artist" --write "$npdir/$bdfolder/backdrop.jpg"
fi
if [[ ! -a "$npdir/$albumart" ]]
then
    glyrc cover -a "$artist" -b "$album" --write "$npdir/$albumart"
fi


if [[ ! "$album" == "$edalbum" ]]
then
    if [[ -a "$npdir/$bdfolder/backdrop.jpg" ]]
    then
        bg_kuva="$npdir/$bdfolder/backdrop.jpg"
    else
        bg_kuva="$genericbd"
    fi

    fg_kuva="$npdir/$albumart"

    convert "$fg_kuva" -alpha set -channel A -evaluate set 80% "$tmpdir"/etu.png

    mogrify -resize $resolution! "$bg_kuva"
    composite -gravity SouthEast -geometry +10+10 "$tmpdir"/etu.png "$bg_kuva" "$wplocation"/wallpaper.png

    DISPLAY=:0.0; feh --bg-scale "$wplocation"/wallpaper.png
    rm "$tmpdir"/etu.png
fi


Re: backdropper

Posted: Thu Aug 20, 2015 1:03 pm
by ChefIronBelly
Looks good, cool idea thanks for sharing.

Re: backdropper

Posted: Thu Aug 20, 2015 1:16 pm
by tenkainen
Thanks.
To be perfectly honest I just needed a break from obsessing over xcolors matching my wallpaper. :-P

Re: backdropper

Posted: Thu Aug 20, 2015 1:28 pm
by ChefIronBelly
tenkainen wrote:Thanks.
To be perfectly honest I just needed a break from obsessing over xcolors matching my wallpaper. :-P
Ha I know that feeling ;)

Re: backdropper

Posted: Thu Aug 20, 2015 2:54 pm
by dkeg
Super cool! Is the full wall image separate than the image in the bottom right corner

Re: backdropper

Posted: Thu Aug 20, 2015 3:14 pm
by tenkainen
^Yes, imagemagick composite is run every time album changes.
My defaults are backdrop.jpg for the background and Folder.jpg for album art.

Re: backdropper

Posted: Thu Aug 20, 2015 3:37 pm
by dkeg
So you could change to only display album art as the smaller image while not setting the bg?

Re: backdropper

Posted: Thu Aug 20, 2015 3:49 pm
by tenkainen
^ Easily. And as one can see, it uses generic_backdrop.jpg for every artist glyrc can't find one for, so basically just commenting out the glyrc backdrops -line it could be used with a static wallpaper. (In this particular case on the condition the currently playing artist doesn't have a backdrop image already.)

But, just to clarify, this script does need (in it's current state) a background for imagemagick to composite the two images together. So xsetroot etc. won't work as such.

Now that I think about it, I could just modify it to use a user defined variable to either use backdrop or one static background image.

Re: backdropper

Posted: Thu Aug 20, 2015 4:14 pm
by tenkainen
Here you go, a (slightly) new version. Now if $usebd="no", it uses only $genericbd for the background image.
E: Changed the default variables to match ones from previous post. Also, if you wonder the few Finnish words
it's cause I've often used them as no (programming) language has them reserved for other purposes. They often
pop up in my scripts, even if I try to make these for the internets to use...

Code: Select all

#!/bin/bash
# v. 1.1 By tenkainen
# Makes the wallpaper from backdrops of artist currently playing, uses glyrc for it.
# Also fetches albumart if needed. Albumart in the same folder as track playing is used.
# --- This script only makes sense, if you use separate folder for different albums ---
# Other paths for albumart needs to be hacked together themself by the nutter using it and this script.
# Folder for backdrop can be adjusted in variables.
# Please, fill in the user defined variable below!

if [[ -z $(which glyrc) || -z $(which mogrify) || -z $(which feh) ]]
then
    echo -e "\e[31mGlyrc, imagemagick and feh needed to operate, smoothly.\e[00m"
    echo -e "\e[33mOn Debian: (sudo) apt install glyrc imagemagick feh\e[00m"
    exit 0
fi

# User defined variables
tmpdir="~/tmp"
genericbd="$tmpdir/generic_backdrop.jpg" # Used for albums glyrc can't find backdrop for
usebd="yes" # no (or anything else) to use one particular image, not an artist backdrop
albumart="Folder.jpg"
player="cmus"
resolution="1920x1200"
wplocation="~/"
bdfolder="../" # ../ used the logic of Music/Artist/Artist-Album1/tracks.mp3 etc, so only one backdrop per artist
# ./ or empty can be used for backdrop.jpg for every album. Wasteful for large music collections.
# The actual existence of the folder in question is never checked. As not to make empty folders in some cases.

# ---------- ONLY CMUS SUPPORTED ATM, write your own below, if you really want -------------------
# Needed from the player: a means to get artist and album of the track playing and path to the actual file
# On Cmus, you can assign this script to the status_display_program variable
# so it updates the wallpaper automatically when playing music

if [[ "$player" == "cmus" && ! -z $(pgrep cmus) ]]
then
    artist=$(cmus-remote -Q | grep "tag artist" | cut -d ' ' -f 3-)
    album=$(cmus-remote -Q | grep "tag album" | cut -d ' ' -f 3-)
    npfile=$(cmus-remote -Q | grep file | cut -d ' ' -f 2-)
else
    echo -e "\e[31mNo compatible players found active.\e[00m"
    echo -e "\e[33mAlso, only Cmus supported, for now.\e[00m"
    exit 0
fi

npdir=$(dirname "${npfile}")
edartist=$(cat "$tmpdir"/npartist.txt | head -n 1)
edalbum=$(cat "$tmpdir"/npalbum.txt | head -n 1)
echo "$artist" > "$tmpdir"/npartist.txt
echo "$album" > "$tmpdir"/npalbum.txt

# Check if albumart and backdrop (if needed) exist and download if not
if [[ ! -a "$npdir/$bdfolder/backdrop.jpg" && "$usebd" == "yes" ]]
then
    glyrc backdrops -a "$artist" --write "$npdir/$bdfolder/backdrop.jpg"
fi
if [[ ! -a "$npdir/$albumart" ]]
then
    glyrc cover -a "$artist" -b "$album" --write "$npdir/$albumart"
fi

# If album has changed, new background is made
if [[ ! "$album" == "$edalbum" ]]
then
    if [[ -a "$npdir/$bdfolder/backdrop.jpg" && "$usebd" == "yes" ]]
    then
        bg_kuva="$npdir/$bdfolder/backdrop.jpg"
    else
        bg_kuva="$genericbd"
    fi

    fg_kuva="$npdir/$albumart"

    convert "$fg_kuva" -alpha set -channel A -evaluate set 80% "$tmpdir"/etu.png

    mogrify -resize $resolution! "$bg_kuva"
    composite -gravity SouthEast -geometry +10+10 "$tmpdir"/etu.png "$bg_kuva" "$wplocation"/wallpaper.png

    DISPLAY=:0.0; feh --bg-scale "$wplocation"/wallpaper.png
    rm "$tmpdir"/etu.png
fi


Re: backdropper

Posted: Thu Aug 20, 2015 4:20 pm
by dkeg
Excellent man, going to test it out tonight!

Re: backdropper

Posted: Thu Aug 20, 2015 5:46 pm
by wuxmedia
nice
don't see my wall much but good work!

Re: backdropper

Posted: Thu Aug 20, 2015 6:25 pm
by tenkainen
^ Me neither, just some that shines through the gaps between windows in hlwm.
But now I've gotten used to put an empty workspace when I leave the computer.

Re: backdropper

Posted: Fri Aug 21, 2015 4:57 am
by rhowaldt
wow, this is a really cool idea tenkai, fantastic! thanks for sharing! makes for a very immersive music-listening experience i bet :)

Re: backdropper

Posted: Wed Aug 26, 2015 7:08 pm
by tenkainen
Boredom led to:
- support for moc as player
- mpd got fixed in sid today, so there's that now

If player is mpd one needs mpc too for this to work. (Ncmpcpp has the much needed execute on song change, don't know about other clients)
Moc at least is pretty much self supportive.

Also, added the script as an attachment to not make another wall of bad scripture.
Try to rename it, couldn't attach .sh or without extension, so .txt it is.

Re: backdropper

Posted: Sun Aug 30, 2015 2:11 pm
by ivanovnegro
A fantastic script. Maybe I will try it out. I never see the beautiful cover art and all folders have them actually.

Re: backdropper

Posted: Fri Sep 18, 2015 1:28 am
by doubledutch
Why isn't there a like button on this forum?
As a cmus/feh user I'm all-in. Love this, thanks!

Re: backdropper

Posted: Fri Sep 18, 2015 4:41 am
by rhowaldt
no like button to encourage the use of actual words instead of shortcuts ;)

Re: backdropper

Posted: Fri Sep 18, 2015 5:53 am
by tenkainen
Thanks! I appreciate words even more than button presses. :-D

Re: backdropper

Posted: Fri Sep 18, 2015 8:28 am
by wuxmedia
wuxmedia and 6 others likes this post.
that's just cold...
Most phpbb boards I've been active on have gone a similar "how about using words to say 'thank you'" way.

Re: backdropper

Posted: Fri Sep 18, 2015 10:10 am
by rhowaldt
^ plus, grammatically incorrect :D