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 1400026 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

WSH Panel Mod script discussion/help

Reply #4125
you might want to limit how many you attempt at once though.
Actually, this is a must.

When you for example update many items via the properties dialog the necessary update operations will be queued and only one thread for updating the files is spawned. With WSH Panel Mod a separate update process is spawned for each affected file. From my own experience this can lead to locking up your computer in case of too many threads with some corrupted files as a result. Therefore I limited the number of entries, which can be updated in one run to 500, which seems to be safe on my system.

WSH Panel Mod script discussion/help

Reply #4126
Well
now you can use JSON

For menu button you have done it before so I guess its not that hard.

I suggest that you use another metadata field to save these values e.g LASTFMTOPTAGS instead of GENRE.
g_metadb.UpdateFileInfoSimple("LASTFMTOPTAGS", tags, "LASTFMTOPTAGS");

*Apply on empty tag

fileinfo = g_metadb.GetFileInfo();
idx = fileinfo.MetaFind("LASTFMTOPTAGS");
vidx = fileinfo.MetaValueCount(idx);

if (vidx == 0 )  //WRITE TAG CODE HERE//


*Rewrite existing Tags

Look into concat() function to join arrays and then write tags

-Manualy Tag>
*list of tags from last.fm (user can select tag to apply)

The array list of tags  must be converted to menu entries.

var _menu = window.CreatePopupMenu();
array = [];

for (i = 0; i < array.length; i++)
        {
            _menu.AppendMenuItem(MF_STRING, i + 1, array);
        }

        var idx = _menu.TrackPopupMenu(30, 300);

        if (idx > 0)

            //WRITE CODE HERE TO APPLY TO//  array[idx - 1]);


-Tag all tracks in playlist.. (it goes trough active playlist and tag all songs one by one)
Not so easy...

-Write 'similar artist to tag' (you can use this to play similar artist from library later)
You would have to get artist.getSimilar json

http://www.last.fm/api/show/artist.getSimilar


Thanks Zeremy

WSH Panel Mod script discussion/help

Reply #4127
Zeremy or someone else..
I have this response:


