Albumart.py - displays mpd album art

I love ncmpcpp but, sadly, it does not display all the beautiful album art I've collected. So I wrote this little Python script  (75 lines) that does just that.
Here's a demo: http://a.pomf.se/wlozbq.mp4
It monitors mpd and searches for an image in the directory of the currently playing file, but you have to tell it mpd's music directory (MUSICDIR). You set PATTERN as how your album art is named, in globbing format. In my case that's Folder.* for Folder.jpg or Folder.png
It also needs a default image (DEFAULTIMG) in case it doesn't find any album art.
It then displays that image and scales it to the window size. The image proportions are kept, so it might fill some space with a background color that you can set (BGCOLOR).
Close the window to quit.
It requires python-mpd2 from the AUR, python-pillow and tk. I'm not an enterprise programmer so forgive me if the code is shitty. In any case, it's simple and light.
#!/usr/bin/env python
# Requires python-mpd2, python-pillow, tk
from tkinter import Tk, Frame, Label
from PIL import ImageTk, Image
from threading import Thread
import mpd, sys
import glob, re
# Required variables
MUSICDIR = "/home/rolf/Music/"
PATTERN = "Folder.*"
DEFAULTIMG = "/home/rolf/.icons/defaultimg.png"
BGCOLOR = "#1c1c1c"
# Frame class that draws an image and zooms it to the window size
class ImageFrame(Frame):
def __init__(self, master, imgPath, *pargs):
Frame.__init__(self, master, *pargs)
self.img = Image.open(imgPath)
self.origImg = self.img.copy()
self.bgImg = ImageTk.PhotoImage(self.img)
self.bg = Label(self, image=self.bgImg, background=BGCOLOR)
self.bg.pack(fill="both", expand="yes")
self.bg.bind('<Configure>', self._resize_image)
def _resize_image(self, event):
s = min(event.width, event.height)
self.img = self.origImg.resize((s, s), Image.ANTIALIAS)
self.bgImg = ImageTk.PhotoImage(self.img)
self.bg.configure(image=self.bgImg)
def change_image(self, imgPath):
self.img = Image.open(imgPath)
self.origImg = self.img.copy()
self.bg.event_generate('<Configure>', width=self.winfo_width(), height=self.winfo_height())
# Connect with mpd server
try:
client = mpd.MPDClient()
client.connect("localhost", 6600)
except(mpd.ConnectionError):
print("Could not connect to MPD. Exiting.")
sys.exit(1)
# Function to look for albumart according to PATTERN in MUSICDIR/<song's directory>/
def get_albumart(song):
albumArt = DEFAULTIMG
if(song != "STOPPED"):
aaDir = re.sub(r"[^/]*$", "", song["file"])
for albumArt in glob.glob(MUSICDIR + aaDir + PATTERN):
break
return(albumArt)
# The window
root = Tk()
root.title("album art")
imgFrame = ImageFrame(root, get_albumart(client.currentsong()))
imgFrame.pack(fill="both", expand="yes")
# Function that monitors mpd for changes and if so, makes the ImageFrame redraw
def poll():
currentSong = client.currentsong()
while True:
client.idle("player")
previousSong = currentSong
currentSong = client.currentsong()
if(client.status()["state"] == "stop"):
currentSong = "STOPPED"
if(previousSong != currentSong):
imgFrame.change_image(get_albumart(currentSong))
# Start shit up
Thread(target=poll, daemon=True).start()
root.mainloop()
Last edited by doggone (Yesterday 13:48:34)

