Skip to main content

Topic: WSH Panel Mod script discussion/help (Read 834654 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • trout
  • [*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1750

marc2003 - Thanks for your gracious help. Much appreciated!




  • onv
  • [*][*]
WSH Panel Mod script discussion/help
Reply #1751
@Falstaff

http://www.youtube.com/watch?v=zq8IpyuZZxI&feature=plcp

left button down + move, without scrollbar, for CarPC & other touchscreen's
  • Last Edit: 22 June, 2012, 05:17:15 PM by onv

  • mjm716
  • [*][*][*]
WSH Panel Mod script discussion/help
Reply #1752
Hi Falstaff,

Any chance you can give some help trying to get your WSH playlist script to support 1/2 ratings, similar to $repeat(★,$meta(rating))$if($strchr($meta(rating),.),☆)?


  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1753
I have a WSH script which reads and displays a textfile, here is the header description inside the script:
// Draws "<dir_containing_current_audio_file>\folder.txt" in a "WSH Panel Mod" panel,
// or if "folder.txt" is not present, will draw the first text file in that directory,
// or if no text file exists, will draw some default ASCII Art text.



I always use the following template to format the textfile (folder.txt) the same way:
Quote
Artist – Album (Date)

<PRODUCT>A line of text is inserted here</PRODUCT/>

<GENRE>A line of text is inserted here</GENRE/>

<OVERVIEW>Multiple lines of text are inserted here
giving informative comments and reviews on the work</OVERVIEW/>

<TRACKS>01. Trackname
02. Trackname
03. Trackname
etc
etc</TRACKS/>

<CREDITS>JOHN SURNAME — guitar
PAUL SURNAME — vocals
GEORGE SURNAME — bass
RINGO SURNAME — drums</CREDITS/>



My script is NEARLY perfect but for one last problem. . .
I want the script to replace the "special words enclosed in angle brackets" with nothing.
That is, I would like the panel to end up displaying like this in foobar2000:
Quote
Artist – Album (Date)

A line of text is inserted here

A line of text is inserted here

Multiple lines of text are inserted here
giving informative comments and reviews on the work

01. Trackname
02. Trackname
03. Trackname
etc
etc

JOHN SURNAME — vocals, guitar
PAUL SURNAME — vocals, bass
GEORGE SURNAME — guitar
RINGO SURNAME — drums


I am pretty sure the search-and-replace method needs to be inserted into the function on_paint(gr) section.
I'm not a javascript programmer and I need some help to realize this.
Some help from one of you javascript gurus would be highly appreciated.

P.S. -- I plan on sharing the script here with everyone once it is fully completed and tested.

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1754
add this to your script (safe mode needs to be disabled) -

Code: [Select]
var doc = new ActiveXObject("htmlfile");

function decode(value) {
    try {
        doc.open();
        div = doc.createElement("div");
        div.innerHTML = value.replace(/\n/g, "<br>");
        return div.innerText;
    } catch(e) {
        return "Error reading content.";
    }
}


then assuming the variable mytext contains your text....

Code: [Select]
mytext = decode(mytext);


note: you don't need to add the first code section if you're importing common4.js from my scripts.





  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1755
Thanks for that reply marc, nice stuff to know. This script is not one of yours.

____________________________________________________________________________________

Anyhow, I just finished composing a reply to my Post #1754. . .so I might as well post it:

I solved it!. . .with a bit of luck and a bit of WWW Google searching with these two terms: (1) jscript replace text, (2) regex escape forward slash.

The relevant function in my script for performing this task is at on_playback_new_track() AND NOT on_paint(gr).

So, looking at an excerpt of the function, we see the code I needed to add (in red):
Quote
function on_playback_new_track(){
   
    g_need_vp_refresh = true;
    g_metadb = get_metadb();

    if (! g_metadb) window.Repaint();
   
    var new_dir = fb.TitleFormat("$directory_path(%path%)").EvalWithMetadb(g_metadb);
    if (g_dir == new_dir) return;

    var new_title = "";
    var new_text = "";
    var filename = new_dir + "\\folder.txt";
    var filename_contents = utils.ReadTextFile(filename);
   
    if (new_text == "") {
        var arr = utils.Glob(fb.TitleFormat("$directory_path(%path%)").EvalWithMetadb(g_metadb) + "\\*.txt").toArray();
        if (arr.length > 0) {
            filename = arr[0];
            try {
                these_strings = /<(PRODUCT|\/PRODUCT\/|GENRE|\/GENRE\/|OVERVIEW|\/OVERVIEW\/|TRACKS|\/TRACKS\/|CREDITS|\/CREDITS\/)>/g;
                new_text = filename_contents.replace(these_strings,"");
            } catch(e) {
                new_text = "";
            }
        }
        window.Repaint();
    }

    ...



When I'm finished with it all, I'll share this textfile viewer with everybody.

I have tested just about every textfile viewer script made for WSH Panel Mod
and this one here is UNBELIEVABLE. It is hands down the best I ever found (and modified:-).

Some of its features:
- Looks for your preferred text file name first, else looks for any text file, else displays contents of a default text file (ASCII Art ...see screenshots)
- Pop-out vertical scrollbar on mouse hover
- Up-Down page scroll with left mouse button drag anywhere on the window
- Up-Down page scroll with keyboard arrows/PgDn/PgUp
- Top-Bottom-Top-Bottom infinite chunk scroll with middle mouse clicks
- flat color or gradient color change views
- A thin header bar showing the name of the displayed text file.
- Right click menu: Open folder | Edit text file | Refresh | Configure

Screenshots of the WSH textfile viewer in my foobar2000...(Top shot is reading a text file, Bottom shot is reading "default.txt" aka no text file found):
  • Last Edit: 09 July, 2012, 03:11:10 PM by derty2

  • rawny
  • [*]
WSH Panel Mod script discussion/help
Reply #1756
@derty2:

You could simplify your regular expression somewhat based on the fact that the / is repeated:
Code: [Select]
these_strings = /<\/?(PRODUCT|GENRE|OVERVIEW|TRACKS|CREDITS)\/?>/g;
? means 0 or 1 occurrences of the character before it, in this case the /

However, it's possible that this might not work unless you group the escaping \ with the / using brackets, as follows:
Code: [Select]
these_strings = /<(\/)?(PRODUCT|GENRE|OVERVIEW|TRACKS|CREDITS)(\/)?>/g;

Try it without the grouping first.

Also, is there any reason why your closing tags have / at both ends, i.e.
Code: [Select]
</GENRE/>
as opposed to
Code: [Select]
</GENRE>
which is the format of closing tags in most mark-up languages such as HTML and XML?

  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1757
Thanks for the tips rawny.

The exact same contents of the text file also gets pasted into the %comment% tag field of the audio files.
I use those <special strings with angled brackets> as delimiters to retrieve string sections from the %comment% tag using foobar2000 title-formatting syntax.

I DO NOT use any other audio tags except these:
ARTIST | TRACKTITLE | ALBUM | DATE | GENRE | ALBUM ARTIST | TRACKNUMBER | DISCNUMBER | COMMENT

Therefore, I use the %comment% tag as an extra database containing custom "pseudo-tags" and "values".
The %comment% tag is a standard tag, and can be read by ANY music player.
I can create custom Playlists, Autoplaylists and Library Searches using fb2k title-formatting and selective searching inside the %comment% tag.

Given the %comment% tag and my text file (folder.txt) are the exact mirror of each other, I can extend my user-interface experience into another dimension;
If I accidentally lose the audio tags, the text file is my backup.
If I accidentally lose folder and file names, the text file contents can be read by command-line tools such as FINDSTR.
In a sense, I'm not just playing audio tracks in a music player but cultivating and indexing an audio collection like a professional librarian (from the old days...
...does anybody here remember the index cards in libraries ???)

I use forward slash at both ends of my closing tags because --after much trial and error-- I found retrieval of delimited string sections from the %comment% tag
using fb2k title-formatting syntax gave me more reliable output.

The standard syntax I use in fb2k to retrieve a delimited section of the %comment% tag looks like this example:
$if($strstr(%comment%,<PRODUCT>),$substr(%comment%,$add($strstr(%comment%,<PRODUCT>),$len(<PRODUCT>)),$sub($strstr(%comment%,</PRODUCT/>),1)),)
  • Last Edit: 09 July, 2012, 05:14:38 PM by derty2

  • godrick
  • [*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1758
@marc2003, I'm chasing some weird problems on my computer and setup (I have a biography component script that seems identical but behaving differently than others), so with the caveat that I don't know if the following is a result of, cause of, or unrelated to the weirdness:

When using your lastfm - similar artists - top tags - top fans - top albums - top tracks script (which I downloaded per your post #1741), every time I hit "update" in the WSH panel I get the following in the console:

Code: [Select]
Last.fm: 
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>503 Service Unavailable</title>
  </head>
  <body>
    <h1>Error 503 Service Unavailable</h1>
    <p>Service Unavailable</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 564881961</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>


and sometimes I also get in the console:

Last.fm: HTTP error: 12152

I've removed all other scripts and settings related to last.fm other than this script and my last.fm username and API key.  When I remove this script I never get these console errors.  As far as the display of the WSH panel itself, the panel never crashes and frequently correctly shows the correct data.  Sometimes it fails to find similar artists for artists I know last.fm has knowledge of and has previously displayed similar artist info.

Are you seeing this or have you seen this before?  Any suggestions?  Does it really mean anything?  Thanks for any suggestions.
  • Last Edit: 10 July, 2012, 06:06:38 PM by godrick

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1759
Quote
Error 503 Service Unavailable


that one couldn't be more straightforward. it's a problem at last.fm's end and you'll just have to wait for them to fix it. you can check this page....

http://status.last.fm/

Web services is what you need to be looking at. at the time of me posting:



Quote
Last.fm: HTTP error: 12152


this one usually indicates local connectivity problems. i know i've seen it when i have no internet connection. but if your connection is fine, then it could well be linked to the above. you'll just have to wait it out.
  • Last Edit: 11 July, 2012, 08:39:40 AM by marc2003

  • godrick
  • [*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1760
Wow - you're right, of course.  I guess I win today's genius award for not even considering the possibility of taking the error message literally.  Thanks!

  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1761
I would like one more bit of help with my 'WSH Textfile Viewer' panel (see Posts: #1754, #1756, #1757, #1758).

I need a Regular Expression pattern to do this:

      If the text file has a line like this:

            <IDX>B-52's, the</IDX/>The B-52's – Wild Planet (1980)

      Then the WSH textfile viewer panel displays like this:

            The B-52's – Wild Planet (1980)

In other words, using regular expression syntax, how do I remove the "<TAGS>" and the string between them ???

In my previous posts, I solved how to remove the "<TAGS>", but this case is trickier.

If any RegEx gurus are reading this, can you show me the regex pattern which solves such a case ?
I have spent hours and hours trying to solve it but I can't !!
Thanks for your help.


  • fbuser
  • [*][*][*][*][*]
  • Developer
WSH Panel Mod script discussion/help
Reply #1762
Try something like this (won't work, if the string after </IDX/> contains a ">"):
Code: [Select]
"<IDX>B-52's, the</IDX/>The B-52's – Wild Planet (1980)".replace(/(<.+>)(.+)/,"$2")
  • Last Edit: 15 July, 2012, 11:45:39 AM by fbuser

  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1763
Thanks for the reply fbuser +++, I will keep your answer for future reference.

I eventually solved it, and the RegEx pattern to do this is quite simple looking: (LEFT_DELIMITER).*(RIGHT_DELIMITER)

What solved it for me was WWW Google searching with this term:  regex remove string between delimiters
which led me to a solution at this webpage:  stackoverflow.com

So, looking at an excerpt of the relevant function in my 'WSH Textfile Viewer' script, we see the code I need (in red):
Quote
function on_playback_new_track(){

    g_need_vp_refresh = true;
    g_metadb = get_metadb();

    if (! g_metadb) window.Repaint();

    var new_dir = fb.TitleFormat("$directory_path(%path%)").EvalWithMetadb(g_metadb);
    if (g_dir == new_dir) return;

    var new_title = "";
    var new_text = "";
    var filename = new_dir + "\\folder.txt";
    var filename_contents = utils.ReadTextFile(filename);

    if (new_text == "") {
        var arr = utils.Glob(fb.TitleFormat("$directory_path(%path%)").EvalWithMetadb(g_metadb) + "\\*.txt").toArray();
        if (arr.length > 0) {
            filename = arr[0];
            try {
                these_strings = /(<IDX>).*(<\/IDX\/>)|<PRODUCT>|<\/PRODUCT\/>|<GENRE>|<\/GENRE\/>|<OVERVIEW>|<\/OVERVIEW\/>|<TRACKS>|<\/TRACKS\/>|<CREDITS>|<\/CREDITS\/>/g;
                new_text = filename_contents.replace(these_strings,"");
            } catch(e) {
                new_text = "";
            }
        }
        window.Repaint();
    }

    ...


Before any RegEx gurus comment. . .
Yes, the RegEx pattern for  these_strings = ...;  can be optimized and reduced, but I prefer it like this; a list of definite items.

The main reason I couldn't solve it is because I wasn't using parenthesis correctly while forming my RegEx pattern.

Cheers.
  • Last Edit: 15 July, 2012, 01:21:53 PM by derty2

  • rawny
  • [*]
WSH Panel Mod script discussion/help
Reply #1764
Before any RegEx gurus comment...

Yes, the RegEx pattern for  these_strings = ...;  can be optimized and reduced, but I prefer it like this; a list of definite items.

You called? 

Your current expression won't match things like:
Code: [Select]
<PRODUCT>...</PRODUCT/>
It'll only match lines starting with <IDX>, e.g.:
Code: [Select]
<IDX>...</PRODUCT/>


This may be more useful:
Code: [Select]
these_strings = /(<IDX>|<PRODUCT>|<GENRE>|<OVERVIEW>|<TRACKS>|<CREDITS>).*(<\/IDX\/>|<\/PRODUCT\/>|<\/GENRE\/>|<\/OVERVIEW\/>|<\/TRACKS\/>|<\/CREDITS\/>)/g;


Somewhat simplified:
Code: [Select]
these_strings = /<(IDX|PRODUCT|GENRE|OVERVIEW|TRACKS|CREDITS)>.*<\/(IDX|PRODUCT|GENRE|OVERVIEW|TRACKS|CREDITS)\/>/g;


However you'll notice that the list of possible values is repeated unnecessarily. To eliminate this - and the potential nuisance of editing both lists if you ever decide to add/remove a tag - you can use a backreference, like this:
Code: [Select]
these_strings = /<(IDX|PRODUCT|GENRE|OVERVIEW|TRACKS|CREDITS)>.*<\/\1\/>/g;

So the \1 is replaced by whatever the first set of brackets in your expression matched ("PRODUCT", "GENRE", "OVERVIEW" etc.). For a better explanation of brackets and backreferencing, check this out: http://www.regular-expressions.info/brackets.html


Alternatively - although perhaps less to your liking as it doesn't involve any kind of definitive list - you could do something along the lines of what fbuser was suggesting and match any set of tags:
Code: [Select]
these_strings = /<(.+)>.*<\/\1\/>/g;
  • Last Edit: 15 July, 2012, 11:41:39 PM by rawny

  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1765
Thanks a lot for passing on your RegEx knowledge rawny +++++++ Highly informative.

In my case, the only <TAG>string</TAG/> I want fully removed from display is <IDX>string</IDX/> .
For all the other <TAG>string</TAG/> items, I remove the tags but allow the string to be displayed .

I don't have any problems with my "defined items list" RegEx pattern; everything works for me as expected. . .HOWEVER, there is a limitation which I am trying to solve
and if you would like to apply your RegEx skills to this it would help solve the final missing piece of the puzzle.

So far, the RegEx pattern I have will only work on single lines in the text file; it fails when operating over multiple lines.
I am in the process of creating another "fully removed" string section delimited by tags named <CUT> and </CUT/>, look at this example. . .

If we have these lines in the text file:
Quote
The Stone Roses were an English rock band formed in Manchester in 1983.
The band were part of<CUT> the declining punk-rock era, but changed their style
over time to alternative/indie rock. They were one of the pioneering groups of
</CUT/> the Madchester movement that was active during the late 1980s and
early 1990s.

Then the WSH Textfile Viewer panel should display this:
Quote
The Stone Roses were an English rock band formed in Manchester in 1983.
The band were part of the Madchester movement that was active during the late 1980s and
early 1990s.


BUT. . .as I stated before, the current RegEx pattern has limitations and cannot operate over multiple lines.
Any suggestions on solving this ?

*** EDIT ***

I found a solution. . .at this webpage:  delphifaq.com

This RegEx pattern works correctly:  (<CUT>)(\n|.)*(<\/CUT\/>)

However, if I add a second pair of CUT tags further down the text file then I remove ALL text from the first/highest <CUT> to the last/lowest </CUT/> . . .which is wrong !
  • Last Edit: 16 July, 2012, 07:39:02 AM by derty2

  • derty2
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1766
(continuation of Post #1766)

I solved my problem !!!

This Regular Expression pattern:   (START_DELIMITER)(\n|.)*?(END_DELIMITER)   will match multiple occurrences of the expression as separate instances.

Therefore, in the case of my 'WSH Textfile Viewer' panel and the multiple occurrences of <CUT>string</CUT/> in my text file,
I offer proof-of-concept results from a test run in my foobar2000. . .

Text file contains this text:
Quote
The Stone Roses were an English rock band formed in Manchester in 1983.
The band were part of<CUT> the declining punk-rock era, but changed their style
over time to alternative/indie rock. They were one of the pioneering groups of
</CUT/> the Madchester movement that was active during the late 1980s and
early 1990s.

They would often display no interest in<CUT> promoting themselves, and many journalists
were confused, and sometimes angered, when their questions were met with complete silence
from the four Stone</CUT/> Roses.


'WSH Textfile Viewer' displays this text:
Quote
The Stone Roses were an English rock band formed in Manchester in 1983.
The band were part of the Madchester movement that was active during the late 1980s and
early 1990s.

They would often display no interest in Roses.


Well. . .that is that; I have all the RegEx I need to control display output in the 'WSH Textfile Viewer' panel .

I hope this was interesting to some of you here, and I will share the 'WSH Textfile Viewer' script and support files with all of you . . .one day soon .

Goodbye and thanks for all the help .
  • Last Edit: 16 July, 2012, 02:45:33 PM by derty2

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1767
samples updated: http://dl.dropbox.com/u/22801321/samples.zip

last.fm charts: you can now access 1 month charts. (this is a recent addition to the last.fm api)

  • r3v0
  • [*][*][*]
WSH Panel Mod script discussion/help
Reply #1768
Hi,

I'm currently refining an Album Cover panel which I started years ago.
And after learning so much from this thread and their regular posters,
I'm trying to clean up the mess I made in that code.

Anyway I wanted to share some pics:







I love album art so I created toggles for showing original art or the remastered version.
Further there are toggles for Gloss, Reflection, Label Icons, Progressbar & text alignment.
Also in the edit mode You can drag the different components (art, text, icon) to your favorite position.
In properties you can change that also and some additional settings.

It's still under construction though.
<3 f00

  • macarych
  • [*]
WSH Panel Mod script discussion/help
Reply #1769
Hi, I'm currently refining an Album Cover panel which I started years ago. .................It's still under construction though.

Very nice ! Do you think to share it ?

  • r3v0
  • [*][*][*]
WSH Panel Mod script discussion/help
Reply #1770
Hi, I'm currently refining an Album Cover panel which I started years ago. .................It's still under construction though.

Very nice ! Do you think to share it ?


When I finish it, maybe.
<3 f00

  • trout
  • [*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1771
I have a script for a "Stop After Current" button. I've used gr.DrawLine() to draw an "X" , with the color depending on whether SAC is active. The problem is it does not display correctly when foobar2000 is started. It only draws a small portion of the line drawn top-left to bottom-right, and none of the second line. But - if I bring up the WSH panel config and just click on [Apply] or [OK], then it displays fully as expected.

Here is just the the meat of the script; enough to demonstrate the issue:
Code: [Select]
var ww = window.Width;
var wh = window.Height;
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

function on_paint(gr) {
    gr.DrawLine(3, 3, ww-4, wh-4, 2, fb.StopAfterCurrent ? RGB(128,128,128) : RGB(188,188,188));
    gr.DrawLine(3, wh-4, ww-4, 3, 2, fb.StopAfterCurrent ? RGB(128,128,128) : RGB(188,188,188)); }
function on_mouse_lbtn_up() {
    fb.RunMainMenuCommand("Playback/Stop After Current");
    window.Repaint(); }
function on_playlist_stop_after_current_changed() {
    window.Repaint(); }

I'm using the most recent WSH Panel Mod (v1.5.3.1) (Inside a Panel Stack Splitter in Columns UI. But I checked it in a Default UI config and the problem was still present). Much appreciation for any feedback on whether it's something I've done wrong (other than drawing an X with lines instead of just using text...), or what the problem is, and how it can be solved.

  • rawny
  • [*]
WSH Panel Mod script discussion/help
Reply #1772
@trout:

You need to stick an on_size() function in there to make sure the graphical stuff is (re-)drawn relative to the panel's final size once it has finished whatever sizing calculations it's doing during foobar start-up.

Try replacing the lines defining ww and wh at the top of your code with:
Code: [Select]
var ww;
var wh;
    
function on_size() {
    ww = window.Width;
    wh = window.Height;
    window.Repaint();
}

Hope that helps
  • Last Edit: 30 July, 2012, 10:08:42 PM by rawny

  • trout
  • [*][*][*][*]
WSH Panel Mod script discussion/help
Reply #1773
rawny,

That's very helpful, thanks!


WSH Panel Mod script discussion/help
Reply #1774
Code: [Select]
var ww;
var wh;
    
function on_size() {
    ww = window.Width;
    wh = window.Height;
}


is enough. It's not recommended calling window.Repaint() in on_size() function; might trigger some problems.

see Notes&hints.txt in wsh panel mod package.

Quote
3. Don't call repaint functions such as window.Repaint() in callback function on_size() {}, especially in pseudo transparent mode.
mad messy misanthropist morbid mused