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 299853 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel script discussion/help

Reply #351
@ marc2003
I think I've found a small bug in your np_basic script. Line 38 (thumbs.mode = 5;) seems to override the saved property value for the thumbs mode. The symptom is that the thumbs setting is always reset to off whenever the script is started or foobar is started.

Re: JScript Panel script discussion/help

Reply #352
It's intentional. The "bug" is the thumbs menu being there when it really shouldn't be. Surely you must realise it looks like crap when you enable one of the options because the text is in the way. Thumbs should be left off.

edit: This updated version of thumbs.js properly hides the menu. Save it inside js_marc2003\js

https://raw.githubusercontent.com/19379/js-marc2003/master/js/thumbs.js


Re: JScript Panel script discussion/help

Reply #353
@marc2003
I've got a problem in some code that I've adapted from yours. I'm trying to enumerate through files in a folder and using the following code;
Code: [Select]
if (_.isFolder(folder)) {
var files = [];
var fl = fso.GetFolder(folder);
fb.trace("File Count", fl.files.count);
var en = new Enumerator(fl.files);
var i = 0;
for (; !en.atEnd(); en.moveNext())
i = i + 1;
fb.trace("i total", i);
}

What I see in the console output is;
File Count 48
i total 19

I think that both lines should give me the same output ie 48. What am I doing wrong?

Edit: After restarting foobar both values are the same. Curious!

Re: JScript Panel script discussion/help

Reply #354
Hello,
i would need help regarding Br3tt's / Falstaffs "JS Smooth Browser" [1]
it is similar to facets and has the ability to group library/playlist into an artists/albums with corresponding artist/cover pictures.
album grouping works fine, but when using artists it looks for an "artist.jpg" in the folder the audiofiles are located and uses that
for display. however i would like to use the artist pics that marcs script once scraped into this folder (%appdata%\foobar200\wsh_data\artists\%artist%\%artist%*.*)

i thought that the "tf_path_artist" property would set the path where to look for the artistart but it seems that does nothing.
even if i hardcode it to one specific file it won't display.
is anyone using his script and found out how to make that work?

i guess i have to modify the portion of the code where it loads the images (line ~270):
Code: [Select]
image_cache = function () {
    this._cachelist = {};
    this.hit = function (metadb, albumIndex) {
        var img = this._cachelist[brw.groups[albumIndex].cachekey];
        if (typeof(img) == "undefined" || img == null) { // if image not in cache, we load it asynchronously
            //if(!isScrolling  && !cScrollBar.timerID) { // and when no scrolling
                if(ppt.enableDiskCache) {
                    brw.groups[albumIndex].crc = check_cache(metadb, albumIndex);
                    if(brw.groups[albumIndex].crc && brw.groups[albumIndex].load_requested == 0) {
                        // load img from cache
                        if(!timers.coverLoad) {
                            if(!isScrolling  && !cScrollBar.timerID) {
                                timers.coverLoad = window.SetTimeout(function() {
                                    try {
                                        brw.groups[albumIndex].tid = load_image_from_cache(metadb, brw.groups[albumIndex].crc);
                                        brw.groups[albumIndex].load_requested = 1;
                                    }; catch(e) {};
                                    timers.coverLoad && window.ClearTimeout(timers.coverLoad);
                                    timers.coverLoad = false;
                                }, 5);
                            }; else {
                                timers.coverLoad = window.SetTimeout(function() {
                                    try {
                                        brw.groups[albumIndex].tid = load_image_from_cache(metadb, brw.groups[albumIndex].crc);
                                        brw.groups[albumIndex].load_requested = 1;
                                    }; catch(e) {};
                                    timers.coverLoad && window.ClearTimeout(timers.coverLoad);
                                    timers.coverLoad = false;
                                }, 20);
                            };
                        };
                    };
                };
                if(!ppt.enableDiskCache || !(ppt.enableDiskCache && brw.groups[albumIndex].crc && brw.groups[albumIndex].load_requested == 0)) {
                    if(brw.groups[albumIndex].load_requested == 0) {              
                        // load img default method
                        if(!timers.coverLoad) {
                            timers.coverLoad = window.SetTimeout(function() {
                                if(ppt.albumArtId==5) { // genre
                                    var arr = brw.groups[albumIndex].groupkey.split(" ^^ ");
                                    try {
                                        var genre_img = gdi.Image(images.path + "genres\\" + arr[0] + ".jpg");
                                    } catch(e) {
                                        var genre_img = gdi.Image(images.path + "genres\\" + "default.jpg");
                                    };
                                    brw.groups[albumIndex].cover_img = g_image_cache.getit(metadb, albumIndex, genre_img);
                                    brw.repaint();
                                }; else {
                                    this.albumArtId = ppt.albumArtId == 0 ? albumIndex + 5 : ppt.albumArtId;
                                    utils.GetAlbumArtAsync(window.ID, metadb, this.albumArtId, true, false, false);
                                };
                                timers.coverLoad && window.ClearTimeout(timers.coverLoad);
                                timers.coverLoad = false;
                            }, (!isScrolling  && !cScrollBar.timerID ? 5 : 20));
                        };
                    };
                };
            //};
        };
        return img;
    };

and insert another exception like "if(ppt.albumArtId==5) { // genre" for genre.
i tried this:
first i added a new property called
Code: [Select]
tf_path_artist_source: fb.TitleFormat(window.GetProperty("_PROPERTY: Artist Images Folder (source)", fb.ProfilePath+"\\wsh_data\\artists\\$meta(album artist,0)\\")), 
and added in the function "image_cache"
Code: [Select]
if(ppt.albumArtId==4) { // test for album art
                                    try {
                                        var artist_img = gdi.Image(ppt.tf_path_artist_source.EvalWithMetadb(metadb) + "test.jpg");
                                    } catch(e) {
                                        var artist_img = gdi.Image(ppt.tf_path_artist_source.EvalWithMetadb(metadb) + "test.jpg");
                                    };
                                    brw.groups[albumIndex].cover_img = g_image_cache.getit(metadb, albumIndex, artist_img);
                                    brw.repaint();
                                };

so far so good, the test.jpg in the corresponding artist folder is being displayed, yay! however i have no idea how to do wildcard calls, because the files are called something like "artist_1235123.jpg" or "artist_123412.png".

I don't think that's trivial but there are already masks defined in the properties to look for *cover*.* front.* *.jpg and last *.* so i guess that's already implemented in some way, i just have no idea how to do this.

you probably laugh at me now, but i'm proud that i made it this far :D
any help is appreciated :) for now i have set the AlbumArtID for artist grouping to display the front cover, that's ok for me too, but it would be nice to have real artist pics displayed.