{"similartracks":{"track":[{"name":"Strong Enough","playcount":"593863","mbid":"5456fafa-c9fd-4e3c-9170-6a61b858c49e","match":"1","url":"http:\/\/www.last.fm\/music\/Cher\/_\/Strong+Enough","streamable":{"#text":"0","fulltrack":"0"},"duration":"220000","artist":{"name":"Cher","mbid":"bfcc6d75-a6a5-4bc6-8282-47aec8531818","url":"http:\/\/www.last.fm\/music\/Cher"},"image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/71997588.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/71997588.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/71997588.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/71997588.png","size":"extralarge"}]},{"name":"All or Nothing","playcount":"253721","mbid":"a88735e6-b35c-4379-8ef7-bbd2b793ccf4","match":"0.872756","url":"http:\/\/www.last.fm\/music\/Cher\/_\/All+or+Nothing","streamable":{"#text":"0","fulltrack":"0"},"duration":"238000","artist":{"name":"Cher","mbid":"bfcc6d75-a6a5-4bc6-8282-47aec8531818","url":"http:\/\/www.last.fm\/music\/Cher"}.......


I can get frist value, but how to get second ''artist.name''?

WSH Panel Mod script discussion/help

Reply #4128
Zeremy or someone else..
I have this response:


{"similartracks":{"track":[{"name":"Strong Enough","playcount":"593863","mbid":"5456fafa-c9fd-4e3c-9170-6a61b858c49e","match":"1","url":"http:\/\/www.last.fm\/music\/Cher\/_\/Strong+Enough","streamable":{"#text":"0","fulltrack":"0"},"duration":"220000","artist":{"name":"Cher","mbid":"bfcc6d75-a6a5-4bc6-8282-47aec8531818","url":"http:\/\/www.last.fm\/music\/Cher"},"image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/71997588.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/71997588.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/71997588.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/71997588.png","size":"extralarge"}]},{"name":"All or Nothing","playcount":"253721","mbid":"a88735e6-b35c-4379-8ef7-bbd2b793ccf4","match":"0.872756","url":"http:\/\/www.last.fm\/music\/Cher\/_\/All+or+Nothing","streamable":{"#text":"0","fulltrack":"0"},"duration":"238000","artist":{"name":"Cher","mbid":"bfcc6d75-a6a5-4bc6-8282-47aec8531818","url":"http:\/\/www.last.fm\/music\/Cher"}.......


I can get frist value, but how to get second ''artist.name''?


To analyze json I suggest using notepad++ with plugins JSTool and JSON Viewer.
You can see the data as a tree.



so the answer is
similiartracks.track[1].artist.name

also read http://www.w3schools.com/js/js_json.asp


 


WSH Panel Mod script discussion/help

Reply #4132
How to delay line from executing, like a sleep() function
Is it window.SetInterval(on_timer, 5000) ??
(I want to do a task after 5 seconds executing previous one )

WSH Panel Mod script discussion/help

Reply #4133
WSH scripts are written in j script  and java script is  pretty much the same (ECMAscript compatible) so java script libraries like d3,jQuery will work in WSH panel ??
Most JavaScript frameworks expect to run in a web browser and require certain programming interfaces. While WSH Panel Mod uses the same or at least very similar programming language it provides a different set of programming interfaces, for example access to the foobar2000 media library instead of access to the HTML DOM and Win32 based drawing functions instead of HTML5 canvas support. I don't think you'll find a lot of JavaScript frameworks which work in WSH Panel Mod.

WSH Panel Mod script discussion/help

Reply #4134
How to delay line from executing, like a sleep() function
Is it window.SetInterval(on_timer, 5000) ??
(I want to do a task after 5 seconds executing previous one )

You can use window.SetTimeout():

Code: [Select]
window.SetTimeout(function() { 
    fb.trace("show after 5 seconds");
}, 5000);

See the interfaces documentation included with component.

Regards,
bas

WSH Panel Mod script discussion/help

Reply #4135
WSH scripts are written in j script  and java script is  pretty much the same (ECMAscript compatible) so java script libraries like d3,jQuery will work in WSH panel ??
Most JavaScript frameworks expect to run in a web browser and require certain programming interfaces. While WSH Panel Mod uses the same or at least very similar programming language it provides a different set of programming interfaces, for example access to the foobar2000 media library instead of access to the HTML DOM and Win32 based drawing functions instead of HTML5 canvas support. I don't think you'll find a lot of JavaScript frameworks which work in WSH Panel Mod.


one thing i've stumbled across that does work is underscore.js

http://underscorejs.org/

WSH Panel Mod script discussion/help

Reply #4136
Interesting. So Underscore is a notable exception because it does not assume any specific features besides the ones provided by the language. If you find any others like this they will probably work as well.

WSH Panel Mod script discussion/help

Reply #4137
I was try both last.fm JSON and XML format request while foobar is playing, and foobar always stop responding for 1-2sec while script executing.
How to prevent this?
I have problem on this simple script:
(this especially happens if i send one request after another ex. 1st func. call XML (artist.getsimilar) , 2nd func. call XML (gettoptracks)..)

Code: [Select]
this.TopTracks = function()
{

url = "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=" + ART + "&api_key=" + API;

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.open("GET",url,false);
xmlhttp.send("");

data = xmlhttp.ResponseText;
xmlhttp.Close;
fb.trace("data: " + data);

xmlhttp.Close;  
xmlhttp.Close;

}

WSH Panel Mod script discussion/help

Reply #4138
Code: [Select]
xmlhttp.open("GET",url,false);


the false there is telling the script to make a synchronous request which blocks the script until it's done. instead, you should be making Asynchronous requests. as well as changing the above to true, you need to add a bit more code like this...

Code: [Select]
var url = ...
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", url, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            //do something with xmlhttp.responsetext
        } else {
            fb.trace(xmlhttp.responsetext || "HTTP error: " + xmlhttp.status);
        }
    }
}

WSH Panel Mod script discussion/help

Reply #4139
WSH scripts are written in j script  and java script is  pretty much the same (ECMAscript compatible) so java script libraries like d3,jQuery will work in WSH panel ??
Most JavaScript frameworks expect to run in a web browser and require certain programming interfaces. While WSH Panel Mod uses the same or at least very similar programming language it provides a different set of programming interfaces, for example access to the foobar2000 media library instead of access to the HTML DOM and Win32 based drawing functions instead of HTML5 canvas support. I don't think you'll find a lot of JavaScript frameworks which work in WSH Panel Mod.


one thing i've stumbled across that does work is underscore.js

http://underscorejs.org/

@marc2003

Have you tried lodash.js https://lodash.com/ or lazy.js http://danieltao.com/lazy.js/ ?

WSH Panel Mod script discussion/help

Reply #4140
i can't even begin to understand those lazy.js docs....    i think i'll stick to my simple arrays and loops.


WSH Panel Mod script discussion/help

Reply #4142
Code: [Select]
xmlhttp.open("GET",url,false);


the false there is telling the script to make a synchronous request which blocks the script until it's done. instead, you should be making Asynchronous requests. as well as changing the above to true, you need to add a bit more code like this...

Code: [Select]
var url = ...
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", url, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            //do something with xmlhttp.responsetext
        } else {
            fb.trace(xmlhttp.responsetext || "HTTP error: " + xmlhttp.status);
        }
    }
}

