backdropper

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

backdropper

Unread post by tenkainen » Thu Aug 20, 2015 12:48 pm

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

Random terrible things.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: backdropper

Unread post by ChefIronBelly » Thu Aug 20, 2015 1:03 pm

Looks good, cool idea thanks for sharing.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Thu Aug 20, 2015 1:16 pm

Thanks.
To be perfectly honest I just needed a break from obsessing over xcolors matching my wallpaper. :-P
Random terrible things.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: backdropper

Unread post by ChefIronBelly » Thu Aug 20, 2015 1:28 pm

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 ;)
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: backdropper

Unread post by dkeg » Thu Aug 20, 2015 2:54 pm

Super cool! Is the full wall image separate than the image in the bottom right corner

Work hard; Complain less

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Thu Aug 20, 2015 3:14 pm

^Yes, imagemagick composite is run every time album changes.
My defaults are backdrop.jpg for the background and Folder.jpg for album art.
Random terrible things.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: backdropper

Unread post by dkeg » Thu Aug 20, 2015 3:37 pm

So you could change to only display album art as the smaller image while not setting the bg?

Work hard; Complain less

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Thu Aug 20, 2015 3:49 pm

^ 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.
Random terrible things.

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Thu Aug 20, 2015 4:14 pm

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

Last edited by tenkainen on Thu Aug 20, 2015 4:38 pm, edited 2 times in total.
Random terrible things.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: backdropper

Unread post by dkeg » Thu Aug 20, 2015 4:20 pm

Excellent man, going to test it out tonight!

Work hard; Complain less

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: backdropper

Unread post by wuxmedia » Thu Aug 20, 2015 5:46 pm

nice
don't see my wall much but good work!
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Thu Aug 20, 2015 6:25 pm

^ 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.
Random terrible things.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: backdropper

Unread post by rhowaldt » Fri Aug 21, 2015 4:57 am

wow, this is a really cool idea tenkai, fantastic! thanks for sharing! makes for a very immersive music-listening experience i bet :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Wed Aug 26, 2015 7:08 pm

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.
Attachments
backdropper.txt
Making wallpapers the way they were never meant and then some!
(3.92 KiB) Downloaded 163 times
Random terrible things.

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: backdropper

Unread post by ivanovnegro » Sun Aug 30, 2015 2:11 pm

A fantastic script. Maybe I will try it out. I never see the beautiful cover art and all folders have them actually.

User avatar
doubledutch
killall X
Posts: 163
Joined: Sun Aug 10, 2014 1:25 pm

Re: backdropper

Unread post by doubledutch » Fri Sep 18, 2015 1:28 am

Why isn't there a like button on this forum?
As a cmus/feh user I'm all-in. Love this, thanks!

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: backdropper

Unread post by rhowaldt » Fri Sep 18, 2015 4:41 am

no like button to encourage the use of actual words instead of shortcuts ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
tenkainen
applies for custom title
Posts: 49
Joined: Wed Feb 19, 2014 12:03 pm
Location: Finland

Re: backdropper

Unread post by tenkainen » Fri Sep 18, 2015 5:53 am

Thanks! I appreciate words even more than button presses. :-D
Random terrible things.

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: backdropper

Unread post by wuxmedia » Fri Sep 18, 2015 8:28 am

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.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: backdropper

Unread post by rhowaldt » Fri Sep 18, 2015 10:10 am

^ plus, grammatically incorrect :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

Post Reply