the reason 5 spawn at once is because a previous version did do 1 at a time and waited for 1 to finish before starting the next. the problem with that is that it prevented foobar from closing which i thought was unacceptable.
Maybe to set delay in vbs?
...I modified your old bio text script, to download biography directly from last.fm web page.
Seems to work fine
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;
DT_END_ELLIPSIS = 0x00008000;
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
FontTypeCUI = {
items: 0,
labels: 1
};
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
FontTypeDUI = {
defaults: 0,
tabs: 1,
lists: 2,
playlists: 3,
statusbar: 4,
console: 5
};
function RGB(r,g,b) {
return (0xff000000|(r<<16)|(g<<8)|(b));
}
function get_font() {
if (g_instancetype == 0) {
g_font = window.GetFontCUI(FontTypeCUI.items);
} else if (g_instancetype == 1) {
g_font = window.GetFontDUI(FontTypeDUI.defaults);
}
}
function get_colors() {
if (g_instancetype == 0) {
g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
} else if (g_instancetype == 1) {
g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
}
}
function on_playlist_switch() {
on_item_focus_change();
}
function on_colors_changed() {
get_colors();
window.Repaint();
}
function on_font_changed() {
get_font();
window.Repaint();
}
function on_item_focus_change() {
if (g_metadb) window.UnwatchMetadb();
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (g_metadb) {
try { on_metadb_changed(); } catch(e) {}
window.WatchMetadb(g_metadb);
}
}
g_instancetype = window.InstanceType;
get_font();
get_colors();
g_metadb = fb.GetFocusItem();
var artist = g_text = '';
folder = fb.ProfilePath + "wsh_lastfm";
fso = new ActiveXObject("Scripting.FileSystemObject");
WshShell = new ActiveXObject("WScript.Shell");
if(!fso.FolderExists(folder)) fso.CreateFolder(folder);
on_item_focus_change();
String.prototype.count=function(s1) {
return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}
function get_bio() {
if (!this.xmlhttp) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
this.xmlhttp.open("GET", "http://www.last.fm/music/" + encodeURIComponent(artist) + "/+wiki", true);
this.xmlhttp.send();
this.xmlhttp.onreadystatechange = function() {
if (this.xmlhttp.readyState == 4) {
if (this.xmlhttp.status == 200) {
var text = this.xmlhttp.responsetext;
if (!this.doc) this.doc = new ActiveXObject("htmlfile");
this.doc.open();
var div = this.doc.createElement("div");
div.innerHTML = text;
var data = div.getElementsByTagName("a");
var urls = [];
for (i = 0; i < 1; i++) {
if (data[i].id.indexOf("about:/wiki/") == 0);
var st = text.indexOf( data[i].id.replace("about:/wiki/", ""));
var str = "id=\"wiki\">";
st = text.indexOf(str, st) + str.length;
var et = text.indexOf("</div>", st);
var artt = text.substr(st, et - st);
var ar = artt;
var ar = ar.replace(/<\/?[^>]+(>|$)/g, "").replace(/\n/g, "<br>").replace(/<BR>/g,"\n").replace(/&/g,"&");
fb.trace("bio: " + ar);
{save_file(ar);};
}
this.doc.close();
} else {
fb.trace("HTTP error: " + im.xmlhttp.status);
}}}}
function save_file(x) {
try {
g_text = x;
g_text = g_text.replace(/<\/?[^>]+(>|$)/g, "");
doc = new ActiveXObject("htmlfile");
doc.open();
div = doc.createElement("div");
div.innerHTML = g_text;
g_text = div.innerHTML;
g_text = g_text;
} catch(e) {
g_text = "This artist does not have a biography";
}
try {
ts = fso.OpenTextFile(filename, 2, true, -1);
ts.WriteLine(g_text);
ts.close();
} catch(e) {
g_text = "Error saving biography for this artist";
}
calc();
}
function on_size() {
ww = window.Width;
wh = window.Height;
calc();
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
if(g_metadb) {
gr.GdiDrawText(g_text, g_font, g_textcolor, 6, offset + 8, ww-16, wh-offset-16,DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
gr.FillSolidRect(-1000, -1000, ww, 38, g_backcolor);
//gr.GdiDrawText(artist, gdi.Font("Segoe UI", 16, 1), g_textcolor_hl, 6, 5, ww-77, 24,DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
//gr.DrawLine(5, 29, ww-10, 29, 1, RGB(137,140,149));
}
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_metadb_changed() {
if(!g_metadb || artist == fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)) return;
artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)
filename = folder + "\\" + fb.TitleFormat("$crc32(%artist%).txt").EvalWithMetadb(g_metadb);
if(fso.fileExists(filename)) {
try {
ts = fso.OpenTextFile(filename,1, false, -1);
g_text = ts.ReadAll();
ts.close();
} catch(e) {
g_text = "Error opening file!";
}
calc();
} else {
get_bio();
}
}
function calc() {
temp_bmp = gdi.CreateImage(1, 1);
temp_gr = temp_bmp.GetGraphics();
arr = temp_gr.GdiDrawText(g_text, g_font, g_textcolor, 0, 0, ww, wh,DT_CENTER| DT_WORDBREAK | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX).toArray();
textheight = arr[3] - arr[1] + (wh/2) + (g_text.count("\n") * 3);
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
offset = 0;
window.Repaint();
}
function on_mouse_rbtn_up(x, y) {
var MF_SEPARATOR = 0x00000800;
var MF_STRING = 0x00000000;
var _menu = window.CreatePopupMenu();
var idx;
_menu.AppendMenuItem(MF_STRING, 1, "Force update");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 2, "Configure...");
idx = _menu.TrackPopupMenu(x, y);
if(idx == 1) get_bio();
if(idx == 2) window.ShowConfigure();
_menu.Dispose();
return true;
}
function on_mouse_wheel(delta) {
step = g_font.height * 1;
offset += (delta * step);
if(offset > 0 || textheight < wh) {
offset = 0;
} else {
temp = -textheight + wh;
if(offset < temp) offset = Math.round(temp / step) * step;
}
window.Repaint();
}