115
comments
|
Tuesday, December 26, 2006
UPDATE: Added more diagnostics to the code. If you were having issues, run it again and post the output to in a comment.
UPDATE2: Changed the second regular expression to be a little more loose. Hopefully this will resolve some of the problems.
UPDATE3: Blogger was removing some code that it thought was HTML causing an endless loop in the script. If you tried the script and it was just hanging, try it again.
UPDATE4: Fixed two things: One - Napster 4 changed its image naming conventions (Thanks Don). Two - This program never handled multi-byte characters well. Its somewhat hacked to fix this.
So, Napster isn't so good at album art for some reason -- no trace of it anywhere in my library. Funny thing is, Napster has its own stash of all the covers in C:\Documents and Settings\All Users\Application Data\Napster\image. Unfortunately its stored by some crazy obfuscated name like 12303503.jpg. Good news is that the Napster database, db30.bin, has the nessesary glue to piece things together. I hacked together some Perl to find my missing artwork and copy it to the album's directory as folder.jpg. This lets Windows Media Player tag the wma's correctly so they even transfer to my Zen with artwork.
Its a little ugly as you can see. I had to resort to some nasty regular expressions to track everything down without learning the entire file layout format. Please steal, improve, maintain, hack this as you see fit.
#!/usr/bin/perl
# This program will scan your music directory for missing album art (library). Then it will scan the napster
# database file (db) for a matching album. Then it will look up the missing image for that album in napsters
# own image archive (imgdir).
#
# Hopefully someone will come along and improve this, maybe make a plugin to WMP and improve the searching.
#
use File::Copy;
my $debug = 0;
my %hash = ();
$db = 'C:\Documents and Settings\All Users\Application Data\Napster\bin\db30.bin';
$imgdir = 'C:\Documents and Settings\All Users\Application Data\Napster\image';
#Your Napster library directory
$library = 'C:\Documents and Settings\CHANGEME\My Documents\My Music';
#Your Napster Username
$username = 'CHANGEME';
print "Fixing Napster Album Art v1.3\n";
# Find the albums with missing art
print "Searching for missing album art:\n";
opendir(LIB, $library) or die "Can't open $library: $!";
while( defined ($artist = readdir LIB) ) {
next if $artist =~ /^\.\.?$/; # skip . and ..
opendir( ART, "$library/$artist" );
while( defined ($album = readdir ART) ) {
next if $album =~ /^\.\.?$/; # skip . and ..
if ( -d "$library/$artist/$album" ) {
if( ! -f "$library/$artist/$album/folder.jpg" ) {
#get the first song in the album
opendir( ALB, "$library/$artist/$album" );
while( defined ($song = readdir ALB) ) {
next if $song =~ /desktop.ini/;
$songReg=$song;
$songReg=~s/[\x7f-\xff]/../g;
$songReg=~s/\W/./g;
if( -f "$library/$artist/$album/$song" ) {
$hash{$songReg}{'missing'} = 'true';
$hash{$songReg}{'album'} = $album;
$hash{$songReg}{'artist'} = $artist;
print " - Missing album art for $artist - $album\n";
last;
}
}
closedir(ALB);
}
}
}
closedir(ART);
}
closedir(LIB);
$size = keys( %hash );
print "Missing album art for $size albums\n";
if( $size == 0 ) {
exit 0;
}
# Find a song in that album
print "\nSearching for missing albums in napster database\n";
open(DB, $db) or die "Can't open $db: $!";
while(<DB>) {
while(m/\000$username\000(\w+)\0001\0000\0001\000\w+\000([^\000]+)\000([^\000]+)\000/g) {
$songID = $1;
$songName = $2;
$songFileName = $3;
#Normalize non-printable characters to periods
$songReg=$2;
$songReg=~s/\W/./g;
if( exists $hash{$songReg} ) {
print " - Found missing albums $hash{$songReg}{'album'} - first songID: $songID\n";
$hash{$songReg}{'ID'} = $songID;
}
}
}
close(DB);
# Find the album ID of that song
print "\nSearching for albumID and artwork in napster directories\n";
open(DB, $db);
while(<DB>) {
while(m/\000$username\000(\d+)\000(\d{5,20})\000(\d{5,20})\000([^\000]+)\000/g) {
my $songID = $1;
my $artistID = $2;
my $albumID = $3;
my $songShortName = $4;
for my $song ( keys %hash ) {
if( $hash{$song}{'missing'} eq 'true' && $hash{$song}{'ID'} eq $songID ) {
$dir = "$library/$hash{$song}{'artist'}/$hash{$song}{'album'}";
$img = "$imgdir"."/"."$albumID".".jpg";
print " - Found albumID for $dir: $albumID\n";
if( -f $img ) {
print " - Found artwork for album: $img\n";
#Finally copy the image for that album to its new home
copy( $img, "$dir/folder.jpg");
$hash{$song}{'missing'} = 'false';
} else {
print " - Error missing album image for $hash{$song}{'album'}: $albumID\n";
print " - img is: $img\n";
}
}
}
}
}
close(DB);
Steps to use this program:
1-Download and install perl from http://www.perl.com
2-Save that script to a file something like fixNapsterArt.pl
3-Edit fixNapsterArt.pl changing the CHANGEME lines to the appropriate values
4-Run fixNapsterArt.pl

