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: Spider Monkey Panel (foo_spider_monkey_panel) (Read 341776 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #250
Is there a way to get an arbitrary URL to open in a browser from FSM (or jscript)? I was thinking this was simple, then when I tried to implement it, I realized that all the times I'd seen it done required foo_run, along with pre-defined URLs.
Maybe Shell.ShellExecute will work?
Code: [Select]
const objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute("https://hydrogenaud.io");

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #251
Is there a way to get an arbitrary URL to open in a browser from FSM (or jscript)? I was thinking this was simple, then when I tried to implement it, I realized that all the times I'd seen it done required foo_run, along with pre-defined URLs.

Use Wshshell.Run with WScript.Shell

Sample function
https://github.com/marc2k3/smp_2003/blob/ed613ee3875cc914ea102a763758457431cdfc25/js/helpers.js#L516

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #252
Back from my holidays, the lastfm album art downloader is not working anymore. It is an old script by marc2003 that I modified now and then. It is quite obvious that the reason is a change in the lastfm web page HTML code. It is likely a silly problem, but I'm not familiar with HTML, so maybe someone here can help me out.

The following is - as far as I understand - the relevant code which needs some change:
Code: [Select]
include(fb.ComponentPath + 'samples\\complete\\js\\lodash.min.js');
include(fb.ComponentPath + 'samples\\complete\\js\\helpers.js')
include(fb.ComponentPath + 'samples\\complete\\js\\panel.js');

var x = new ActiveXObject("Microsoft.XMLHTTP");
var ar = panel.tf("$meta_sep(artist,', ',' and ')");
var al = panel.tf("%album%");

x.open("GET", "https://www.last.fm/music/" + encodeURIComponent(ar) + "/" + encodeURIComponent(al) + "/+images", true);
x.setRequestHeader("If-Modified-Since", "Thu, 01 Jan 1970 00:00:00 GMT");
x.send();

var o = _.first(_.filter(_getElementsByTagName(x.responseText, "img"), {"className" : "image-list-image"}));


The issue is in the last line of the above code. It used to fetch the first of the album covers on the album lastfm page, such as this one. I've been looking at this part of the HTML code (from line 1077 in the aforementioned example page):
Code: [Select]
    <ul class="image-list">
       
            <li class="image-list-item-wrapper">
                <a href="/music/Alessandro+Alessandroni/Prisma+Sonoro/+images/829db16b90ed471cbbfe248ef08ada39" class="image-list-item">
                    <img
                        src="https://lastfm-img2.akamaized.net/i/u/avatar170s/829db16b90ed471cbbfe248ef08ada39.webp"
                        alt="None"
                    >
                </a>
            </li>
       
            <li class="image-list-item-wrapper">
                <a href="/music/Alessandro+Alessandroni/Prisma+Sonoro/+images/72cd2e7b55604336b9003de58bf58d24" class="image-list-item">
                    <img
                        src="https://lastfm-img2.akamaized.net/i/u/avatar170s/72cd2e7b55604336b9003de58bf58d24.webp"
                        alt="None"
                    >
                </a>
            </li>
       
            <li class="image-list-item-wrapper">
                <a href="/music/Alessandro+Alessandroni/Prisma+Sonoro/+images/d002704049d844f4ba5dcc647614a483" class="image-list-item">
                    <img
                        src="https://lastfm-img2.akamaized.net/i/u/avatar170s/d002704049d844f4ba5dcc647614a483.webp"
                        alt="None"
                    >
                </a>
            </li>
       
    </ul>


I guess the parameters in the _getElementsByTagName function do not match the page HTML code anymore, but I cannot reference it properly.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #253
Maybe Shell.ShellExecute will work?
Code: [Select]
const objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute("https://hydrogenaud.io");

Use Wshshell.Run with WScript.Shell

Sample function
https://github.com/marc2k3/smp_2003/blob/ed613ee3875cc914ea102a763758457431cdfc25/js/helpers.js#L516
Thanks, guys. thisban's code worked great, but I already had Marc's helper script in my theme so I saved a line of code :)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #254
Back from my holidays, the lastfm album art downloader is not working anymore. It is an old script by marc2003 that I modified now and then. It is quite obvious that the reason is a change in the lastfm web page HTML code. It is likely a silly problem, but I'm not familiar with HTML, so maybe someone here can help me out.

The following is - as far as I understand - the relevant code which needs some change:
...

I guess the parameters in the _getElementsByTagName function do not match the page HTML code anymore, but I cannot reference it properly.
A few things:
1) The img's don't have "image-list-image" class attached to them anymore, so all images are being filtered out. You'd have to completely remove the _.filter section, or first get all "a" tags and filter by class="image-list-item" and then get all images from inside those. I haven't used those methods enough to know how to write that relevant code though.
2) Those are .webp images. Can SMP even handle those, presuming they can be scraped correctly?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #255
A few things:
1) The img's don't have "image-list-image" class attached to them anymore, so all images are being filtered out. You'd have to completely remove the _.filter section, or first get all "a" tags and filter by class="image-list-item" and then get all images from inside those. I haven't used those methods enough to know how to write that relevant code though.
2) Those are .webp images. Can SMP even handle those, presuming they can be scraped correctly?

