It is currently April 19th, 2024, 8:44 am

URL-ception

Get help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

URL-ception

Post by kyriakos876 »

Hello,
I have a measure that parses a link. That link has some links in it. I want to parse one link inside of that first link.
Let me demonstrate:

Code: Select all

[ParentPost]
Measure=Plugin
Plugin=WebParser
URL=#ParentURL#
RegExp=#ParentRegExp#
DynamicVariables=1

[LinkForPost1]
Measure=Plugin
Plugin=WebParser
URL=[ParentPost]
StringIndex=(3*1-1)
DynamicVariables=1

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[LinkForPost1]
RegExp="(?siU)<p>(.*)</p>.*"
DynamicVariables=1
Now for some reason, when I run this the last measure returns nothing. But if I put the link that came from [LinkForPost1] manually as the URL for [ToolTipForPost1] it works fine. I tried something with the updaterate and the OnFinish action on the [LinkForPost1] measure as I thought it could be because the first update grabs the link, so the last measure would be empty until the next update, but none of those work.
Any idea of what I am doing wrong?

-Thanks in advance.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: URL-ception

Post by jsmorley »

It's really hard when we don't have the parent URL and the RegExp, so we have some hope of testing...

However, I would be tempted to try:

Code: Select all

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[&LinkForPost1]
RegExp="(?siU)<p>(.*)</p>.*"
DynamicVariables=1
You can't directly use the value of a "child" measure in a URL of another measure. What you would have to do is use the value of the child measure as a dynamic [&SectionVariable] in the URL.

https://docs.rainmeter.net/manual/measures/webparser/#URL
If you want to use the current value of a measure in a dynamic way as a Section Variable, rather than as a reference to a "parent" WebParser measure, you must prefix the name of the measure with the & character.

URL=http://SomeSite.com\[&WebMeasure]
The construct URL=[LinkForPost1] is attempting to act as a "child" measure for the "parent" [LinkForPost1], which 1) Isn't a parent measure, and 2) if it was, you would need a StringIndex on the child.

You might want a FinishAction on the parent to force an Update to [ToolTipForPost1], but I'm not sure. Can't test...
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: URL-ception

Post by kyriakos876 »

jsmorley wrote: October 23rd, 2018, 11:45 pm It's really hard when we don't have the parent URL and the RegExp, so we have some hope of testing...

However, I would be tempted to try:

Code: Select all

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[&LinkForPost1]
RegExp="(?siU)<p>(.*)</p>.*"
DynamicVariables=1
You can't directly use the value of a "child" measure in a URL of another measure. What you would have to do is use the value of the child measure as a dynamic [&SectionVariable] in the URL.

https://docs.rainmeter.net/manual/measures/webparser/#URL



The construct URL=[LinkForPost1] is attempting to act as a "child" measure for the "parent" [LinkForPost1], which 1) Isn't a parent measure, and 2) if it was, you would need a StringIndex on the child.

You might want a FinishAction on the parent to force an Update to [ToolTipForPost1], but I'm not sure. Can't test...
Ok, I made it work with an addition to your code:

Code: Select all

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[&LinkForPost1]
RegExp="(?siU)<p>(.*)</p>.*"
StringIndex=1
DynamicVariables=1
added StringIndex as you told in "2)" because if you think about it, it's a child of [LinkForPost1]

Two more things.
  • 1) I read the manual you linked but I still don't get what is & doing....
    2)In the returned string I get a <br /> in the end of the first line, which I suppose stands for break, as the string continues on the next line.
I can sure use Substitute="<br />":"" but what if there's <br /> in the actual string? I doubt it but just in-case and out of curiosity, is there another way?

(BTW I didn't post the link of the regular expressions because the context is in Greek and you wouldn't understand where the link should come from and what to show.)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: URL-ception

Post by jsmorley »

No, [LinkForPost1] is not a "parent" measure, and [ToolTipForPost1] can't be a "child" of it. [LinkForPost1] is a "child" of [ParentPost].

A parent measure will always have a RegExp that (captures) one or more bits of data.

When you use a URL=[SomeMeasure] in WebParser, that is specifically saying to use [SomeMeasure] as the "parent" for this measure, and then you use StringIndex to tell the child which bit of data from the one or more (captures) you have in the RegExp in the parent.

