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: JScript Panel script discussion/help (Read 283000 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel script discussion/help

Reply #575
Directly after

Code: [Select]
var panel = new _.panel('Last.fm Similar Artists / User Charts', ['metadb']);

insert

Code: [Select]
panel.fonts.normal = _.gdiFont("font name", 12, 0); // 12 size, 0 style
panel.row_height = panel.fonts.normal.Height;

Note that changes to font settings made in the main UI preferences will override this so you'd need to reload the panel.

As for the library referencing thing, possible but could bog down running 100 queries at once??? It has no effect on me because my collection is so small but could be an issue for others. You'll need to edit samples\complete\js\list.js

On line 424, you should find this...

Code: [Select]
						this.data = _(_.get(_.jsonParse(_.open(this.filename)), 'similarartists.artist', []))
.map(function (item) {
return {
name : item.name,
width : _.textWidth(item.name, panel.fonts.normal),
url : this.lastfm_link == 0 ? item.url : 'artist HAS ' + item.name
};
}, this)
.value();

try this instead...

Code: [Select]
						this.data = _(_.get(_.jsonParse(_.open(this.filename)), 'similarartists.artist', []))
.filter(function (item) {
return fb.GetQueryItems(fb.GetLibraryItems(), 'artist IS ' + item.name).Count == 0;
})
.map(function (item) {
return {
name : item.name,
width : _.textWidth(item.name, panel.fonts.normal),
url : this.lastfm_link == 0 ? item.url : 'artist HAS ' + item.name
};
}, this)
.value();

If editing while foobar is open, make sure to reload panel to pick up changes. Also, future component updates will overwrite this file so make notes or move the edited file elsewhere and edit the preprocessor import path for list.js in the Configuration window.

Re: JScript Panel script discussion/help

Reply #576
Thanks for the help.

Indeed the query freezes foobar for 1-3 seconds, not too severe, but not optimal either, Probably could be improved by some sort of caching or limiting the last.fm query to a smaller number (and maybe occasionally firing it twice if there aren't enough artist left after the cross reference). But for what I wanted should be good enough.

Changing the font also works. Just for reference in case someone else tries using it too, theres a typo at your second line in your second codebox, 'pane.row_height' should be 'panel.row_height'.

Also one more question, is JScript capable of writing tags? Seems like multiple people are using a convoluted method to retrieve similar artists from last.fm and then later copy its values to a multivalue tag. So I was wondering if one could automatize this with JScript alone. foo_uie_biography can do something similar (makes said data available as a tag for the currently playing song), but stuff like $meta(tag,0) don't work on the provided tag so it's not that useful. I don't really expect a code for this, I'm just curious if it's doable at all.


Re: JScript Panel script discussion/help

Reply #577
Edit .take(20) on line 2...

Code: [Select]
						this.data = _(_.get(_.jsonParse(_.open(this.filename)), 'similarartists.artist', []))
.take(20)
.filter(function (item) {
return fb.GetQueryItems(fb.GetLibraryItems(), 'artist IS ' + item.name).Count == 0;
})
.map(function (item) {
return {
name : item.name,
width : _.textWidth(item.name, panel.fonts.normal),
url : this.lastfm_link == 0 ? item.url : 'artist HAS ' + item.name
};
}, this)
.value();

And yes, you can edit tags with JScript Panel. If you wanted to, you could even update every single file in the library that has the same artist as the current track because obviously the similar artists would be the same. Also, it writes multi-value tags properly.

I'll post a quick and dirty example later.

Re: JScript Panel script discussion/help

Reply #578
This will update all library files with the same artist (determined using $meta(artist,0) ) as the current track with the first 5 similar artists when you double click the panel. A blank area would be better than clicking on the text! Check the tag_name variable if you want to edit it...

Code: [Select]
function on_mouse_lbtn_dblclk() {
if (list.lastfm_mode != 0 || list.items == 0)
return;
var tags = _(list.data)
.take(5)
.map('name')
.value()
.join(';');
var tag_name = 'similar artists';
var items_to_tag = fb.GetQueryItems(fb.GetLibraryItems(), 'NOT "$ext(%path%)" IS cue AND "$meta(artist,0)" IS ' + list.artist);
if (WshShell.popup('About to update tags in ' + items_to_tag.Count + ' file(s). Continue?', 0, panel.name, popup.question + popup.yes_no) == popup.yes)
items_to_tag.UpdateFileInfoSimple(tag_name, tags, tag_name);
}

It will count the files and prompt you first. If you want it to happen automatically without the prompt, remove this line...

Code: [Select]
	if (WshShell.popup('About to update tags in ' + items_to_tag.Count + ' file(s). Continue?', 0, panel.name, popup.question + popup.yes_no) == popup.yes)

If you really want to do one track at a time...

Code: [Select]
function on_mouse_lbtn_dblclk() {
if (list.lastfm_mode != 0 || list.items == 0)
return;
var tags = _(list.data)
.take(5)
.map('name')
.value()
.join(';');
var tag_name = 'similar artists';
panel.metadb.UpdateFileInfoSimple(tag_name, tags, tag_name);
}

Re: JScript Panel script discussion/help

Reply #579
Seems to be working well.

I took the liberty to also hook up on_playback_new_track() or on_playback_starting() with your last script. However both seems to only trigger the tag writing process after you switch away from the track in question (so it basically always updates the previous track when playback has started on a new one).  Is there one that triggers right away or am I doing something fundamentally wrong?

(The goal with this one is to update the currently playing track automatically, similarly how foo_uie_biography works. With the modified list.js that only shows similar artists not yet in library I feel this might better in terms of always showing up to date info. Compared to one batch operation of every file, which would probably work better with the regular lists.js getting all similar artists that should be fairly consistent over time. It's possible there will also be a conflict between the component waveform seekbar which seems to "lock" the files while it's scanning them the first time, we'll see. That can probably be solved by delaying the writing process a couple seconds.)

Code: [Select]
function on_playback_new_track() {
    if (list.lastfm_mode != 0 || list.items == 0)
return;
var tags = _(list.data)
.take(5)
.map('name')
.value()
.join(';');
var tag_name = 'similar artists';
panel.metadb.UpdateFileInfoSimple(tag_name, tags, tag_name);
}

Re: JScript Panel script discussion/help

Reply #580
Can someone please help be with a button to launch the VMDGB webpage for an album based on the tag %vmgdb%

Code: [Select]
http://vgmdb.net/album/%vmgdb%

I would like the button to use a PNG graphic. It would be awesome if the graphic could change if the %vmgdb% tag is empty (I would use a grayed-out version of the button image so it looks disabled).

If anyone has code for a similar button (for loading a URL using a tag value), I can adapt it to fit my needs. I just didn't find anything in the Samples folder.

Thanks :)

Re: JScript Panel script discussion/help

Reply #581
or am I doing something fundamentally wrong?

Yes. you've overwritten an already existing on_playback_new_track function in panel.js and completely broken the script's ability to update when a new track starts. If any duplicate functions exist in javascript, the last always takes precedence so you need to include code from the old function. Also, a timer is required to make it work properly because it can take a second or 2 for the web request to complete on new tracks or updating when the cached data is over a day old. I've allowed 5 seconds. You can place this inside the Configuration window...

Code: [Select]
function on_playback_new_track() {
panel.item_focus_change(); //required code from old function
if (list.timer)
window.ClearTimeout(list.timer);
list.timer = window.SetTimeout(function () {
if (list.lastfm_mode != 0 || list.items == 0)
return;
var tags = _(list.data)
.take(5)
.map('name')
.value()
.join(';');
var tag_name = 'similar artists';
try {
panel.metadb.UpdateFileInfoSimple(tag_name, tags, tag_name);
} catch (e) {}
}, 5000);
}

Mr Bean...
Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// @import "%fb2k_component_path%samples\complete\js\panel.js"
// ==/PREPROCESSOR==

var panel = new _.panel('Button', ['metadb', 'custom_background']);
var buttons = new _.buttons();
var off = fb.ProfilePath + "my_images\\off.png"; // edit the folder/image names as needed
var on = fb.ProfilePath + "my_images\\on.ong";

function on_size() {
panel.size();
}

function on_metadb_changed() {
if (panel.metadb) {
var vmgdb = panel.tf("[%vmgdb%]");
//firt 4 values are x,y,w,h
buttons.buttons.vmgdb = new _.button(0, 0, 20, 20, { normal : vmgdb.length ? on : off }, function () {
if (!vmgdb.length)
return; // do nothing if tag is empty
_.run('http://vgmdb.net/album/' + vmgdb);
}, 'VMGDB');
} else {
buttons.buttons = {}
}
window.Repaint();
}

function on_paint(gr) {
panel.paint(gr);
buttons.paint(gr);
}

function on_mouse_move(x, y) {
buttons.move(x, y);
}

function on_mouse_leave() {
buttons.leave();
}

function on_mouse_lbtn_up(x, y) {
buttons.lbtn_up(x, y);
}

function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y);
}