[1] http://br3tt.deviantart.com/art/JS-Smooth-Browser-571376160


Re: JScript Panel script discussion/help

Reply #355
I think you need to delete all the cached images that were generated after the script first ran. IIRC, the folder is inside js_br3tt,

Re: JScript Panel script discussion/help

Reply #356
marc2003, how do you feel about the possibility of adding a secondary/fallback titleformatting pattern in your scripts that pull album/artist art (presumably from last.fm), for cases when the primary pattern have failed to retrieve anything?

Would be useful in scenarios where artists have changed names multiple times, are simply known under two different names (like Japanese writing vs Latin letters) or really just whenever ALBUM ARTIST and ARTIST are different and one might retrieve useful information while the other would not. The last.fm database is not exactly consistent enough to commit to one style of formatting and it wouldn't be desired to do so either.

Also noticed you 'added library tracks only' support for the last.fm cover art downloader script (was a while ago, but only checked it now), thanks for that.

Re: JScript Panel script discussion/help

Reply #357
Previously someone asked for multiple artist support for collaborations etc and I said no because it would be a real PITA. Buf if it's for different variants of the same artist which can share the same folder, it could be doable.

Re: JScript Panel script discussion/help

Reply #358
Well, what I'm asking should be a lot more simple than that.

Run query with %artist%. If a match has been found, save cover art to $directory_path(%path%)\lastfm.jpg and stop.
Otherwise run another query with %album artist%. If a match has been found, save cover art to $directory_path(%path%)\lastfm.jpg and stop.

(If the identical filenames are a problem, the result of the second query can just always be saved as lastfm2.jpg instead.)

Re: JScript Panel script discussion/help

Reply #359
I didn't realise you were talking about the album art script. Modifying that should be easier.

Re: JScript Panel script discussion/help

Reply #360
About 'now playing (basic)', is it possible to change fallback font?

 

Re: JScript Panel script discussion/help

Reply #362
what do you mean by "fallback"??
The font that replaces regular font when it can't can't display certain characters or script can't recognize font at all (name).
Looks like this (it's draw.string but with GdiDrawText it's the same). Looks like Microsoft Sans Serif to me:

http://i.cubeupload.com/iNSAWI.png


Re: JScript Panel script discussion/help

Reply #363
Well I don't know anything about that. Use something else to display the track title. It's not like there is a shortage of alternatives.

Re: JScript Panel script discussion/help

Reply #364
Of course, it was only a question. Thanks for scripts anyway.