What you are trying to do is to use the data returned by a child measure, [linkForPost1] as the URL in a brand-new "parent" measure. The only way to do that is to use it as a section variable, and with WebParser, that is done by prefixing the name of the measure with &. It is the same as the the "nested" variant of a measure section variable.

Now in this case, just to make things a little cloudy for you, we can have [ToolTipForPost1] be both a "parent", in that it has a URL and a RegExp that (captures) data, AND a "child", in that it has a StringIndex. In that sense, it is a child of itself.

That way, since it only returns one (capture), we can just use it in the meter to display the value.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
ParentURL=file://C:\Users\Jeffrey\Documents\Rainmeter\Skins\@Working\Test1.html
ParentRegExp=(?siU)<item>(.*)</item>

[ParentPost]
Measure=Plugin
Plugin=WebParser
URL=#ParentURL#
RegExp=#ParentRegExp#
DynamicVariables=1

[LinkForPost1]
Measure=Plugin
Plugin=WebParser
URL=[ParentPost]
StringIndex=1
DynamicVariables=1

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[&LinkForPost1]
RegExp=(?siU)<p>(.*)</p>.*
StringIndex=1
DynamicVariables=1

[MeterOne]
Meter=String
MeasureName=ToolTipForPost1
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test1.html:

Code: Select all

<item>file://C:\Users\Jeffrey\Documents\Rainmeter\Skins\@Working\Test2.html</item>
Test2.html:

Code: Select all

<p>This is a tooltip</p>
1.png

P.S. You won't find <br /> in any actual string value, as if you think about it, that can't be displayed as a literal in HTML, it will always be converted to a line break when rendered. If someone wanted some text that contained that HTML tag as literal text, followed by an actual line break, as in

You do a line break in HTML with the <br /> tag

You might see:

You do a line break in HTML with the &lt;br /&gt; tag<br />

With the characters that would normally confuse HTML encoded as Character References. There are other ways using CDATA and such, but they are less common.
You do not have the required permissions to view the files attached to this post.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: URL-ception

Post by kyriakos876 »

Alright, I have no more questions now. Thanks for the thorough answer!
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: URL-ception

Post by jsmorley »

I would note that a simple line break in HTML is one of the least standard tags out there. When parsing sites, you will see it as:

<br>
<br/>
<br />

All of which work fine. If you are creating, I think the safest is <br /> which is the standard for XHTML, the XML compliant form of HTML, but that kind of stuff is exactly what flame-wars start with.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: URL-ception

Post by kyriakos876 »

jsmorley wrote: October 25th, 2018, 1:43 pm I would note that a simple line break in HTML is one of the least standard tags out there. When parsing sites, you will see it as:

<br>
<br/>
<br />

All of which work fine. If you are creating, I think the safest is <br /> which is the standard for XHTML, the XML compliant form of HTML, but that kind of stuff is exactly what flame-wars start with.
Yea, whoever decided it's a good idea to have 3 different ways for that is evil :twisted:
So I suppose I should substitute all 3 of those to return null then...
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: URL-ception

Post by kyriakos876 »

Hey, so, I realized that inside of the URL that is inside of a URL, it could be text alone or text with another URL....
Now, if the end result is a text only, I want to display the text. If it is a text with a URL embedded I would like to display a text that when clicked, opens the URL.
I will make an example as I think nobody will understand without one, so here goes:

We have
ParentExample.com
You click that and you get

Announcement1.com
Announcement2.com
Announcement3.com

now when you click, say, Announcement1.com you get
We inform you that the program has been update
and you can click that to download the program.

There's also a chance that this is a simple announcement as:
We inform you that tomorrow's meeting has been canceled.
and you can't click that.

So I have one measure that goes like:

Code: Select all

[ToolTipForPost1]
Measure=Plugin
Plugin=WebParser
URL=[&LinkForPost1]
RegExp=(?siU)<p><a itemprop="url" href="(.*)".*>(.*)</a></p>.*
StringIndex=2
Substitute="<br />":"","<br/>":"","<br>":""
DynamicVariables=1
DecodeCharacterReference=1
where StringIndex=1 will return the link (if the text is clickable) and StringIndex=2 will return the text.
I want to display the text, and if it's clickable I want it to do according to the link.

How can I do that last part?
-Thanks in advance.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: URL-ception

Post by kyriakos876 »

Nevermind, I solved it after some intense code-staring.