Re: JScript Panel script discussion/help

Reply #582
Woot! Thanks mark2003.

Sadly, I get an error:

Quote from: JScript Panel
JScript Panel ({FA8128A9-B8F6-4599-AD1F-C6E6D5BBEF0C})
JavaScript runtime error:
'panel' is undefined
File: <main>
Line: 17, Col: 2
<source text only available at compile time>

Re: JScript Panel script discussion/help

Reply #583
It looks like you installed the dll only without the required files contained within the archive. I do give this link on the installation page for a reason...

http://wiki.hydrogenaud.io/index.php?title=Foobar2000:How_to_install_a_component

edit: or you could be using a pretty old version that didn't come with samples. Use the Help menu>Check for updated components.

Re: JScript Panel script discussion/help

Reply #584
Hmm, I didn't use the install, but I did copy all the files from the archive, not just the dll.

I deleted it and used the install, it's working now. Thanks again :)

Re: JScript Panel script discussion/help

Reply #585
@marc2003 , quick question about Musicbrainz script. Is is possible for it to check the currently selected artist, and compare album names in our library with musicbrainz info, for releases we already have in our library. And use different font colour, or style, or basically any kind of formatting, for those releases? Extra text, like "in library", next to it, or simple check mark, would work too.

Guessing, but tagging our library with musicbrainz album ID would help there?

