Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: WSH Panel Mod script discussion/help (Read 1399771 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

WSH Panel Mod script discussion/help

Reply #3350
no. i use a 3rd party webservice provided by the the echonest. last time i checked, it took about a week for a new edit to show on their site. the reason i use this and not last.fm directly is because i can get the full text for the article. last.fm only provide the first few sentences. my script will eventually show the edited page because it checks to see if the locally saved page is a day old. if it is, it checks for updates.

WSH Panel Mod script discussion/help

Reply #3351
no. i use a 3rd party webservice provided by the the echonest. last time i checked, it took about a week for a new edit to show on their site. the reason i use this and not last.fm directly is because i can get the full text for the article. last.fm only provide the first few sentences. my script will eventually show the edited page because it checks to see if the locally saved page is a day old. if it is, it checks for updates.


Why you don't want to use web page directly?
I modified your old bio text script, and i receive full bio text directly from last.fm> link
You can do this also for wikipedia...
Then user can also use different language etc..

WSH Panel Mod script discussion/help

Reply #3352
@marc2003

hi marc...

i'd like to ask a last question about relocation of saved files. my local SSD is only 120gb so it get full pretty quick...

is it possible to change the artists => artists name folder to be moved to say a different disk

what kinds of adjustments in codes / paths do i need to make to change the path from roaming = foobar2000 = wsh_data to say, my D hard drive...

(or is it just easier to scrap everything and install foobar on my D hard drive and not in C program files...?)

*also if i installed the foobar on D hard drive... will that messed with your scripts and other plugins (like foo uie lyrics3) as well... ?

rvpio

WSH Panel Mod script discussion/help

Reply #3353
@mire777, if wiki editors must see instant changes, they can use your script. i'm not changing mine.

@rovopio, installing foobar2000 in portable mode on another drive is the best solution. just copy the entire contents of %appdata%\foobar2000 in to your new foobar2000 folder and all your previous settings and components should work just fine.

WSH Panel Mod script discussion/help

Reply #3354
nice @marc2003,

thanks a lot!!

again, thank you for the thumb script

WSH Panel Mod script discussion/help

Reply #3355
Just updated to common8, I didn't realize common7 wasn't supported anymore. Is there no Now Playing script with this one? I don't see it in the samples.


WSH Panel Mod script discussion/help

Reply #3357
I'm seeing some weirdness in using the musicbrainz script with both common7 and common8, and it would be great of someone can confirm if they see something similar or not to determine if the problem is  unique to my setup or not.

With entities that MB called a "group" (for example, the Beach Boys), the MB script will fail to list the "live" releases listed for a group.  Compilations are listed, albums are listed, but not live releases.

If the MB entity is an "artist", then everything seems fine with respect to live releases.  I haven't had time to see if there is anything similar going on with EPs, singles or remixes.

edit: I made sure to delete the previous json to ensure the script downloaded new data, and I updated the common8 script to what reports as the latest as of an hour ago.
edit 2: I just found a "group" that shows live releases in the MB script, and the MB website under the discography listing shows an "artist" column the for group (The Crystal Method), but The Beach Boys shows no such "artist" column for their discography listing.  No idea if that's relevant or not to the script.

WSH Panel Mod script discussion/help

Reply #3358
it's purely down to how many release groups the artist has. artists with a bigger back catalogue will exhibit this problem because i can only fetch 100 in a single request and i've never implemented pagination. albums are listed first, then compilations, then live releases, then singles and finally, EPs.

WSH Panel Mod script discussion/help

Reply #3359
Thanks for the explanation. 100 sounds good enough for the script's purposes, so knowing that limit  I'm fine with the existing script.

WSH Panel Mod script discussion/help

Reply #3360
no. i use a 3rd party webservice provided by the the echonest. last time i checked, it took about a week for a new edit to show on their site. the reason i use this and not last.fm directly is because i can get the full text for the article. last.fm only provide the first few sentences. my script will eventually show the edited page because it checks to see if the locally saved page is a day old. if it is, it checks for updates.

I'll wait and see how long the updates take to show up. A week seems like a very long time for updates. Hopefully its not always that long.

WSH Panel Mod script discussion/help

Reply #3361
no. i use a 3rd party webservice provided by the the echonest. last time i checked, it took about a week for a new edit to show on their site. the reason i use this and not last.fm directly is because i can get the full text for the article. last.fm only provide the first few sentences. my script will eventually show the edited page because it checks to see if the locally saved page is a day old. if it is, it checks for updates.


Why you don't want to use web page directly?
I modified your old bio text script, and i receive full bio text directly from last.fm> link
You can do this also for wikipedia...
Then user can also use different language etc..

@mire777
I tried your modified bio script. Works ok and I can see all updates immediately. Great! But for some reason it doesn't have any pagination/spacing. So the text shows up as one big paragraph. The original script shows paragraph spacing, so what changed?
FYI. Some time ago last.fm changed their policy to limit retrieving to the first few sentences, looks like they may have changed their policy again as the full text is being retrieved now.

WSH Panel Mod script discussion/help

Reply #3362
i was going to update it but i can't be bothered anymore. there's no reason to think the old one will stop working. if you need to download it again, it's here: https://dl.dropboxusercontent.com/u/2280132...mp/samples7.zip

I tried using the  old now_playing script. It didn't work.

I changed the following line to use common8.
// @import "%fb2k_profile_path%marc2003\common8.js"

Now I get a error.
Error: WSH Panel Mod (Now Playing by marc2003): Microsoft JScript runtime error: 'images' is undefined

I noticed that the images are now in subfolders where as before they were in the root "images" folder. What do I have to do to get them working?

Thanks.


WSH Panel Mod script discussion/help

Reply #3363
i was going to update it but i can't be bothered anymore. there's no reason to think the old one will stop working. if you need to download it again, it's here: https://dl.dropboxusercontent.com/u/2280132...mp/samples7.zip

I tried using the  old now_playing script. It didn't work.

I changed the following line to use common8.
// @import "%fb2k_profile_path%marc2003\common8.js"

Now I get a error.
Error: WSH Panel Mod (Now Playing by marc2003): Microsoft JScript runtime error: 'images' is undefined

I noticed that the images are now in subfolders where as before they were in the root "images" folder. What do I have to do to get them working?

Thanks.

I think you have to put common7.js inside your marc2003 folder ,mine works fine without any changes.

WSH Panel Mod script discussion/help

Reply #3364
i was going to update it but i can't be bothered anymore. there's no reason to think the old one will stop working. if you need to download it again, it's here: https://dl.dropboxusercontent.com/u/2280132...mp/samples7.zip

Quote
I tried using the  old now_playing script. It didn't work.

I changed the following line to use common8.
// @import "%fb2k_profile_path%marc2003\common8.js"

Now I get a error.
Error: WSH Panel Mod (Now Playing by marc2003): Microsoft JScript runtime error: 'images' is undefined

I noticed that the images are now in subfolders where as before they were in the root "images" folder. What do I have to do to get them working?

Thanks.

I think you have to put common7.js inside your marc2003 folder ,mine works fine without any changes.

Just tried that and it doesn't work for me.  I get the following error. I even tried recreating the wsh panel. And moved the now_playing script into "samples".

Code: [Select]
WSH Panel Mod (Now Playing by marc2003): Parsing file "C:\....\foobar2000\marc2003\common7.js"
WSH Panel Mod (Now Playing by marc2003): initialized in 24 ms
Error: WSH Panel Mod (Now Playing by marc2003): Microsoft JScript runtime error:
Object required
File: C:\....\foobar2000\marc2003\common7.js
Ln: 1576, Col: 4
<source text only available at compile time>

WSH Panel Mod script discussion/help

Reply #3365
Did you place the "images" folder as well in the marc2003 folder from the common7 download?

WSH Panel Mod script discussion/help

Reply #3366
Did you place the "images" folder as well in the marc2003 folder from the common7 download?

I think I would need the "images" folder from the common8 download to use the other newer scripts.
Update. I tried moving just the files from the old images folder to marc2003 but that didn't work either. Same error.

WSH Panel Mod script discussion/help

Reply #3367
here's a simplified now playing script to work with my new pack: https://dl.dropboxusercontent.com/u/2280132...w%20playing.txt

edit: if anyone downloaded this in the last 25 minutes, they should grab it again. i just fixed a silly bug...

because large chunks of underlying code have changed, i've had to get rid of some features...
no right click options to toggle things on/off. just edit the variables at the top of the script to false if you want.
no top/bottom option for trackinfo/rating. it's locked to the bottom.
no web links
thumbs are disabled. you can cycle through multiple images using your mouse wheel.
users of the old common7 script will need to run the migrate script in the full samples8.zip download if they want their images to show in this.

@mire777
FYI. Some time ago last.fm changed their policy to limit retrieving to the first few sentences, looks like they may have changed their policy again as the full text is being retrieved now.


he's not using the webservice. instead he's scraping the html source of the webpage to get it.

WSH Panel Mod script discussion/help

Reply #3368
@marc2003
I tried to to build a now playing script with with last fm play count sync button
I added the relevant function calls separately
But when i add  ps.metadb_changed();  in  function on_metadb_changed() methored i got this error:

Error: WSH Panel Mod (Thumbs by marc2003): Microsoft JScript runtime error:
'ps' is null or not an object
File: <main>
Ln: 148, Col: 5
<source text only available at compile time>

This is my full script:

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_profile_path%marc2003\common8.js"
// @name "Thumbs"
// @author "marc2003"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==



 //the track info section displays 3 lines of title formatted text. you can customise that here/////////////////////////////////////////////
var line1 = {
text: "", //leave this blank
tf: "%artist%", //enter any title formatting
font: gdi.Font("Segoe UI", 36, 1), //font name, size, style. 1 means bold and 0 is normal.
colour: RGB(240, 240, 240), //colour
y: 0 //change this value to move text up or down.
}
var line2 = {
text: "",
tf: "%title%",
font: gdi.Font("Segoe UI", 28, 1),
colour: RGB(210, 210, 210),
y: 38
}
var line3 = {
text: "",
tf: "[%album%]",
font: gdi.Font("Segoe UI", 20, 1),
colour: RGB(180, 180, 180),
y: 70
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






var p = new panel("Thumbs", ["metadb", "remap", "custom_background"]);

window.SetProperty("2k3.musicbrainz_releases", false);
var li = new list("musicbrainz", 0, 0, 0, 0);
var th = new thumbs();
var r = new rating(0, 4, 24);
var bt = new buttons("playback");
var b = new buttons();
var bs = 32; //button size
var c = new cd(0, 0, p.w, p.h);
p.item_focus_change();
var l = new lastfm();
//function takes 3 values: x, y, size. see on_size function if you want to update these relative to panel width/height
var ps = new playcount_sync(3, 0, 32);

if (fb.IsPlaying) ps.playback_new_track();
else if (p.metadb) p.item_focus_change();
else ps.update_button();


bt.update = function() {
bt.buttons = {
stop: new button((p.w - bs*6) , p.h-bs*3, bs, bs, {normal: this.images.stop}, function() { fb.Stop(); }, "Stop"),
play: new button((p.w - bs*6)+bs, p.h-bs*3, bs, bs, {normal: !fb.IsPlaying || fb.IsPaused ? this.images.play : this.images.pause}, function() { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "Play" : "Pause"),
previous: new button((p.w - bs*6)+bs * 2, p.h-bs*3, bs, bs, {normal: this.images.previous}, function() { fb.Prev(); }, "Previous"),
next: new button((p.w - bs*6)+bs * 3, p.h-bs*3, bs, bs, {normal: this.images.next}, function() { fb.Next(); }, "Next")
}
window.Repaint();
}

bt.update();

function on_playback_time() {
ps.playback_time();
}
function on_playback_time(time) {
th.playback_time(time);
 
   
}




function on_size() {
p.size();
    pos_x = 0;
    pos_y = p.h-15;
th.size();
    bt.update();
    r.x = p.w - 125;
r.y = p.h - 25;
c.w = 200;
c.h = 200;
    c.x=0;
    c.y=p.h-200;
    ps.x = p.w - 220;
ps.y = p.h - 95;
ps.update_button();
 
   
}

function on_paint(gr) {
p.draw_background(gr);
th.draw(gr);
    r.draw(gr);
   


    for (var i = 0; i < li.items; i++) {
p.draw_image(gr, li.musicbrainz_images[li.images[i]], pos_x + (i * 20), pos_y, 16, 16);
}
   
   
    gr.FillSolidRect(0, p.h-150, p.w, 110, RGBA(0, 0, 0, 196));
p.left_text(gr, line1.text, line1.font, line1.colour, 210, p.h-150, 500, line1.font.Height);
p.left_text(gr, line2.text, line2.font, line2.colour, 210, p.h-150+ line2.y, 500, line2.font.Height);
p.left_text(gr, line3.text, line3.font, line3.colour, 210, p.h-150 + line3.y, 500, line3.font.Height);
    c.draw(gr);   
    bt.draw(gr);
    b.draw(gr);   
}


function on_playback_stop() {
bt.update();
}

function on_playback_pause() {
bt.update();
}

function on_playback_starting() {
bt.update();
}



function on_metadb_changed() {
th.metadb_changed();
    r.metadb_changed();
    li.metadb_changed();
    c.metadb_changed();
    line1.text = p.eval(line1.tf);
    line2.text = p.eval(line2.tf);
    line3.text = p.eval(line3.tf);
    ps.metadb_changed();
}

function on_playback_new_track() {
ps.playback_new_track();
}


function on_playback_edited() {
ps.playback_edited();
}



function on_get_album_art_done(metadb, art_id, im, ip) {
c.get_album_art_done(ip);
}

function on_mouse_wheel(step) {
th.wheel(step);
}

function on_mouse_move(x, y) {
p.move(x, y);
th.move(x, y);
bt.move(x, y);
    r.move(x,y);
    //c.move(x, y);
    if (x > pos_x && x < pos_x + (li.items * 20) && y > pos_y && y < pos_y + 20) p.tt(li.urls[Math.floor((x - pos_x) / 20)]);
else p.ttd();
    b.move(x, y);

}

function on_mouse_lbtn_up(x, y) {
th.lbtn_up(x, y);
    r.lbtn_up(x,y);
    bt.lbtn_up(x, y);
    if (x > pos_x && x < pos_x + (li.items * 20) && y > pos_y && y < pos_y + 20) p.browser(li.urls[Math.floor((x - pos_x) / 20)]);
    b.lbtn_up(x, y);
}


function on_mouse_lbtn_dblclk(x, y) {
th.lbtn_dblclk(x, y);
    r.lbtn_dblclk(x, y);
    c.lbtn_dblclk(x, y);
}





WSH Panel Mod script discussion/help

Reply #3369
@mire777
I tried your modified bio script. Works ok and I can see all updates immediately. Great! But for some reason it doesn't have any pagination/spacing. So the text shows up as one big paragraph. The original script shows paragraph spacing, so what changed?
FYI. Some time ago last.fm changed their policy to limit retrieving to the first few sentences, looks like they may have changed their policy again as the full text is being retrieved now.

No, nothing was changed on last.fm..
If you use Last.fm API you cant receive full text, because last.fm service  truncated text to 300 char.
Instead this Marc use Echonest, which have directly access to last.fm page, and then this service provide text in json or xtml format.
But there is problem with text upadate , they do that one in week or one in month, i edited some bio and wait all month to appear .

What this script does is to have direct access to last.fm web page, no API no other services, no echonest.
This is only test to show that this work, so i didn't fix ''spacing''' there.

Here's fix for ''spacing'':

Code: [Select]
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(/&amp;/g,"&").replace(/<br>/g,"---");
            fb.trace("bio: " + ar);
            {save_file(ar);};
                }
                   
                this.doc.close();
               
} else {
fb.trace("HTTP error: " + this.xmlhttp.status);
}}}}

