It is currently April 28th, 2024, 7:50 am

Substitute returned string before downloading image

Get help with creating, editing & fixing problems with skins
Hexagons
Posts: 4
Joined: February 7th, 2012, 8:38 am
Location: Sweden

Substitute returned string before downloading image

Post by Hexagons »

So I'm working with some quite irregular expressions in a feed.
If the feed doesn't return an url with an image, I want it to substitute that string (they are regular expressions) with a static image from another site.
The problem I've got at the moment, is that the substitution doesn't happen until after [MeasureImageDownload] tries to download the image from the site "self", which won't work for obvious reasons.

So in short, I want [MeasureImageDownload] to download "www.somesite.com/someimage.png" if the regular expression returns "self" instead of an url.
What am I doing wrong here?

Code: Select all

[MeasureImageLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=....
RegExp=....
StringIndex=1

[MeasureImageDownload]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureImageLink]
StringIndex=2
Substitute="self":"www.somesite.com/someimage.png"
Download=1
Thank you for your time.
User avatar
Brian
Developer
Posts: 2688
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Substitute returned string before downloading image

Post by Brian »

I believe this is a Dynamic Variable issue.

Dynamic Variables are not supported by the WebParser.dll at this time, but possibly in the near future.

Check this out. Now, I know this is for the calc measure, but I believe the same logic is valid for WebParser as well. It basically says that to get the substituted values, you have to "call" the measure with brackets around it, making it a Dynamic Variable - and since WebParser doesn't support Dynamic Variables, this might not be possible at this time.

Maybe someone else can shed some more light on this?

-Brian
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Substitute returned string before downloading image

Post by smurfier »

I believe that substitute does nothing for the actual url of a webparser measure as the substitute happens on the Rainmeter side of the fence and not on the Webparser side. Another words, Webparser has no idea that the substitute is even happening.

For what you desire I believe you will need to wait for Dynamic Variables to be implemented in WebParser. At that point it should be rather easy to do what you ask.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Substitute returned string before downloading image

Post by Mordasius »

If you can't wait forDynamicVariables in Webparser, you could try putting a Substitute= in [MeasureImageLink] and then use a Calc Measure to Enable or Disable Webparser Measures that either download the 'captured' image or use a substitute image:

Code: Select all

[Rainmeter]
DynamicWindowSize=1

[MeasureImageLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://rainmeter.deviantart.com/
RegExp=(?siU)<title>#(.*)</title>.*<p>The winner of Skin of the Month.*data-src="(.*)"></a></span>
StringIndex=1
Substitute="Rainmeter on deviantART":"1"
UpdateRate=3600

[CalcCheckForImage]
Measure=Calc
Formula=[MeasureImageLink]
IfEqualValue=1
IfEqualAction=!Execute [!ShowMeterGroup Substitutes] [!EnableMeasure MeasureSubstituteImage] [!HideMeterGroup GotAnImage] [!DisableMeasure MeasureImageDownload]
IfBelowValue=1
IfBelowAction=!Execute [!ShowMeterGroup GotAnImage] [!EnableMeasure MeasureImageDownload]
DynamicVariables=1

[MeterSearching]
Meter=String
FontColor=ffffff
FontSize=10
Text="Searching.."
Hidden=1
Group=GotAnImage

;------- These if an image is found
[MeasureImageDownload]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureImageLink]
StringIndex=2
Download=1
Disabled=1

[MeterShowImage]
Meter=Image
ImageName=[MeasureImageDownload]
DynamicVariables=1
Hidden=1
Group=GotAnImage

;------- These for the substitute image
[MeterSubstituted]
Meter=String
FontColor=ffffff
FontSize=10
Text="Substitute Image"
Hidden=1
Group=Substitutes

[MeasureSubstituteImage]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://a.deviantart.net/avatars/r/a/rainmeter.png?15
Download=1
Disabled=1

[MeterShowSubstituteImage]
Meter=Image
ImageName=[MeasureSubstituteImage]
Y=20
DynamicVariables=1
Hidden=1
Group=Substitutes
You can test this by changing StringIndex=1 to StringIndex=2 in [MeasureImageLink]. Only problem is that [CalcCheckForImage] causes an "unknown function/variable" error if [MeasureImageLink] returns a link rather than the substituted number.
Hexagons
Posts: 4
Joined: February 7th, 2012, 8:38 am
Location: Sweden

Re: Substitute returned string before downloading image

Post by Hexagons »

Thank you for your answers.

I will try what you're suggesting Mordasius. I really appreciate it.
If it doesn't work, I could probably live with the matching error a little while longer.

Thanks again.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Substitute returned string before downloading image

Post by smurfier »

Here's one idea for you. The Lua measure should return the correct path to the image you want.

Skin.ini

Code: Select all

[MeasureImageLink]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=....
RegExp=....
StringIndex=1

[MeasureImageDownload]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureImageLink]
StringIndex=2
Download=1

[MeasureSelf]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=www.somesite.com/someimage.png
Download=1

[Lua]
Measure=Script
ScriptFile=Lua.lua
Lua.lua

Code: Select all

PROPERTIES={}

function Initialize()
	Measures={SKIN:GetMeasure('MeasureImageDownload');SKIN:GetMeasure('MeasureSelf')}
end

function Update()
	Var=Measures[1]:GetStringValue()
	return	Var=='' and Measures[2]:GetStringValue() or Var
end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Substitute returned string before downloading image

Post by Mordasius »

smurfier wrote:

Code: Select all

PROPERTIES={}
function Initialize()
	Measures={SKIN:GetMeasure('MeasureImageDownload');SKIN:GetMeasure('MeasureSelf')}
end

function Update()
	Var=Measures[1]:GetStringValue()
	return	Var=='self' and Measures[2]:GetStringValue() or Var
end
Very elegant and so simple once someone shows you how to do it. I had to get the LUA manual out to work out how that X and Y or Z bit worked with non-boolean values. Having done that, it seems to me that Var=='self' might always be False since [MeasureImageDownload] with Download=1 will return an empty string when passed a non-downloadable URL (e.g. 'self'). Would I be right in thinking that if update is modified to

Code: Select all

function Update()
   Var=Measures[1]:GetStringValue()
 return   Var=='' and Measures[2]:GetStringValue() or Var
end
the script will return the path to a 'substitute' image whenever the URL in [MeasureImageDownload] is set to anything which causes download to fail?
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Substitute returned string before downloading image

Post by smurfier »

I believe you are right and have changed my above post to reflect that.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .