Embedded Album Covers, Your PSP, Amarok, and You
Sunday December 9, 2007
So… first off, I Googled for Amarok, hoping to find some new sweet pixels and instead I find this. Um… so not the Amarok that I know and love.
Anyway, a couple of years ago, I won a PSP from the LinuxWorld convention. Being that I’m a geek, it was love at first boot jingle. Being that I am married, have 3 kids, work full-time++, and try to hack every once in a while, the brave little PSP spent a lot of alone time. Oh sure, I own several PSP games (go SOCOM2!!), but that’s about it.
Until now.
Since I’m lucky enough to be able to work from home for a bit, I’m not driving back and forth to work every day and as such, I gave my iPod to my darling daughter. So I bought a 4G memory stick (oh, that reminds me, I need to blog about stupid, evil, skanky eBay sellers of fraudulent flash memory, since I wasted my time with one personally…) (but for non-fraudulent and kick-butt flash, I highly recommend SanDisk’s Gaming Pro Duo… it’s uber fast) (and that’s enough parenthetical statements for one sentence). And, having this nice little PSP and 4G of disk space on it now, I’ve been figuring out how to put stuff of interest onto it.
Movies: Totally cool. The PSP has a 480×272 screen. Handbrake does a really nice job of ripping a DVD and creating an mp4 that the PSP can play perfectly. Really, really nice. Oooh, and the new PSP OS has this nifty little auto-generating movie browser thingey that is kind of like a scene selector on a DVD movie… lets you see scene selections for the movie at configurable intervals too… Anyway, the only beef I have with Handbrake thus far is that it doesn’t allow me to increase the volume on the ripped movie. So I’m looking at ffmpeg now to see if it does as good a job as Handbrake. I’m sure I’ll blog more about that later.
Music: Really cool here too. The PSP plays a variety of audio formats and has some really nice eye candy/visualizations/etc. for your music-listening pleasure. However (and this is what actually what prompted this post), it shows album covers per song only if they’re embedded as APIC frames in your mp3’s ID3 tag. Now, I’m new to this, and didn’t know that there were such animals as APIC frames until just yesterday, but I did know that I wanted to put my album art into my little mp3s so that they’d show up all purty-like on my PSP (there, full circle now).
So, I’ve put in the usual geekly late night or two (yes, dear, I’m honestly coming to bed… in a sec…) and learned much about ID3 tags and the various tools that one might employ in one’s attempt to embed album covers in one’s mp3s. I even bugged my good friend Seb, who pointed me to a really cool “EmbedCover” script for amarok that I didn’t know existed. But, along the learning curve, I saw a lot of complaints about Amarok showing distorted embedded album covers. My problem was slightly different in that I couldn’t figure out how to get them embedded in the first place, let alone getting them there and then finding them distorted. Through trial and error (and aforementioned geekly late nights), I think I’ve found a consistent way to get album covers to be embedded and why they might show up distorted in Amarok (and other players too, mind you–it’s not Amarok’s fault).
The first step in getting album cover art embedded in my mp3s was to get a picture into each directory of my music. I organize things like this: “Artist – Album/Artist – Title.mp3”, and in each folder, I want an album cover file. One way to do this is an amarok script called CopyCover. Assuming that you’ve first found all album art for your music via Amarok’s cover manager, CopyCover will, as you are playing your music, copy the album art from Amarok’s cache into the folder for your music and call it “cover.png”. There’s also an offline script that is supposed to do the job all at once instead of you having to do it the song-by-song way, but I couldn’t get it to work for me… I think the database schema changed behind its back. An alternate route (and this is what I did) was to tell Amarok to organize all of my music for me (highlight all tracks in player and right-click, “Manage Files” | “Organize Files”, and then click the “use cover art for folder icons” checkbox. Amarok will put a “.desktop” file in each of your folders and the “Icon” attribute will point to Amarok’s cached album cover. I then wrote this simple function to copy this album art into the folder itself:
function albumcoversfromamarok() {
for f in *
do
count=$(ls –color=never $f | grep mp3| wc -l)
echo “$count : $f”
if [ $count -gt 0 ]
then
icon=$(cat “$f/.directory” 2>/dev/null | egrep “^Icon” | cut -d “=” -f2)
[ -e “$icon” ] && cp “$icon” “$f/cover.png”
fi
done
}
I then wrote 2 more simple functions that will rip through all of my folders and embed the updated album art into my mp3s:
function mp3albumcoverdir() {
if [ -e “cover.png” ]
then
convert -quality 90 -geometry 300×300\> cover.png cover.jpg
else
return
fi
for f in *.mp3
do
echo “Embedding cover in: [$f]”
mp3albumcover “$f” cover.jpg
done
}function mp3albumcover() {
FILENAME=”$1″
IMAGE=”$2″# first, remove existing images
# do this for FRONT_COVER and OTHER APIC types and twice just to make sure we’re clean
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1# now, get rid of cruft left behind by previous images
id3v2 –APIC “” “$FILENAME” >/dev/null# make sure we have a valid id3 tag
eyeD3 –to-v2.3 “$FILENAME” >/dev/null 2>&1
# now embed the image
eyeD3 –add-image=”$IMAGE”:FRONT_COVER “$FILENAME”
}
Then I run it from the top level of my music collection with “for f in *; do; mp3albumcoverdir “$f”; done”.
Now, along the way, whenever I found an incorrect album cover embedded and tried to fix it by removing the previous album art and adding the new one, I started seeing the corrupted images in amarok that I’d been reading about. And it’s not just that amarok wasn’t able to read the images… they were truly corrupt. “eyeD3 –write-images=. $FILE” produced a corrupt image as well. And, every time I cleared the previous image and added a new one with eyeD3, I noticed that my filesize kept getting bigger and bigger. Even when I “removed” all images with eyeD3’s “–add-image=:FRONT_COVER”, the filesize of the mp3 just kept getting bigger. It was then that I tried setting the APIC frame to null (“”) with id3v2, and that returned my mp3’s filesize back to where it should be. And after that, if I added the album art to the mp3, it added it cleanly, my filesize looked sane again, and Amarok was able to see the embedded album art again.
So, my theory, which is mine, and belongs to me and I own it, and what it is too, is that people who are seeing album art distortions/corruptions in amarok might possibly have files that either have more than one embedded picture, or have dirty APIC tags. If any of you, dear readers, is seeing embedded album art distortion in Amarok, would you please install id3v2 and eyeD3 onto your little Linux box and try running my mp3albumcover function against that mp3 with a new album image? I’d very much like to see if it fixes the problem for you.
As an open-source fan, you owe it to yourself to install a custom firmware on your PSP.
Then you’ll be able to do an awful lot more – including using the open-source cross-compiler toolchain to develop your own apps for it.
Heh. Which firmware do you recommend for me to install, might I ask? I’ll admit right up front that I don’t feel compelled to put a Linux OS on every device that I own, honestly. I’m pretty darned pleased with the PSP’s functionality as a multi-media/gaming device. I don’t need it to do much more than it does… I have a Palm 700p for that. =:) And I haven’t yet hit any “oh, golly, I sure wish this thing could do X”, so I’ve no itches that I need to scratch.
That is the album that Amarok was named after. Load it up and play it in Amarok and it pops up a nice wee Easter Egg notice telling you so. Its also a very good album as well.
@neil: Wow, so, that’s really interesting. But I just listened to a sample of this masterpiece and… I guess it’s just not my bag, baybee…. =;)
I agree, the craze for Linux on everything is over the top.
The PSP custom firmwares basically focus on small patches to the existing official firmware, mostly to remove the DRM that prevents unofficial applications from being run, but also small tweaks such as allowing underclocking of the unit for extra battery life, etc.
There’s a huge amount of unofficial software available, of varying quality. The bulk of it tends to be homebrewed games, but there are also some useful apps – e.g. shoutcast players, satnav, file managers, alarm clocks etc. There’s an out-of-date list at http://www.psp-homebrew.eu that should give some idea of the range.
The leader of the pack as far as custom firmware goes is the M33 series – it’s probably best to view the how-tos, e.g. at forums.noobz.eu, forums.pspupdates.com, or similar large PSP sites for info on how to install it – it’s not very straightforward, sadly.
Hi.
I have a folder icon with the following code and path inside the desktop.ini inside the folder:
[ViewState]
Mode=
Vid=
FolderType=Music
Logo=
[.ShellClassInfo]
IconResource=D:\Music\Carlos Santana\santana.ico,0
If I now change the path to
.\santana.ico,0
or
.\santana.ico
or even
./santana.ico
like described here the folder icon won’t show anymore.
What I want to do is if the folders gets moved to another PC and the drive letter is then F”\ instead of D:\ or whatever drive letter there is that the folder icons still show.
Please give me a hand here.
Thanks in advance,
Cheng
Hi Cheng!
I think that you’re talking about Windows desktop files?? I can’t help ya there. I run Linux and the Linux “.directory” file that is produced for Amarok’s organized folders is very simple and looks like this:
…….thanks for the quick reply.
The tutorial about adding album covers to mp3 files doesn’t apply in my case or I don’t understand it correct.
Anyway, in my little mp3 archive of 450 complete CD Rips each mp3 file is tagged with album cover, artist, genre, album title, song title and release year etc.
My “Music Folder” contains subfolders for each artist and each artist folder contains subfolders for each album released by this artist.
To the artist folder I added an icon (256×256) which is as far as I know only possible in Windows Vista and that is what I’m using but the icon file will also display in128x128, 64×64, 48×48, 32×32 and 16×16.
The icon is placed in the artist folder and the desktop.ini which is a hidden file that every folder contains holds the info about each individual folder including the path to the icon that was assigned to that folder wich is in one of my folders:
IconResource=D:\Music\Carlos Santana\santana.ico,0
If I now transfer the whole “Music Folder” to another PC and to a different drive other than D:\ the path to the icon is incorrect because of the drive letter and the assigned folder icon won’t display anymore.
So I was thinking to change the path to a relative path like in i.e. websites but I can’t get this to work and was hoping that one of you guys has an idea how to do this.
If that’s the case please please let me know, I really would appreciate it.
Thanks again…….Cheng…….
Minor tweaks on the first script to have it handle spaces more cleanly, and also to remove the ls –colors and cut -d “=” which died on my system.
function albumcoversfromamarok() {
find . -name ‘.directory’ -type f | while read dirfile
do
icon=`cat “$dirfile” 2>/dev/null | egrep “^Icon” | cut -d = -f2`
outloc=`dirname “$dirfile”`/cover.png
[ -e “$icon” ] && cp “$icon” “$outloc”
done
}
Excellent write up. Thank you.
Thank you for your story that brings two great CLI utilities eyeD3 and id3v2 to my knowledge. Putting cover images as directory icons is also very cool! Here are my remarks about image tags after some tests:
1) I saw that if your add a FRONT_COVER image X times you will need to launch the command eyeD3 –add-image=:FRONT_COVER “$FILENAME” X times as well in order to erase them all.
2) I’ve also found that in order to reclaim your original file size and really get rid of previous images, your can also use this eyeD3 command: eyeD3 –remove-v2 “$FILENAME”.
3) By the way the right command to do the same with id3v2 seems to me to be: id3v2 -d “$FILENAME”
When I try id3v2 -APIC “$FILENAME”, I get rid of the images garbage, but I also get the file tagged with the information “album=PIC”.
To my conclusion, you don’t need any more command than: eyeD3 –remove-v2 “$FILENAME”.
Thanks again.
I’m sorry, please correct “–” instead of “-“:
eyeD3 –-add-image=:FRONT_COVER “$FILENAME”
eyeD3 –remove-v2 “$FILENAME”.
🙁
Hey man, great script!
Now I have all my albums tagged with cover art.
Here’s what I did if anyone’s interested:
First I had used amarok’s function to obtain all cover art.
Next I already used another script, copycover to get a file “cover.png” in every album directory, you can find it here
http://www.kde-apps.org/content/show.php?content=22517
Use “python copycover-offline.py”, but first edit line 141 to
cover_filename = “cover.png”
So that it will give simple filenames.
(you can probably do this easier with the function above, but I had already done it this way)
Then I put your functions in a bash script and ran it over my entire music library (after backing up first). Like this (put this in some bin, e.g. /usr/bin or ~/bin/ and make it executable “chmod 777 mp3albumcover”):
####### file mp3albumcover ######
#!/bin/bash
function mp3albumcoverdir() {
if [ -e “cover.png” ]
then
convert -geometry 300×300 cover.png cover.jpg
else
return
fi
for f in *.mp3
do
echo “Embedding cover in: [$f]”
mp3albumcover “$f” cover.jpg
done
rm cover.png
}
function mp3albumcover() {
FILENAME=”$1″
IMAGE=”$2″
# first, remove existing images
# do this for FRONT_COVER and OTHER APIC types and twice just to make sure we’re clean
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1
# now, get rid of cruft left behind by previous images
id3v2 –APIC “” “$FILENAME” >/dev/null
# make sure we have a valid id3 tag
eyeD3 –to-v2.3 “$FILENAME” >/dev/null 2>&1
# now embed the image
eyeD3 –add-image=”$IMAGE”:FRONT_COVER “$FILENAME”
}
cd “$1”
mp3albumcoverdir
####### end of file mp3albumcover ######
Then I ran it using find for all directories (my music is in /media/disk/Muziek/) :
find /media/disk/Muziek/ -type d -exec mp3albumcover {} \;
Works perfect for me! Thanks again.
I haven’t tried your script because of the following questions:
Why do you REMOVE images with “-add-image”? (there is an eyeD3 option called “–remove-images” that seems more suitable to me)
Why do you do this twice? Is eyeD3 an undeterministic program? Is twice enough? Or could reliability be increased by removing the images five times?
# first, remove existing images
# do this for FRONT_COVER and OTHER APIC types and twice just to make sure we’re clean
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:OTHER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1
eyeD3 –add-image=:FRONT_COVER “$FILENAME” >/dev/null 2>&1
Hi @Joe. I’ll be happy to answer your questions.
I am pretty sure that I tried –remove-images (if it was there in the versions I tried when I was trying to hack this together), and I don’t honestly remember why I didn’t end up using it. One of the tools that I tried in my trial-and-error work ended up removing the image tag, but it didn’t actually remove the space taken up by the old image. So every time I tried setting and removing an image, it just kept adding to the file size. Also, note that the –add-image help description says this: “If the IMG_PATH value is empty the APIC frame with TYPE is removed.”
As for why twice… iirc, during my testing, one of my approaches was adding an image to “OTHER” and another was adding it to “FRONT_COVER”. I didn’t have any more than two of each of these, so I added two –add-images just to make sure there aren’t any left-overs. I’d recommend taking these 4 lines out and trying –remove-images and see if it works for you. =:)
If you find something that does work better, I’d love to hear about it.
Thank you very much for sharing your script. It was a great help as I couldn’t figure it out for myself.
It works great.