function save_file(x) {
try {
g_text = x;
g_text = g_text.replace(/<\/?[^>]+(>|$)/g, "").replace(/<br>/g,"---");
doc = new ActiveXObject("htmlfile");
doc.open();
div = doc.createElement("div");
div.innerHTML = g_text;
g_text = div.innerHTML;

//Check if biography exist
if (g_text.indexOf("TYPE")==0) {g_text = "This artist does not have a biography";}
else
{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.replace(/---/g,"\n"), 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;
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();
}

WSH Panel Mod script discussion/help

Reply #3370
The new now playing script works great, thank you.

WSH Panel Mod script discussion/help

Reply #3371
@mire777
I tried your modified bio script. Works ok and I can see all updates immediately. Great! But for some reason it doesn't have any pagination/spacing. So the text shows up as one big paragraph. The original script shows paragraph spacing, so what changed?
FYI. Some time ago last.fm changed their policy to limit retrieving to the first few sentences, looks like they may have changed their policy again as the full text is being retrieved now.

No, nothing was changed on last.fm..
If you use Last.fm API you cant receive full text, because last.fm service  truncated text to 300 char.
Instead this Marc use Echonest, which have directly access to last.fm page, and then this service provide text in json or xtml format.
But there is problem with text upadate , they do that one in week or one in month, i edited some bio and wait all month to appear .

What this script does is to have direct access to last.fm web page, no API no other services, no echonest.
This is only test to show that this work, so i didn't fix ''spacing''' there.

Here's fix for ''spacing'':

Code: [Select]
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(/&amp;/g,"&").replace(/<br>/g,"---");
            fb.trace("bio: " + ar);
            {save_file(ar);};
                }
                   
                this.doc.close();
               
} else {
fb.trace("HTTP error: " + this.xmlhttp.status);
}}}}