Re: JScript Panel script discussion/help

Reply #365
I guessed it was the soundtrack for the Amelie movie so found the track title on wikipedia. It looks OK with all these different fonts??



The code for the above...

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_profile_path%js_marc2003\js\lodash.min.js"
// @import "%fb2k_profile_path%js_marc2003\js\helpers.js"
// ==/PREPROCESSOR==

var tag = "La valse d'Amélie";

var text_colour = _.RGB(192, 192, 192);
var font_names = ["Segoe UI", "Tahoma", "Microsoft Sans Serif", "Verdana", "Calibri", "Impact"];
var fonts = _.map(font_names, function (item) {
return _.gdiFont(item, 32);
});

function on_paint(gr) {
gr.FillSolidRect(0, 0, window.Width, window.Height, _.RGB(30, 30, 30));
_.forEach(fonts, function (item, i) {
gr.GdiDrawText(item.Name, item, text_colour, 5, 5 + (i * 45), window.Width - 10, 40, LEFT);
gr.GdiDrawText(tag, item, text_colour, 5, 5 + (i * 45), window.Width - 10, 40, RIGHT);
});
}

Re: JScript Panel script discussion/help

Reply #366
- Yes, it is clearly this particular font problem, no doubt about it at any stage. It cannot display certain characters (incl. national).
- I thought that fallback font option is included somewhere in scripts and you can change it, for example: if you put Ariol instead of Arial  :) certain default font is displayed
- it's not - not a problem, must be some system setting(? or whatever),

Re: JScript Panel script discussion/help

Reply #367
- I thought that fallback font option is included somewhere in scripts and you can change it, for example: if you put Ariol instead of Arial  :) certain default font is displayed

It looks like the gdi.Font function built in to the component handles that...

Code: [Select]
var font = gdi.Font("ariol", 12);
fb.trace(font.Name); // outputs "Microsoft Sans Serif"

Re: JScript Panel script discussion/help

Reply #368
Can anyone link a biography script that fetches the bio from Wikipedia?

Re: JScript Panel script discussion/help

Reply #369
Now that foo_uie_biography seems to have stopped working, I'm looking for something that (upon selection/playing) downloads artist art (from last.fm or where ever) and saves it to a predefined folder (if there isn't already one).

I think that the thumbs sample does almost what I want it to, however I have a couple of questions:
1. Is it possible to change the path the images get downloaded to as well as the way the images are named? I looked through the code and I suspect I found the lines I would have to change...but yeah, I can't code, so I stopped before breaking something...
2. In contrast to the biography viewer, thumbs seems rather slow with respect to fetching the images. Is there something I can do about this? By slow I mean 5 seconds instead of ~ 1.
3. Biography viewer somehow only downloaded square images...is this also possible with thumbs? For layout reasons I'd prefer the same ratio for all the pictures...

Thank you very much in advance!

Re: JScript Panel script discussion/help

Reply #370
1) No, I'm not providing help on how to change filenames. They must keep the ID from the source on last.fm to prevent them being downloaded again.

The album art preferences in foobar support wildcards so you can specify a path to the folder meaning any component like EsPlaylist/facets/etc can use the images...

Code: [Select]
D:\path\to\wsh_data\artists\%artist%\*.jpg

2) I have no way to detect when images are downloaded so the script runs on a timer checking the folder for changes every 3 seconds.

The script used to detect when an image had completed and refreshed itself but that prevented you from closing foobar while it was running so I had to remove that feature.

3) Use a square panel with one of the crop options enabled.

Basically, if you don't like how it works... don't use it.

Re: JScript Panel script discussion/help

Reply #371
Not quite what I was hoping for :)
Thanks anyway, keep up your great work!

Re: JScript Panel script discussion/help

Reply #372
Hi,
I noticed a weird thing with the LastFM biography JScript : quite often, informations about a specific artist disapear (the LastFM biography file for the artist is still on my HDD, but when I open this file using Notepad or a similar software, it’s blank. The biography text isn’t here anymore).
Each time,  I have to delete the empty file stored on my HDD in order to be able to recover the artist biography…  It’s quite disturbing. I noticed, most of the time, it  happens with artists I listen very often (e.g : Pink Floyd)
It looks to me that, from time to time, LastFM biography script tries to update informations already stored on the dedicated local folder and, somehow, fail to do so.
So far, I assumed when LastFM biography script found a file with the artist biography stored in the local folder, it didn’t try to connect  to LastFM site in order to update biography, but maybe I was wrong … Was I ?
If there is some kind of « automatic update » feature included in the script, is there a way to disable it ?
Thanks a lot for the help !
YOGAMAN
P.S. Obviously, english is not my mother tongue, so please, excuse my french ;-).