Also, left click now gets us to release-group of the album, could it be edited (or small search button added next to releases) that it uses outside pages like google, itunes, spotify, whatever site really, for album search? Links option via right click gives us artist related pages.


Re: JScript Panel script discussion/help

Reply #586
I see marc2003, thanks for the help.

Re: JScript Panel script discussion/help

Reply #587
It appears that this edit results in a crash in the similar artist panel if %artist% is Hidekuni Horita. As long as a letter is changed everything is fine and other metadata doesn't seem to contribute. It also works fine with the unedited list.js. Not really sure why.

Code: [Select]
JScript Panel (Last.fm Similar Artists / User Charts by marc2003)
JavaScript runtime error:

File: foobar2000\user-components\foo_jscript_panel\samples\complete\js\list.js
Line: 427, Col: 9
<source text only available at compile time>

Code: [Select]
// ==PREPROCESSOR==
// @name "Last.fm Similar Artists / User Charts"
// @author "marc2003"
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// @import "%fb2k_component_path%samples\complete\js\panel.js"
// @import "%fb2k_component_path%samples\complete\js\list.js"
// @import "%fb2k_component_path%samples\complete\js\lastfm.js"
// ==/PREPROCESSOR==

// Requires the "Guifx v2 Transports.ttf" font which can be downloaded from
// http://blog.guifx.com/2009/04/02/guifx-v2-transport-font/

var panel = new _.panel('Last.fm Similar Artists / User Charts', ['metadb']);

panel.fonts.normal = _.gdiFont("Segoe UI", 8, 0); // 12 size, 0 style
panel.row_height = panel.fonts.normal.Height;

var lastfm = new _.lastfm();
var list = new _.list('lastfm_info', LM, TM-36, 0, 0);

panel.item_focus_change();

function on_notify_data(name, data) {
lastfm.notify_data(name, data);
}

function on_size() {
panel.size();
list.w = panel.w - (LM * 2);
list.h = panel.h - TM+60;
list.size();
}

function on_paint(gr) {
panel.paint(gr);
//gr.FillSolidRect(0, 0, panel.w, TM, panel.colours.header);
//gr.GdiDrawText(list.header_text(), panel.fonts.title, panel.colours.highlight, LM, 0, panel.w - (LM * 2), TM, LEFT);
list.paint(gr);
}

function on_metadb_changed() {
list.metadb_changed();
}

function on_mouse_wheel(s) {
list.wheel(s);
}

function on_mouse_move(x, y) {
list.move(x, y);
}

function on_mouse_lbtn_up(x, y) {
list.lbtn_up(x, y);
}

function on_key_down(k) {
list.key_down(k);
}

function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y, list);
}

function on_mouse_lbtn_dblclk() {
if (list.lastfm_mode != 0 || list.items == 0)
return;
var tags = _(list.data)
.take(5)
.map('name')
.value()
.join(';');
var tag_name = 'similar artists';
panel.metadb.UpdateFileInfoSimple(tag_name, tags, tag_name);
}

Re: JScript Panel script discussion/help

Reply #588
What I would like to do is close the "Console" and "Preferences" dialogs through a button on my JScript panel. I can open these dialogs easily through,
fb.RunMainMenuCommand("View/Console"); and
fb.RunMainMenuCommand("File/Preferences");
Calling @TheQwertiest - their modified component might be able to do this, mine can't.

TLDR: Regretfully, there is no easy way to do that, even with WSH methods. There is a messy solution though:
Spoiler (click to show/hide)

Full story: it seems, that foobar2000 creates Console and Preferences windows as separate entities, i.e. they do not have parent-child relationship with foobar2000. Thus, the only way to get those windows is via searching all top level windows, with specific caption and class, since there might be a collision in Caption with other windows.

If there was a proper parent-child relationship, we could get away with Caption only, since there is not a lot of windows in foobar2000 itself.