Thanks, I'll try your suggested fixes. I don't know about the webp format yet. I wanted to fix the file download anyway, as a mean to better understand how to use the xmlhttp object. I found instructions on how to manually download the webp file as a jpg, so maybe it's possible to edit the code in order to emulate such method. Perhaps a better alternative would be to get the jpg url from the meta tag (line 65 of the HTML code in the above example page). This might be my next question.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #256
@davideleo , I think it should be fixed with the latest marc2003 scripts (https://github.com/marc2k3/smp_2003). Download them and put them in samples/complete.

@MordredKLB , SMP doesn't support .webp images.
[EDIT] MSDN indicates that there's some built-in support for .webp images, but there is no information on when and where such support is available (https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-constant-image-file-format-constants)

PS: I might have found a workaround that might allow me to work around MSVS issues.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #257
@davideleo , I think it should be fixed with the latest marc2003 scripts (https://github.com/marc2k3/smp_2003). Download them and put them in samples/complete.

Thanks for the link, but I cannot find the "Last.fm Album Art Downloader" script. As far as I know marc2003 stopped updating it since a few years, at least publicly.

However I tried fetching the jpg URL in the page metadata with this code:
Code: [Select]
let doc = new ActiveXObject('htmlfile');
doc.open();
doc.write(x.responseText);                       
var o = doc.querySelector("meta[property='og:image']").getAttribute("content");
doc.close();

The code correctly assigns the url, such as this one, to the variable "o", but the "download" visual basic script doesn't seem to like it as an argument. The code that runs the visual basic script is the following:
Code: [Select]
_runCmd("cscript //nologo " + _q(fb.ComponentPath + "samples\\complete\\vbs\\download.vbs") + " " + _q(o) + " " + _q(f), false);
where the variable "f" is the destination filename.

I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #258
The code correctly assigns the url, such as this one, to the variable "o", but the "download" visual basic script doesn't seem to like it as an argument.

Problem solved. The issue was a leftover line of the previous code (commented out in the script below) which I naively thought to be harmless.


Code: [Select]
                        let doc = new ActiveXObject('htmlfile');
                        doc.open();
                        doc.write(x.responseText);                       
                        var o = doc.querySelector("meta[property='og:image']").getAttribute("content");
                        doc.close();                     
// var u = o.src.replace("avatar170s", "ar0");
     _runCmd("cscript //nologo " + _q(fb.ComponentPath + "samples\\complete\\vbs\\download.vbs") + " " + _q(o) + " " + _q(f), false);
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #259
Hello,

When I use image in my panels, for example with gdi.Image('path.to.img'), I can't delete the file from filesystem without closing foobar2000. Is there a best practice to release image handle?
Kind regards,
Nicolas

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #260
Hi, I just noticed that when I print out the track title for example ( fb.TitleFormat('%title%'); ) the character & does not display correctly. This is what it looks like. It's not a huge deal, but it would be nice if I could fix it. And ideas?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #261
Hi, I just noticed that when I print out the track title for example ( fb.TitleFormat('%title%'); ) the character & does not display correctly. This is what it looks like. It's not a huge deal, but it would be nice if I could fix it. And ideas?
What method are you calling to print the text? Which font are you using?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #262
I'm a little confused about the encodeURIComponent() function.
The lastfm album art downloader script uses the function to get the right URL of the lastfm album page, like this:
Code: [Select]
include(fb.ComponentPath + 'samples\\complete\\js\\panel.js');

var x = new ActiveXObject("Microsoft.XMLHTTP");
var ar = panel.tf("$meta_sep(album artist,', ',' and ')");
var al = panel.tf("%album%");
x.open("GET", "https://www.last.fm/music/" + encodeURIComponent(ar) + "/" + encodeURIComponent(al), true);

This usually worked fine, but with the Damned's "The MCA Singles A's + B's" I got
https://www.last.fm/music/The%20Damned/The%20MCA%20Singles%20A's%20%2B%20B's
whereas the URL of the lastfm album page is
https://www.last.fm/music/The%20Damned/The%20MCA%20Singles%20A's%20%252B%20B's

The encodeURIComponent() function properly converts the "+" character to "%2B", but the lastfm URL shows a sort of double encoding converting the "%" character to "%25" in turn, and thus the "+" character becomes "%252B".
Therefore I changed the code applying the function twce, like this:
Code: [Select]
"https://www.last.fm/music/" + encodeURIComponent(encodeURIComponent(ar)) + "/" + encodeURIComponent(encodeURIComponent(al))
getting a weird
https://www.last.fm/music/The%2520Damned/The%2520MCA%2520Singles%2520A's%2520%252B%2520B's
which surprisingly (at least for me) works as well.

Can anybody explain me the logic of this double encoding?


I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #263
Can anybody explain me the logic of this double encoding?
It seem that's just a bug in lastfm url generation.
`encodeURIComponent` seems to perform exactly as it's described in JavaScript docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #264
Version: 1.2.2-preview
Link: https://github.com/TheQwertiest/foo_spider_monkey_panel/releases/tag/v1.2.2-preview
Changelog:
Spoiler (click to show/hide)
Detailed description of API changes: https://github.com/TheQwertiest/foo_spider_monkey_panel/wiki/API-Changes#v122

PS: the version is called "preview", because it was built manually on my PC (instead of appveyor CI as before). Because of Microsoft shenanigans this is the only way right now. It will be republished as a proper non-preview version once MS fixes the bug (mind you, it's already been two months since the bug was reported). It will be the same though functionality-wise (unless there are bugs discovered, of course)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #265
It seem that's just a bug in lastfm url generation.
`encodeURIComponent` seems to perform exactly as it's described in JavaScript docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

Yes, sorry my question was not clear enough. How come the double encoding works? Unlike my code, lastfm's bug generates a double encoding of only one percentage character in the URL. In other words, why does
https://www.last.fm/music/The%2520Damned/The%2520MCA%2520Singles%2520A's%2520%252B%2520B's
lead me to
https://www.last.fm/music/The%20Damned/The%20MCA%20Singles%20A's%20%252B%20B's?
It is as if all "%25" were interpreted as "%", but one.
Mind that triple encoding doesn't work.

I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #266
What method are you calling to print the text? Which font are you using?

gr.GdiDrawText. Segoe UI, and that font has the '&' character.

Here's my code for clarity:
Code: [Select]
var font = gdi.Font("Segoe UI", 12, 0);
var play_pause = fb.TitleFormat('$if(%ispaused%,❚❚,▶)');
var title = fb.TitleFormat('%title%');
var time1 = fb.TitleFormat('%playback_time%');
var time2 = fb.TitleFormat(' / %length%');


function on_playback_pause() {
    window.Repaint();
}
function on_playback_new_track() {
    window.Repaint();
}
function on_playback_seek() {
window.Repaint();
}
function on_library_items_changed() {
window.Repaint();
}
function on_playback_time() {
window.RepaintRect(213, 3, 85, 12);
}


function Color(r, g, b) {
return 0xFF000000 | r << 16 | g << 8 | b;
}
function on_paint(gr) {
    var time_width = gr.CalcTextWidth(time1.Eval() + time2.Eval(), font);
    gr.FillSolidRect(0, 0, 1000, 1000, Color(240,240,240));
    gr.GdiDrawText(play_pause.Eval() + " " + title.Eval(), font, Color(0,0,0), 5, 1, 287 - time_width, 1000);
    gr.GdiDrawText(time1.Eval() + time2.Eval(), font, Color(0,0,0), 297 - time_width, 1, 1000, 1000);
}

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #267
@spuuunit : `GdiDrawText` (which uses `::DrawText` internally) uses `&` for some formatting rules (e.g. adding underscore to the following character). In your case you can just add `DT_NOPREFIX` flag (0x00000800) to the method. For more info about flags of `GdiDrawText` see corresponding section in docs/flags.js.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #268
@spuuunit : `GdiDrawText` (which uses `::DrawText` internally) uses `&` for some formatting rules (e.g. adding underscore to the following character). In your case you can just add `DT_NOPREFIX` flag (0x00000800) to the method. For more info about flags of `GdiDrawText` see corresponding section in docs/flags.js.

Oooh, I see. That makes sense. And thanks, I added that now. :)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #269
I had a problem moving from 1.2.1 to 1.2.2 when using the updated jsplaylist-mod.

I seems like g_font_wd2 and g_font_wd3 were undefined in WSHplaylistmanager.js and WSHtopbar.js and so I had to add the following in both files (specifically, in the functions oPlaylistManager and oTopBar):

Code: [Select]
var g_font_wd2 = {
name: "Wingdings 2",
Size: 24
};

var g_font_wd3 = {
name: "Wingdings 3"
};

This fixes the problem for me.


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #271
@AndreaT , most likely you are using up all the memory =)

Quote
At least I can have it running for a while
Do you mean that the script doesn't fail immediately?

I will try to whip up a debug build that has a more detailed error message.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #272
@AndreaT , most likely you are using up all the memory =)

Quote
At least I can have it running for a while
Do you mean that the script doesn't fail immediately?

I will try to whip up a debug build that has a more detailed error message.

@TheQwertiest : Yes, exactly so, the script runs for a while, even for minutes, then it crashes randomly (but quite often when making a search or browsing/scrolling through the search's results).
Regards, Andrea

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #273
@AndreaT, does it fail always in the same place (i.e. OrderByRelativePath)? If not, does it produce the same error message ("allocation overflow") ?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #274
Hi all,

I've got an questions. I'm trying to make a theme selector that would changes the whole colour scheme of foobar.
I was wondering if it's possible to change the default colours in Columns UI, as shown in the attached picture, this ofcourse with the SpiderMonkeyPanel.

My apologies If I'm asking this question in the wrong place.