Since that simple script of r6 was so helpful for me, I thought it only fair for me to provide my tweak to it.
Mods:
* Fetched from albumart.org
* Uses directory path for search information
* downloads larger image instead of thumbnail
* works with find -exec {} to auto populate all directories
Here is a link to my simple write up
I just run the following in the root of my music directory
find . -type d -exec ./get_coverart {} \;
And a copy of the script
#!/bin/bash -e
# get_coverart.sh
# This simple script will fetch the cover art for the album information provided on the command line.
# It will then download that cover image, and place it into the child directory.
# The term "album information" is really the relative path of the final directory.
# get_coverart <relative-path>
# get_coverart Tonic/Lemon Parade
# get_coverart Tonic/Lemon\ Parade
# get_coverart Tonic/Lemon_Parade
# To auto-populate all directories in the current directory, run the following command
# find . -type d -exec ./get_coverart "{}" \;
dpath="$1"
encoded="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$dpath")"
# Skip already processed ones
if [ -f "$dpath/cover.jpg" ]
then
echo "$dpath/cover.jpg already exists"
exit
fi
echo ""
echo "Searching for: [$1]"
url="http://www.albumart.org/index.php?srchkey=$encoded&itempage=1&newsearch=1&searchindex=Music"
echo "Searching ... [$url]"
coverurl=`wget -qO - $url | xmllint --html --xpath 'string(//a[@title="View larger image" and starts-with(@href, "http://ecx.images-amazon")]/@href)' - 2>/dev/null`
echo "Cover URL: [$coverurl]"
wget "$coverurl" -O "$dpath/cover.jpg"
Last edited by Skidd (2011-03-10 03:53:35)

