I've tried to do automatic downloading, but there is one problem with art.exe. I wrote about it .here
When creating request for nonexistent artist's name in database last.fm. art.exe not self-closing, and remains in Task Manager.
// ==PREPROCESSOR==
// @import "%fb2k_path%scripts\marc2003\v2\common.js"
// ==/PREPROCESSOR==
var title = fb.TitleFormat("[%title%]").Eval();
var album_tf = fb.TitleFormat("$if2(%album%,)");
var artist_tf = fb.TitleFormat("%artist%").Eval();
var g_font_title = gdi.Font("Calibri", 16, 0);
var g_font_album = gdi.Font("Calibri", 18, 0);
var g_font_artist = gdi.Font("Calibri", 18, 0);
var artist = old_artist = null;
var album_img = null;
var artist_img = null;
var g_timer = null;
var offset = 0;
var cycle = window.GetProperty("cycle", 200) - 200;
var limit = window.GetProperty("limit", 325) - 300;
var transition = window.GetProperty("transition", 801) - 800;
var album_img_size = window.GetProperty("album_img_size", 490) - 400;
ww = window.width;
wh = window.height;
var arr = new Array();
if(fb.IsPlaying) on_playback_new_track();
function on_playback_stop(reason) {
if(album_img) album_img.Dispose();
if(artist_img) artist_img.Dispose();
g_metadb = album_img = artist_img = null;
if(reason != 2) window.Repaint();
}
function on_timer(id) {
offset--;
if(offset == 0) {
window.KillTimer(g_timer);
CollectGarbage();
}
window.Repaint();
}
function on_playback_new_track() {
if(transition == 1) {
g_timer = window.CreateTimerInterval(1);
offset = 30;
}
g_metadb = fb.GetNowPlaying();
if(artist) old_artist = artist;
artist_out = fb.TitleFormat("[%artist%]").EvalWithMetadb(g_metadb);
artist = fb.TitleFormat("$replace($lower(%artist%),.,)").EvalWithMetadb(g_metadb);
album = album_tf.EvalWithMetadb(g_metadb);
if(album_img) album_img.Dispose();
album_img = utils.GetAlbumArtEmbedded(g_metadb.rawpath, 0);
if(!album_img) utils.GetAlbumArtAsync(window.ID, g_metadb, 0);
if(artist != old_artist) {
folder = data_folder + fb.TitleFormat("$replace($lower(%artist%),.,)").EvalWithMetadb(g_metadb);
WshShell.Run("\"" + script_path + "art.exe\" \"" + artist + "\" \"" + folder + "\" " + limit, 0, true);
var jpg = utils.Glob(folder + "\\*.jpg").toArray();
var png = utils.Glob(folder + "\\*.png").toArray();
var gif = utils.Glob(folder + "\\*.gif").toArray();
arr = jpg.concat(png, gif);
}
index = Math.floor(Math.random()*arr.length);
load_image();
}
function on_playback_time(time) {
if(cycle > 0 && arr.length > 1 && (time % cycle == 0)) on_mouse_wheel(1);
}
function on_mouse_wheel(delta) {
if(arr.length < 2) return;
index += delta;
if(index < 0) index = arr.length-1;
if(index == arr.length) index = 0;
load_image();
}
function load_image() {
if(artist_img) artist_img.Dispose();
artist_image_path = arr[index];
artist_img = gdi.Image(artist_image_path);
window.Repaint();
}
function on_mouse_lbtn_dblclk() {
try {WshShell.Run("\"" + artist_image_path + "\""); } catch(e) {}
}
function on_get_album_art_done(metadb, art_id, im, ip) {
album_img = im;
window.Repaint();
}
function on_size() {
ww = window.width;
wh = window.height;
}
function scale(gr, img, pos_x, pos_y, width, height, mth) {
var s = mth == "max" ? Math.max(width / img.width, height / img.height) : Math.min(width / img.width, height / img.height);
var nw = img.width * s;
var nh = img.height * s;
pos_x += ((width - nw) / 2);
pos_y += ((height - nh) / 2);
gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.width, img.height);
}
function on_paint(gr) {
if(artist_img) {
gr.FillSolidRect(0,0,ww,wh,RGBA(17,19,49,255)); //background
scale(gr, artist_img, 0, 0, ww, wh, "min");
} else {
gr.FillGradRect(0, 0, ww, wh, 90,g_backcolor, g_textcolor_hl);
}
gr.FillSolidRect(20,wh-130,ww - 40,110,RGBA(0,0,0,156));
if(album_img) {
text_x = album_img_size + 40;
scale(gr, album_img, (-offset * 20) + 30, wh-30-album_img_size, album_img_size, album_img_size, "min");
} else {
text_x = 30;
}
if(fb.IsPlaying) {
gr.GdiDrawText(title, g_font_title, RGB(255,255,255), text_x, (offset * 15) + wh - 100, ww-text_x-40, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
gr.GdiDrawText(album, g_font_album, RGB(255,255,255), text_x, (offset * 20) + wh - 55, ww-text_x-40, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
gr.GdiDrawText(artist_out, g_font_artist, RGB(255,255,255), text_x, (offset * 10) + wh - 130, ww-text_x-40, wh,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
}
}
function on_mouse_rbtn_up(x, y) {
var _menu = window.CreatePopupMenu();
var _cycle = window.CreatePopupMenu();
var _limit = window.CreatePopupMenu();
var _album = window.CreatePopupMenu();
var _transition = window.CreatePopupMenu();
var idx;
_cycle.AppendMenuItem(MF_STRING, 200, "Off");
_cycle.AppendMenuItem(MF_STRING, 205, "5 seconds");
_cycle.AppendMenuItem(MF_STRING, 210, "10 seconds");
_cycle.AppendMenuItem(MF_STRING, 220, "20 seconds");
_cycle.CheckMenuRadioItem(200, 220, window.GetProperty("cycle"));
_limit.AppendMenuItem(MF_STRING, 301, "1");
_limit.AppendMenuItem(MF_STRING, 305, "5");
_limit.AppendMenuItem(MF_STRING, 310, "10");
_limit.AppendMenuItem(MF_STRING, 325, "25");
_limit.CheckMenuRadioItem(301, 325, window.GetProperty("limit"));
_album.AppendMenuItem(MF_STRING, 490, "Small");
_album.AppendMenuItem(MF_STRING, 600, "Large");
_album.CheckMenuRadioItem(490, 600, window.GetProperty("album_img_size"));
_transition.AppendMenuItem(MF_STRING, 800, "Off");
_transition.AppendMenuItem(MF_STRING, 801, "On");
_transition.CheckMenuRadioItem(800, 801, window.GetProperty("transition"));
_menu.AppendMenuItem(g_metadb ? MF_STRING : MF_GRAYED, 11, "Download artist art from Last.fm");
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _limit.ID, "Limit");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(artist_img? MF_STRING : MF_GRAYED, 12, "Open containing folder");
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _cycle.ID, "Cycle");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _album.ID, "Cover image size");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _transition.ID, "Transition effects");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
//_menu.AppendMenuItem(MF_STRING, 99, "Properties");
_menu.AppendMenuItem(MF_STRING, 100, "Configure...");
idx = _menu.TrackPopupMenu(x, y);
switch(idx) {
case 200:
case 205:
case 210:
case 220:
window.SetProperty("cycle", idx);
cycle = idx - 200;
break;
case 301:
case 305:
case 310:
case 325:
window.SetProperty("limit", idx);
limit = idx - 300;
break;
case 490:
case 600:
window.SetProperty("album_img_size", idx);
album_img_size = idx - 400;
window.Repaint();
break;
case 800:
case 801:
window.SetProperty("transition", idx);
transition = idx - 800;
break;
case 11:
WshShell.Run("\"" + script_path + "art.exe\" \"" + artist + "\" \"" + folder + "\" " + limit, 0, true);
on_playback_new_track();
break;
case 12:
WshShell.Run("explorer /select," + artist_image_path);
break;
case 99:
window.ShowProperties();
break;
case 100:
window.ShowConfigure();
break;
}
_menu.Dispose();
_cycle.Dispose();
_limit.Dispose();
_transition.Dispose();
_album.Dispose();
return true;
}
function RGBA(r, g, b, a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }