I've changed again the "coverArt.js" script, now it works like it should; the modifications (compared to the original script), apart from some comments and debug lines, are the ones in
bold:
code:
...
var MyFilename;
function album_checkInDirForCover(dir, album, filename, artist){
//removes the extension from the currently playing file name
var MyFilename = filename;
var dirparts = MyFilename.split(".");
dirparts.pop();
var MyFilename = dirparts.join(".");
var items = ["Album", "Cover", "Folder", album, artist]
var exts = ["jpg", "jpeg", "gif", "png", "bmp"];
//searches for cover with same filename as media file
for(ext in exts){
file = MyFilename + "." + exts[ext];
//Debug.Trace('Looking for cover: ' + file);
if(fso.FileExists(file)){
Debug.Trace('Found cover: ' + file);
return file;
}
}
//continues search for cover
for(name in items){
for(ext in exts){
file = dir + items[name] + "." + exts[ext];
//Debug.Trace('Looking for cover: ' + file);
if(fso.FileExists(file)){
Debug.Trace('Found cover: ' + file);
return file;
}
}
}
Debug.Trace('No cover found for file ' + filename);
return false;
}
function getAlbum(artist, album, callback, file){
var dirparts = file.split("\\");
dirparts.pop();
var dir = dirparts.join("\\") + "\\";
var item;
if(fso.FileExists(coverArtDirectory + stripfilename(album) + ".jpg")){
callback(coverArtDirectory + stripfilename(album) + ".jpg");
}else if(item = album_checkInDirForCover(dir, album, file, artist)){
Debug.Trace('from file');
callback(item);
}else{
CoverArtTemp = callback;
CoverArtAlbum = album;
new Ajax(sprintf(cover_url, escape(artist + " " + album)), {"onComplete" : parseAlbumResults.bind(this)});
}
}
As you can notice, the differences are:
- When the GetAlbum function calls the Album_checkInDirForCover, it passes not only the dir parameter, but also album, file and artist (as received from the Main.js).
- In the album_checkInDirForCover, in the var items, corrected the single apices enclosing the elements of the list into quotation marks (oddly enough, the element Folder already was enclosed in quotation marks, while Album and Cover had single apices. I don't know if in javascript the difference is relevant, but anyway the "Folder.jpg" worked, while the "Album.jpg" didn't.
- Again, converted the single apices to quotation marks in the var exts.
- Appended the additional parameters passed by the GetAlbum function (Album and Artist) to the list of elements for the var items.
- Added a For...Next loop that runs before the standard search for cover.
As a result, the script, when it can't find a cover on the Internet, nor in the
cache\art folder, looks into the folder where resides the currently playing MP3 and searches for an image
in this order:
[list=1][*]Variable name: (MP3 filename).jpg (or .jpeg, .gif, .png, .bmp)
[*]Exact name: "Album.jpg"
[*]Exact name: "Cover.jpg"
[*]Exact name: "Folder.jpg"
[*]Variable name: (Album name from ID3).jpg
[*]Variable name: (Artist name from ID3).jpg
[/list]
In my system, it works like a charm: I can assign a cover to each single MP3 (by creating a .jpg with the same name of the .mp3), or assign a cover to each album (while having multiple albums in the same folder), or even creating a "default" jpg with the artist image, and the script will select it if anything else fails.
I hope that my explanation makes sense; I'm sorry if my terminology is not accurate, but - as said - I'm not a programmer and I've never dealt with javascripts before.
For anyone interested, I'm attaching the modified "coverArt.js" (I've removed the one in my previous post);
@ DT: feel free to do with the code whatever you want
@anyone else:
use it at your own risk.