function save_file(x) {
try {
g_text = x;
g_text = g_text.replace(/<\/?[^>]+(>|$)/g, "").replace(/<br>/g,"---");
doc = new ActiveXObject("htmlfile");
doc.open();
div = doc.createElement("div");
div.innerHTML = g_text;
g_text = div.innerHTML;

//Check if biography exist
if (g_text.indexOf("TYPE")==0) {g_text = "This artist does not have a biography";}
else
{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.replace(/---/g,"\n"), 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;
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();
}

Works great. Thanks!
I noticed that the retrieved text is being displayed in the foobar console. Can that be stopped?

 

WSH Panel Mod script discussion/help

Reply #3372
@marc2003
I tried to to build a now playing script with with last fm play count sync button


i fixed it up for you. http://pastebin.com/EWbdwVri

with playcount sync in the panel, you can't have a choice of prefer now playing/follow selected track. it must always prefer the playing track. also take a look at what i've done to the mouse move/click functions to make them work.

i presume you're going to do more work on it? it's hard to see those icons without a contrasting background and the button positioning is a bit odd too?? 

WSH Panel Mod script discussion/help

Reply #3373
Works great. Thanks!
I noticed that the retrieved text is being displayed in the foobar console. Can that be stopped?

Yes.
Here is new script:

Code: [Select]
// ==PREPROCESSOR==
// @name "Biography Text"
// @author "Mire777"
// ==/PREPROCESSOR==

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(/&amp;/g,"&").replace(/<br>/g,"---");
//fb.trace("bio: " + ar);
{save_file(ar);};
}

this.doc.close();

} else {
fb.trace("HTTP error: " + this.xmlhttp.status);
}}}}