Similar Messages

  • IPad doesn't display correct album art

    I could really use some help here, I am at the end of my rope.  I have HomeSharing on so that my iPads and iPhones will play music and movies from our iTunes library.  I have an iPhone 5, an iPhone 4S, an iPad 4 and (2) iPad 2 models.  Both iPhones and the iPad 4 will display the correct album art in the movies but the iPad 2's scramble up the album art.  For instance on the iPad 4 shows the Aladdin album art where it says Aladdin is but on the iPad 2 (both of them) it will display random album art.  So you'll be looking at a picture of Bug's Life but the line states that the movie is Aladdin.  Now when you select that movie and it enters the info page where the play button is, the album art comes up correctly.  It's just in the title screen or selection screen this happens.  Then to add to that, the music and music videos all displays fine, the correct album art every time.  For some reason, this is only happening in the movies.  And again, only happening on the iPad 2's.  There is no issue with the newer iPad or the iPhones.  So is this a setting that is goofed?  A software issue that I can't resolve?  I would appreciate any input you can provide, especially if you can help me fix this!! 
    FYI, the iPad 2's are my daughter's so I have the PG restriction on making sure that they can't watch anything PG-13 or over.  Although it won't display a PG-13 or over movie, it will display the album art (for instance it will show Hills Have Eyes instead of Aladdin although the text shows Aladdin and again, if you click on it the correct album art shows Aladdin in the info screen).  I thought maybe the restrictions were the problem so I shut them off but that didn't resolve the issue.

    Me Too. Glad to hear I'm not alone in this...
    I can't explain it. All my songs show the correct art in iTunes but it's often mismatched on the Nano. I've noticed that selecting a problem track in iTunes, get info and clicking "ok" on the already correct art, sometimes corrects the issue (for that one track) on the Nano after the next sync.. but not always.
    p.s. Other posts say "restore" is the answer. I'll try that tonight.

  • Problems displaying SOME album art for Home Movies in iTunes 11.1.4

    I have a number of home videos in my iTunes 11.1.4 library on my Mac.  I have manually added album art to each video, but only about half the movies actually show the album art when viewing the movies from the Home Videos tab in iTunes.  The other half of the movies just show a frame of the movie.  I double checked Get Info for the movies that aren't displayed the album art and confirmed that the album art is listed.  All the album art I uploaded is of the same size and file type.  Not sure why half the art displays and half doesn't.  Anyone else see this before?  I'm puzzled.
    Thanks

    I don't know if you got your answer this this post is from about 3 months ago. I've also been having the same issue.
    On my end, I've been keeping all of my movie files on an external drive and just as your situation, only some of them appear and some of them are missing. I don't know if it's as a result of having them on an external drive and anytime I launch iTunes, it's not always plugged in. I'd have to do a bit more testing on that.
    I did notice that as soon as I select the "Get Info" on a movie file with missing artwork and confirm that it's there in the metadata by just clicking "ok", it appears automatically in the iTunes window. Seems like a quick and easy solution for now, but not so if you have 300+ movies and you have to do the step for every other one.
    If you figured out a solution for this or what worked for you, I'd be glad to hear it.

  • How do i get itunes 11 to display my album art while in list mode like it did in the previous version?

    How do i get itunes 11 to display my album art while in list mode like it did in the previous version?

    I think the Sidebar preview image is gone. But found that when I'm playing music either from the entire library or a playlist you can click the tiny thumbnail at the top to open a Artwork based player that is scalable. Reduce (minimize) the main Itunes window and the player is actually Nice.  Hope that helps.

  • Vid iPod displays incorrect album art

    My video iPod has started to display incorrect album art when playing back songs. The songs and their corresponding album art play back fine in iTunes on my computer. But when playing back on the iPod, it displays the wrong album covers. Any ideas on how to fix this?

    Same problem. I am still lokking for a fix for my 5G pod.

  • Front Row not displaying all Album Art

    Hi, I recently bought a Macbook Pro and imported all the music I had to it. I started downloading all the album arts for all my albums, and finally placed them all in order. They look perfect in iTunes in Coverflow.
    Then, when I started Front Row, I noticed that not all of my songs displayed an Album Art, only some of them. Does anyone know how to solve this problem?

    Similar discussion here with a possible fix:
    http://discussions.apple.com/thread.jspa?threadID=1201950&tstart=15
    Message was edited by: Sith Happens

  • Displaying ipod album art in itunes

    I have a question about the iPod's display of album art in iTunes when it is plugged into my computer. I had been getting really frustrated for the better part of the evening after adding a bunch of album art to my music, updating it on the iPod (I do manual update so I dragged the songs onto the iPod after adding the art), and then clicking on them in the iPod's library in iTunes only to see that there was no album art there. What gives?
    However, I realized that I was getting annoyed for no reason when I checked it out in the iPod itself, after I disconnected it. All of the album art is there.
    So here is the strange behavior I have observed this evening: if I had to go out on the internet and find cover art myself, and add it manually to the files in iTunes, it displays in the iPod's library in iTunes. If iTunes helpfully went out and found the cover art for me automatically, it does NOT display in the iPod library in iTunes (although it is actually there when you go to play the music on the disconnected iPod). I went through the iPod's library in iTunes and this is consistently what is happening.
    Obviously this isn't a life-or-death kind of situation, but I was wondering if anyone else has noticed this behavior or knows why this happening. For what it's worth, my entire iTunes library is on an external hard drive, and all of my music is on there in the same place. Do you think iTunes is storing the art in separate places depending on whether I added it or it found it on its own? Would this even matter? I am very curious about this. Thanks for any insight anyone has for me.
    5g iPod (video) 80 GB   Mac OS X (10.4.8)   iTunes 7

    when i play the music on the iPod the albums show up
    no problem... but when the iPod is connected to
    iTunes, and i'm browsing my ipod via itunes, only
    some album art shows up...
    IE: beck guero, has album art in the itunes library,
    it also has the art on the ipod if i play it with the
    ipod disconnected from my mac. it DOES NOT show album
    art when connected to itunes and view the ipod within
    itunes...
    whats the deal? some albums are just fine, but the
    vast majority of them dont display the art while in
    itunes... again, if i disconnect the ipod and view
    them on the ipod, there is no problem all albums
    display.
    any help is appreciated.
    Just so you know, you're not going crazy and you're not the only one that's seeing this. I'm seeing the same behavior with a 30GB 5G iPod and iTunes7 under Windows XP.
    30GB 5G iPod with 1.2 firmware   Windows XP   iTunes 7

  • How can I display all album art of my library in iTunes

    All my music tracks in my library contain the respective album art within their ID3-tags and it is perfectly displayed in the lower left corner window when I select or play a track.
    What I really would like to do is to browse through my library using the album art, not the text-based endless lists (title, album, interpret, genre etc.), then click on a cover, see the tracks and select one.
    Is there a feature in iTunes already that can do that or a plug-in somewhere in the market ? (I do not need a tool that collects album art like eyejamz, but a tool to display the art I already have)
    Thanks a lot for any feedback
    bigfoot9
    iPod shuffle   Windows XP  

    Bakergirl,
    You can use iTunes to remove the beginning or end of a song (or both) by setting the Start and Stop times. 
    But to remove a section from the middle and keep the rest, you will need an audio editor such as Audacity.

  • Itune display correct album art but i touch shows wrong album in genius mix

    Hi there im using itunes 9.1.0.79 and i have an ipod touch 2g running version 3.1.3
    Now the problem is the genius mixes on itunes is showing correct album art i.e. each of the four mixes are composed of four album art
    ON ITUNES DANCE POP MIX CONSISTS OF SPICE GIRLS,LADY GAGA, KC AND SUNSHINE BAND AND AQUA.
    THE SAME DANCE POP MIX DISPLAYS MICHAEL JACKSON, BRITNEY SPEARS, TATU AND SPICE GIRLS ON MY IPOD WHERE AS THE SONGS UNDER THE LIST ARE SAME ON THE COMPUTER AND MY IPOD
    THERE IS A SAME PROBLEM WITH THE REST OF THE MIXES
    EVERYTHING ELSE IS WORKING FINE ON THE IPOD EXCEPT THIS
    can someone please help me find a solution and is anyone else also facing this problem......

    You don't have a problem, and there is not solution. The album art you see for a genius mix is a representative sample of the albums contained in that mix. It is not all inclusive, there are other albums in that mix. When you mouse over a genius mix in iTunes, you'll see below the mix title that that mix is based on Artist A, Artist B, Artist C and others. When you play a mix, you'll see the album art changes from 4 covers to the album cover for the song now playing.
    If you sync a mix to your iPhone/iPod Touch, the four covers will not be the same as those in iTunes, they will be 4 covers representing the albums included in that mix; however the description of the mix under the 4 covers will be the same as it is in iTunes. When you play a mix on your device, the art displayed is the art from the now playing song.
    Mixes are not playlists, they are mixes of songs that sound good together. If you play a dance pop mix, it should be like tuning a radio to a dance pop station.
    Bottom line, it is what it is. Listen and enjoy. Don't obsess about the minor details.

  • Tracks often displaying incorrect album art in playlist and podcast modes

    Strange one this, and not at all consistent.
    I'm often noticing that the album art for another unrelated album is being displayed when I am playing music from a playlist or playing a podcast.
    Any ideas how to stop my iPod Touch doing this, and to display the correct artwork?

    I too have the exact same problem, and pretty often too. It's really a pain when I've taken the time to find almost all of the correct artwork for all 18,000+ songs (92+ GB) in my iTunes library, and yet it won't be displayed correctly on my iPhone. I've tried countless reset's, restore's, starting fresh with a new library, etc. Nothing I can think of works. Does anyone have a successful solution? I sometimes get an error when trying to update my iPhone 3GS with the number (-6999) at the end of it. I'm wondering if there's any correlation there...

  • #g: how do you display coverflow/album art ?

    Hi,
    I was just wondering how and if Album art is displayed on the 3G?
    I downloaded the same tunes that display album art on my Nano... but they don't seem to display on the 3G. Do I have to turn this feature on?
    When playing tunes on the iPhone what happens when a call is made or received?
    Thanks

    Did you turn your iPhone sideways? If so, what does it display?
    If a call comes in the music fades out and you have a display that allows you to answer or reject the call.

  • IPod Nano (1st gen) Displays Incorrect album art.

    I woke up this morning and went for a bike ride with my nano when I realized it was showing incorrect album art for some of the songs. I have not noticed any pattern. I also have a 60gb photo that IS showing the correct album art so I'm pretty sure its just the nano (I updated them both today to check, and still same situation). I have tried restarting the iPod already. Anyone know what I should do?

    If your iPod is set to update automatically then try this:
    iTunes 6
    1. Connect your iPod
    2. Disable "Show Album art" in iTunes>Edit>Preferences>iPod.
    3. Syncronise the iPod with iTunes. (Disconnecting and then reconnecting your iPod will do the trick)
    4. Re-enable "Show Album Art" in iTunes>Edit>Preferences>iPod.
    5. Syncronise the iPod again.
    iTunes 7
    1. Connect your iPod
    2. Disable "Display album artwork" in iPod>Music tab and click Apply.
    3. Syncronise the iPod with iTunes.
    4. Re-enable "Display album artwork" in iPod>Music tab and click Apply.
    5. Syncronise the iPod again.

  • Ipod displays wrong album art & skips entire songs since updating to 1.2

    I recently got the new itunes update and the ipod update 1.2, and ever since that it has been skipping entire batches of songs and shows wrong album art for the songs that DO play. I have a 30 Gig Video
      Windows XP  

    Try this: Open itunes> plug in your ipod> select your ipod icon> click the music tab> uncheck the box that says display alblum artwork (unless its already unchecked)> click apply> check the same box again> click apply. If all else fails you can restore your ipod and the artwork will come with it.
    kEat0n

  • IPod displays incorrect album art for some songs

    Hi, I hope someone can help. I've tried a bunch of things and I'm still having problems with some of my album art. They display fine in iTunes and other music players, but sometimes not on my iPod. Sometimes it'll display a different album cover than it should, and it kinda annoys me. The only thing I can do is to open the iPod in iTunes, delete the song off the iPod and drag it back on. I think I've had this problem with songs I've brought back in though. Also, once the wrong art is displayed, it remeains that way unless I delete the song and replace (like I just said). I thought maybe the iPod was stressed by starting up, so I tried running through all songs figuring it would endure less stress, therefore displaying the right album art, and thus it would remember the artwork than me, but artwork still messed up
    I tried the diplay album art setting in iTunes
    running through songs on iPod
    I started in automatic update and now I'm in manual update, but this problem occurred in both
    Please Help me, someone!!!
    -Jim

    Welcome to Apple Discussions!
    See if the steps in this link help...
    btabz: My songs have artwork in iTunes, but it won't transfer to my iPod!
    btabz

  • IPod displays random album art that I've never added or downloaded

    I've noticed sometimes that album art on my iPod would be missing or displaying art from another album or track in my library but what I noticed today is really confusing me.
    I've noticed a couple of albums so far are displaying weird images that I've never downloaded or added to iTunes. They aren't from another album, track or podcast. One is of the Golden Girls posing with their Emmys! How did this random artwork get applied to tracks on my iPod? The artwork is perfectly fine in iTunes and the thumbnails in the iPod's list view tend to be correct as well. It only shows up when I play the track or album.
    No one has been using my iPod, plus I have a passcode on it. It seems like a restore is in order but I'm just curious to know if others have had this problem and know the cause.

    I'm not running iOS 5 but it could be related to iTunes. The artwork seems to be completely out of the blue but I'm still seeing regular artwork being mixed up from album to album. The other weird images I don't recognize could possibly be from chapters in some podcasts that I never noticed before, I suppose.
    A full restore of the iPod is likely the only solution to this fix I would guess.