@marc2003 : Can I post a link to my version of jscript here? Or should I share it only privately (i.e. PM, e-mail, etc)?

Re: JScript Panel script discussion/help

Reply #589
@OoNebsoO, right click panel>links should give itunes/spotify links for most established artists. You could always contribute to musicbrainz if you find they are missing. I'm not querying the library for releases for performance reasons and I'm not really inclined to add any other options at the moment.

@Daeron , shame I didn't read my own docs when implementing that edit. I know that function can throw errors with invalid queries and I forgot to handle it properly.

Code: [Select]
							.filter(function (item) {
try {
return fb.GetQueryItems(fb.GetLibraryItems(), 'artist IS "' + item.name + '"').Count == 0;
} catch (e) {
return true;
}
})

@TheQwertiest, you can post a link to your component, no problem.

However, I don't think it will work for preferences because the caption changes every time you select a different item in the tree. Also (foobar2000.exe) is only provided by that  banned component we can't really name. And that changes to what ever component provides the option you have selected.

Re: JScript Panel script discussion/help

Reply #590
Thanks for the fix marc2003.

Re: JScript Panel script discussion/help

Reply #591
Is it possible to write more than one proper multivalue tag in one go  & if so what's the syntax?

The following didn't seem to work:

Code: [Select]
handle.UpdateFileInfoSimple("GENRE1", "Downtempo;Ambient", "GENRE1","GENRE2", "Rock;Classic Rock", "GENRE2");
Other variances I tried either only wrote one tag else only one was correctly written as a multivalue tag.

I actually want to write 5 multivalue tags at a time. UpdateFileInfoSimple can be run separately for each, but that then seems to rewrite the file 5 times, and so isn't ideal for many files.

Any help would be appreciated.

Re: JScript Panel script discussion/help

Reply #592
I thought the existing docs were clear enough... ?? :P

Code: [Select]
UpdateFileInfoSimple(field1, value1 [, field2, value2 [,...] ] [, multivalue_fields]);
if value is an empty string, field will be removed
multivalue_fields is a semicolon-separated list containing field names which need to be treated as multivalue.

So you want something like...

Code: [Select]
handle.UpdateFileInfoSimple("GENRE1", "Downtempo;Ambient", "GENRE2", "Rock;Classic Rock", "GENRE1;GENRE2");

Remember you can use UpdateFileInfoSimple on a handle list as well.

Re: JScript Panel script discussion/help

Reply #593
What I would like to do is close the "Console" and "Preferences" dialogs through a button on my JScript panel. I can open these dialogs easily through,
fb.RunMainMenuCommand("View/Console"); and
fb.RunMainMenuCommand("File/Preferences");

Here is updated code and the modded component foo_jscript_panel-v1.2.3.3[modded] (make a backup of existing one, before replacing though)
Spoiler (click to show/hide)

Also (foobar2000.exe) is only provided by that  banned component we can't really name. And that changes to what ever component provides the option you have selected.
Heh, never knew that, since I was using that component with fb2k from the day one =)
Quite a shame, that it was banned, since it adds so many useful features to fb2k...


Re: JScript Panel script discussion/help

Reply #595
Yep. You now get a progress dialog like this when working with enough files...



I've only managed to test with 2000 files as that's all I have.  :-[

edit: funny how fbuser was able to tag 500 files at once with the old function. I found my own system crashed after tagging 75.

 

Re: JScript Panel script discussion/help

Reply #596
Yep. You now get a progress dialog like this when working with enough files...



I've only managed to test with 2000 files as that's all I have.  :-[

edit: funny how fbuser was able to tag 500 files at once with the old function. I found my own system crashed after tagging 75.

Awesome. Thanks :)
Great improvement.

My max was 100 entries...

Re: JScript Panel script discussion/help

Reply #597
@marc2003-

Is there an easy way to change the included jsspm double click selection behavior into single click? At one point Falstaff had this in his original version but changed it for reasons unknown.

I'd like to ask for a 'feature' request as well. I see file properties (from samples) still creates an autoplaylist from any item clicked in that panel. Is there any possibility to change that so it is off by default instead of the way it is now? I personally do not find it useful to have an autoplaylist created from say one files MD5 hash tag. Generally I edit list.js by commenting out those lines but feel that should be optional. Right click option maybe? Don't know and just a suggestion.

Re: JScript Panel script discussion/help

Reply #598
If anyone has found the included allmusic script has stopped working, you can edit line 253 of user-components\foo_jscript_panel\samples\complete\js\text.js by replacing the http with https like this...

https://github.com/19379/foo-jscript-panel/commit/d216052e4e4863ac6187af9aa1cf968a11953943

edit: just noticed some previous posts have been nuked. I apologise to the mods and the previous poster is on the ignore list.  :P

Re: JScript Panel script discussion/help

Reply #599
Thanks