function save_file(x) {
try {
g_text = x;
g_text = g_text.replace(/<\/?[^>]+(>|$)/g, "").replace(/<br>/g,"---");
doc = new ActiveXObject("htmlfile");
doc.open();
div = doc.createElement("div");
div.innerHTML = g_text;
g_text = div.innerHTML;

//Check if biography exist
if (g_text.indexOf("TYPE")==0) {g_text = "This artist does not have a biography";}
else
{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.replace(/---/g,"\n"), 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 = 50;
offset += (delta * step);
if(offset > 0 || textheight < wh) {
offset = 0;
} else {
temp = -textheight + wh-5000;
if(offset < temp) offset = Math.round(temp / step) * step;
}
window.Repaint();
}

WSH Panel Mod script discussion/help

Reply #3374
@Marc.
Can you look at this code please?
I use this script to receive bio from wikipedia, but i have high cpu on scroll text.
Don't know where is the problem?


Code: [Select]
// ==PREPROCESSOR==
// @name "Biography Wikipedia"
// @author "Mire777"
// ==/PREPROCESSOR==

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://en.wikipedia.org/wiki/" + encodeURIComponent(artist) + "", 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]);

                   
            var st = text.indexOf( data[i].className.replace("about:/wiki/", ""));
            var str = "<p>";
            st = text.indexOf(str, st) + str.length;
            var et = text.indexOf("</html>", 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(/&amp;/g,"&");
            //fb.trace("bio: " + ar);
            {save_file(ar);};
                }
                   
                this.doc.close();
               
} else {
fb.trace("HTTP error: " + this.xmlhttp.status);
}}}}

function save_file(x) {
try {
g_text = x;
g_text = g_text.replace(/<\/?[^>]+(>|$)/g, "").replace(/<br>/g,"---");
doc = new ActiveXObject("htmlfile");
doc.open();
div = doc.createElement("div");
div.innerHTML = g_text;
g_text = div.innerHTML;

//Check if biography exist
if (g_text.indexOf("TYPE")==0) {g_text = "This artist does not have a biography";}
else
{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.replace(/---/g,"\n").replace(/amp;/g,""), 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 = 50;
offset += (delta * step);
if(offset > 0 || textheight < wh) {
offset = 0;
} else {
temp = -textheight + wh-5000;
if(offset < temp) offset = Math.round(temp / step) * step;
}
window.Repaint();
}