Re: JScript Panel script discussion/help

Reply #373
Hello !

I really enjoy your Jscript plugin. Thanks for the hard work.

I'm not a programmer, but through errors I've made many modifications to your basic examples in order to fit my needs.

Unfortunately, one thing I can't do no matter what.

I want to have toggle buttons - when I press a button it should stay pressed and activate an option. When I press it once more, it should deselect itself and deactivate that option.

I've tried modifying your example with Simple themed buttons, but with no success.

PS: Any work around would be OK for me if my requirement can't be done with this plugin.

Screenshot - Foobar - My buttons

Here is the original script:

Code: [Select]
// vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:

// ==PREPROCESSOR==
// @name "SimpleThemedButton"
// @author "T.P Wang"
// ==/PREPROCESSOR==

function RGB(r, g, b) {
    return (0xff000000 | (r << 16) | (g << 8) | (b));
}

ButtonStates = {
    normal: 0,
    hover: 1,
    down: 2,
    hide: 3
}

var DT_TOP = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;

var g_theme = window.CreateThemeManager("Button");
var g_font = gdi.Font("Tahoma", 12);

function SimpleButton(x, y, w, h, text, fonClick, state) {
    this.state = state ? state : ButtonStates.normal;
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.text = text;
    this.fonClick = fonClick;
   
    this.containXY = function (x, y) {
        return (this.x <= x) && (x <= this.x + this.w) && (this.y <= y) && (y <= this.y + this.h);
    }
   
    this.changeState = function (state) {
        var old = this.state;
        this.state = state;
        return old;
    }

    this.draw = function (gr) {
        if (this.state == ButtonStates.hide) return;
       
        switch (this.state)
        {
        case ButtonStates.normal:
            g_theme.SetPartAndStateId(1, 1);
            break;
           
        case ButtonStates.hover:
            g_theme.SetPartAndStateId(1, 2);
            break;
           
        case ButtonStates.down:
            g_theme.SetPartAndStateId(1, 3);
            break;
           
        case ButtonStates.hide:
            return;
        }

        g_theme.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
        gr.GdiDrawText(this.text, g_font, RGB(0,0,0), this.x, this.y, this.w, this.h, DT_CENTER| DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
    }

    this.onClick = function () {
        this.fonClick && this.fonClick();
    }
}

function drawAllButtons(gr) {
    for (var i in $buttons) {
        $buttons[i].draw(gr);
    }
}

function chooseButton(x, y) {
    for (var i in $buttons) {
        if ($buttons[i].containXY(x, y) && $buttons[i].state != ButtonStates.hide) return $buttons[i];
    }

    return null;
}

$buttons = {
    Console: new SimpleButton(5, 5, 80, 26, "Console", function () {
        fb.ShowConsole();
    }),
    Configure: new SimpleButton(5, 40, 80, 26, "Configure", function () {
        window.ShowConfigure();
    })
}

var cur_btn = null;
var g_down = false;

// --- APPLICATION START

function on_paint(gr) {
    drawAllButtons(gr);
}

function on_mouse_move(x, y) {
    var old = cur_btn;
    cur_btn = chooseButton(x, y);
   
    if (old == cur_btn) {
        if (g_down) return;
    } else if (g_down && cur_btn && cur_btn.state != ButtonStates.down) {
        cur_btn.changeState(ButtonStates.down);
        window.Repaint();
        return;
    }
       
    old && old.changeState(ButtonStates.normal);
    cur_btn && cur_btn.changeState(ButtonStates.hover);
    window.Repaint();
}

function on_mouse_leave() {
    g_down = false;
   
    if (cur_btn) {
        cur_btn.changeState(ButtonStates.normal);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x, y) {
    g_down = true;
   
    if (cur_btn) {
        cur_btn.changeState(ButtonStates.down);
        window.Repaint();
    }
}

function on_mouse_lbtn_up(x, y) {
    g_down = false;
   
    if (cur_btn) {
        cur_btn.onClick();
        cur_btn.changeState(ButtonStates.hover);
        window.Repaint();
    }
}

// --- APPLICATION END

Re: JScript Panel script discussion/help

Reply #374
Samples updated: https://github.com/19379/js-marc2003/releases


Hi Marc,
I noticed most of the jscripts you created are no longer stored on GitHub (error 404). Maybe you choose to remove them for some reason (in that case, I hope they'll be back soon because they're so helpfull. Thanks by the way !), but if the removal wasn't done on purpose, then there is a problem with GitHub.