Thank you :-)

WSH Panel Mod script discussion/help

Reply #4143
@mire777

*Apply on empty tag

fileinfo = g_metadb.GetFileInfo();
idx = fileinfo.MetaFind("LASTFMTOPTAGS");
vidx = fileinfo.MetaValueCount(idx);

if (vidx == 0 )  //WRITE TAG CODE HERE//

This does not work.

Use
Code: [Select]
g_metadb = fb.GetFocusItem();
lastfmtoptags = fb.TitleFormat("%lastfmtoptags%").EvalWithMetadb(g_metadb);

if (lastfmtoptags == "?") {/////write code here////}

WSH Panel Mod script discussion/help

Reply #4144
Have you tried lodash.js https://lodash.com/


i've done a little reading up on this and it's most definitely recommended over using underscore.js so forget i even mentioned that.

i've started using it and everything i've tried so far works perfectly.

WSH Panel Mod script discussion/help

Reply #4145
Dear friends, especially Marc2003

I am using your scripts for long time. Recently following your suggestion, I have modify it to add the Last.fm API and now all the panels function properly
There is only disturbing thing:

The last.fm panel for similar artists shows related artists but when I click the mouse in, it delays for several seconds (about 10s) then Foobar notice window shows up "Unable to launch your default browser". Before when I click to it, the related last.fm webpage will open in my browser.

I have followed your suggestion about typing  "Windows + R" and type a url, everything loads fine. Chrome is my default browser (has been set in Window 8 setting for default program, no firewall blocking etc)

Also I found that other embedded urls in my FOOBAR2000 also cannot be opened.

I am using 64 bit, windows 8 laptop with portable install of latest Foobar2000 version

IS THERE ANYTHING WRONG WITH MY SETTING UP OF FOOBAR2000?? Please give me some clues?
Thank you very much for your help!!!!!

WSH Panel Mod script discussion/help

Reply #4146
given launching websites from the run dialog works, i'm not really sure what the problem is.

you can try opening marc2003\common8.js (or even common7.js) in a decent text editor. windows notepad won't open them properly so don't use that.

find this line of text...

Code: [Select]
this.browser = function(c) {


replace this function

Code: [Select]
    this.browser = function(c) {
        if (!this.run(c)) this.MsgBox("Unable to launch your default browser.", 0, this.name);
    }


with

Code: [Select]
this.browser = function(c) {
    var WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run(c);
}


if foobar is running, make sure you open/close the editor dialog for the script to pickup the changes.

the script should now crash but the important thing is you might get a more meaningful error message than what you had previously.

WSH Panel Mod script discussion/help

Reply #4147
Is it possible to alter the common7 rating sample (or similar) into a binary switch for mood for use with Falstaff's JSPlaylist mood column? So far that seems like it would do what I want the best if possible. EG: The rating can work when playing OR selected and not playing.

I know I could just tap the icon in the playlist but my most used playlist is an autoplaylist setup like so: %play_count% IS 0. When the song vanishes from the playlist after its count reaches 1 I can still rate it if it's playing. Very handy if I happen to miss rating before the minute is up. Thinking the same thing for mood would be nice.

WSH Panel Mod script discussion/help

Reply #4148
if no one provides you with a script, make another autoplaylist to show recently played tracks.

WSH Panel Mod script discussion/help

Reply #4149
Already have one. I'll just wing it.