115 Comments:
Having trouble getting it to work. i installed perl and edited the location of my music but when I run the script the DOS screen shows up black and nothing happens. Am I doing something wrong?
12/28/2006 11:09 AM
Did you edit your username too?
I'll add a little bit more diagnostics tonight. Check back tomorrow.
12/28/2006 12:29 PM
I edited the user name and the music path then I paste the script into a notepad file and named it napsterfix.pl. When I run it the command prompt pops up with a black screen and does nothing.
12/28/2006 7:04 PM
OK - Try again, I added a lot more debugging information to the script. Then just paste the output in a comment if you have trouble.
12/29/2006 8:53 AM
Also - If your running it by double clicking or using the Run menu, don't do that since you'll loose the output. Instead bring up a command prompt, cd to the directory where your script is, the run the script.
12/29/2006 10:43 AM
Ok I got it running and it says it's searching for album art in napster database but it's not finding anythig even though the art is there.
12/29/2006 8:42 PM
By the way I think this is a great script that will help a lot of people. Soon as I get it to work I will spread the word. I did it by clicking on it first then I used the command prompt. COuld that cause a problem?
Happy New Year
12/29/2006 9:23 PM
- Missing album art for Nelly Furtado - Loose [US version]
- Missing album art for Perfect - Riddim Driven_ Sidewalk University
- Missing album art for Sean Paul feat Keyshia Cole - Step Up Soundtrack
- Missing album art for Sizzla - Riddim Driven_ Sidewalk University
- Missing album art for Snow Patrol - Eyes Open
- Missing album art for Tanto Metro - Riddim Driven_ Sidewalk University
- Missing album art for The Fray - How To Save A Life
- Missing album art for The Pussycat Dolls - PCD
- Missing album art for Tony Matterhorn - Riddim Driven_ Sidewalk University
- Missing album art for Version - Riddim Driven_ Sidewalk University
- Missing album art for Vybz Kartel - Riddim Driven_ Sidewalk University
- Missing album art for Ward 21 - Riddim Driven_ Sidewalk University
Missing album art for 33 albums
Searching for missing albums in napster database
12/29/2006 9:30 PM
Well, It looks like it can't find the album information in your napster database. If you want to send me a copy of your database and the exact output logs, I'll take a look.
To send the output logs, run 'script.pl > output.log'. Then email me output.log with your database (db30.bin). My email address is in my profile.
12/29/2006 10:58 PM
Good news is it's at least working for one person :)
http://www.epizenter.net/e107_plugins/forum/forum_viewtopic.php?67571.last
12/29/2006 11:01 PM
Email sent
12/29/2006 11:50 PM
This works perfectly and now all my downloaded tracks from napster have album art in WMP. Good work...
12/30/2006 6:41 PM
This worked great for me thanks a bunch, very cool
1/08/2007 5:46 PM
This thing just won't recognize that all of my new Napster music needs to get their Album Arts fixed.
1/15/2007 11:17 PM
I figured out your program is deciding everything by a Artist/Album/Song structure, but my Napster does not use that.
1/15/2007 11:25 PM
You will need to have your music organized in folders. You can change the options in Napster. Also it does nto work well for the windows media player plug in so I suggest you use the stand alone.
2/13/2007 10:00 PM
Works great for me.
2/13/2007 10:00 PM
This post has been removed by the author.
3/31/2007 10:50 AM
It says "Missing album art for 0 albums" even though I still have no album art.
3/31/2007 11:10 AM
yeah! works perfect with napster germany!
Tahnk you soo much!
4/22/2007 10:20 AM
No luck here, it gets to the line "Searching for missing albums in napster database" and then stops. I do have my music organized by Artist - Album - Song so don't think that's the problem.
8/28/2007 2:40 AM
dXgGju You have a talant! Write more!
10/30/2007 12:42 PM
n8C54S Hello all!
10/30/2007 10:32 PM
GavmgK The best blog you have!
11/02/2007 3:40 AM
d6bRpw Wonderful blog.
11/02/2007 1:20 PM
Wonderful blog.
11/02/2007 2:14 PM
Wonderful blog.
11/02/2007 3:01 PM
Good job!
11/02/2007 3:55 PM
Good job!
11/02/2007 4:58 PM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/03/2007 6:31 AM
Thanks to author.
11/03/2007 11:09 AM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/03/2007 12:11 PM
Please write anything else!
11/03/2007 1:15 PM
Wonderful blog.
11/03/2007 2:03 PM
4ipU8n write more, thanks.
11/04/2007 9:32 AM
Good job!
11/04/2007 10:53 PM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/04/2007 11:27 PM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/05/2007 1:17 AM
Good job!
11/05/2007 1:52 AM
Thanks to author.
11/05/2007 2:27 AM
Magnific!
11/05/2007 2:55 AM
Wonderful blog.
11/05/2007 3:26 AM
Nice Article.
11/05/2007 3:56 AM
Thanks to author.
11/05/2007 4:34 AM
Nice Article.
11/05/2007 5:17 AM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/05/2007 5:54 AM
Hello all!
11/05/2007 6:26 AM
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
11/05/2007 6:57 AM
C++ should have been called B
11/05/2007 7:32 AM
Build a watch in 179 easy steps - by C. Forsberg.
11/05/2007 8:11 AM
Save the whales, collect the whole set
11/05/2007 8:40 AM
A flashlight is a case for holding dead batteries.
11/05/2007 9:08 AM
Suicidal twin kills sister by mistake!
11/05/2007 9:40 AM
Clap on! , Clap off! clap@#&$NO CARRIER
11/05/2007 10:13 AM
The gene pool could use a little chlorine.
11/05/2007 10:47 AM
Calvin, we will not have an anatomically correct snowman!
11/05/2007 11:19 AM
Thanks to author.
11/05/2007 11:50 AM
Please write anything else!
11/05/2007 12:23 PM
Change is inevitable, except from a vending machine.
11/05/2007 12:56 PM
The gene pool could use a little chlorine.
11/05/2007 1:38 PM
All generalizations are false, including this one.
11/05/2007 2:17 PM
Hello all!
11/05/2007 2:54 PM
Thanks to author.
11/05/2007 3:28 PM
What is a free gift ? Aren't all gifts free?
11/05/2007 4:01 PM
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
11/05/2007 4:28 PM
What is a free gift ? Aren't all gifts free?
11/05/2007 4:54 PM
A flashlight is a case for holding dead batteries.
11/05/2007 5:24 PM
A lot of people mistake a short memory for a clear conscience.
11/05/2007 5:53 PM
I don't suffer from insanity. I enjoy every minute of it.
11/05/2007 6:27 PM
What is a free gift ? Aren't all gifts free?
11/05/2007 7:01 PM
Clap on! , Clap off! clap@#&$NO CARRIER
11/05/2007 7:36 PM
Friends help you move. Real friends help you move bodies
11/05/2007 8:11 PM
What is a free gift ? Aren't all gifts free?
11/05/2007 8:42 PM
Calvin, we will not have an anatomically correct snowman!
11/05/2007 9:14 PM
Hello all!
11/05/2007 9:47 PM
When there's a will, I want to be in it.
11/05/2007 10:29 PM
The gene pool could use a little chlorine.
11/05/2007 11:11 PM
Thanks to author.
11/05/2007 11:44 PM
Good job!
11/06/2007 12:25 AM
Give me ambiguity or give me something else.
11/06/2007 12:59 AM
Hello all!
11/06/2007 1:32 AM
I don't suffer from insanity. I enjoy every minute of it.
11/06/2007 2:12 AM
Suicidal twin kills sister by mistake!
11/06/2007 2:54 AM
Ever notice how fast Windows runs? Neither did I.
11/06/2007 3:40 AM
Thanks to author.
11/06/2007 4:26 AM
Ever notice how fast Windows runs? Neither did I.
11/06/2007 5:09 AM
What is a free gift ? Aren't all gifts free?
11/06/2007 5:50 AM
When there's a will, I want to be in it.
11/06/2007 6:38 AM
Oops. My brain just hit a bad sector.
11/06/2007 7:32 AM
Suicidal twin kills sister by mistake!
11/06/2007 8:22 AM
Give me ambiguity or give me something else.
11/06/2007 9:03 AM
All generalizations are false, including this one.
11/06/2007 9:42 AM
All generalizations are false, including this one.
11/06/2007 10:20 AM
All generalizations are false, including this one.
11/06/2007 10:56 AM
The gene pool could use a little chlorine.
11/06/2007 11:34 AM
Friends help you move. Real friends help you move bodies
11/06/2007 12:17 PM
What is a free gift ? Aren't all gifts free?
11/06/2007 12:58 PM
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
11/06/2007 1:42 PM
When there's a will, I want to be in it.
11/06/2007 2:32 PM
I don't suffer from insanity. I enjoy every minute of it.
11/06/2007 3:19 PM
Give me ambiguity or give me something else.
11/06/2007 3:56 PM
Works on Vista with Napster 4 with the following:
the db is C:\ProgramData\Napster\bin\db30.bin
the imgdir is
C:\ProgramData\Napter\bin\image
the library is something like
C:\Users\_NAME_\Music
AND
the image file names don't seem to contain "_big" (i.e. in the last while loop (on line 88) change "_big.jpg" to just ".jpg"
)
11/27/2007 10:00 PM
Thanks DOn.
12/02/2007 12:16 AM
Installed Perl and edited the script file for my music location and my username. When I run the script, I get this error message:
Bad name after queencityrunner' at D:\NJ_Docs\Perl\fixNapsterArt.pl line 19.
Line 19 (counting blanks) is the line in which my username (queencityrunner) is defined. This is the code just before and after that line. Any suggestions? Thanks so much.
#Your Napster library directory
$library = 'D:\NJ_Docs\My Music_Napster\';
#Your Napster Username
$username = 'queencityrunner';
print "Fixing Napster Album Art v1.3\n";
12/30/2007 11:03 PM
Disregard previous comment. Just changed the way I saved and renamed the script file, and it worked fine. Thanks!
12/30/2007 11:16 PM
Hi, thank you for the program. I works fine. The only problem is that it copies the little cover art (100*100) and not the "_big" one (150*150). Do you think is possible to fix this? Thank you!! Chris
1/12/2008 7:07 PM
Works great. Thanks alot.
2/17/2008 10:34 AM
Cool, Worked Great Thanks a Lot
3/27/2008 10:20 AM
Cut-n-Pasted script ad added all the carriage returns that would not copy so it would 'look' just a posted. Followed all the helpful instructions above and wallah!!
Works like a charm. THank You so muc. A real time saver.
5/16/2008 9:11 AM
Works great! thanks!
5/17/2008 10:54 AM
Wonderful, works like a charm. Thank you very much. But is it possible to change the jpg from 100x100 to the big 150x150 ones? would be even better. Thanks in advance ;)
7/19/2008 3:36 PM
I changed my Napster username - and subsequently neither my new or old username would work with the script. Setting my username to * in the script (to match anything) seemed to fix it again.
9/21/2008 5:57 AM
Oh yeah, and to get it to use the higher quality "big" artwork, near the end of the file change
$img = "$imgdir"."/"."$albumID".".jpg";
to
$img = "$imgdir"."/"."$albumID"."_big.jpg";
9/21/2008 6:04 AM
Do you know what type of database the db30.bin file for napster is? I'd like to browse around in it, or convert it to another database to browse it with.
2/14/2009 10:16 AM
I am very new to anything scripting-wise....
However, I got the script to work with the help of a friend, and then it told me that it had only 5 albums with the artwork missing (which were albums that I had ripped that I didn't really care about.)
Some albums did show up in Windows Media Player, but the rest are still "paste album art here." What should I do? When I "apply Media information changes" it doesn't work either. help?
6/10/2009 6:26 PM
Post a Comment
<< Home