Maybe you are looking for

  • Reading from socket inputstream returns -1

    I'm using a socket in order to connect to a chat server. The code is: Socket socket; InputStreamReader isr; OutputStreamWriter osw; try {   socket = new Socket(sHost, iPort);   isr = new InputStreamReader(socket.getInputStream());   osw = new OutputS

  • Making a Swf a valid widget

    I have a swf carousel that will work sat inside an HTML file for the purposes of siting on a web page. What as3 code do I need to make this a valid widget? I don't actually need it to interact with the captivate project, but I need the user to be abl

  • Maintain local in-house jar files while java plug-in is upgraded

    I have some in-house developed jar files which are kept at C:\Program Files\Java\jre_xxx\lib\applet. However, starting from Jre 1.4.2, there is an "autoupdate" feature which allows auto-download and installation of newer version of JRE to the client

  • HT4259 Does Airport Express extended network inherits wifi time restrictions?

    Hello: I have created a network with my Airport Extreme and I've set up some wifi access time restrictions based on mac addresses. Now I want to extend this network adding an Airport Express at the living room. Everything went smooth but I'd like to

  • Full scratch disk

    I am trying to reinstall adobe photoshop 7.0 on a replacement desktop computer. HP with Windows 7 64bit and 750GB ha rd drive. Also have a Seagate 2TB external d rive. When I try to launch Adobe I get a message that Adobe ca nnot launch because the s