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

Remove backslash

Get help with creating, editing & fixing problems with skins
TimTim
Posts: 3
Joined: January 25th, 2017, 3:44 am

Remove backslash

Post by TimTim »

I have a string from my API for an image but I need to remove the backslashes from the url before I can download the image. Can someone please help me?

Code: Select all

https:\/\/yt3.ggpht.com\/-rJq9gk1QIis\/AAAAAAAAAAI\/AAAAAAAAAAA\/Kx4wkvKOfxY\/s88-c-k-no-mo-rj-c0xffffff\/photo.jpg
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Remove backslash

Post by jsmorley »

Need to see a bit more of the code to see how you are getting that URL.
TimTim
Posts: 3
Joined: January 25th, 2017, 3:44 am

Re: Remove backslash

Post by TimTim »

Code: Select all

[Variables]
Query=pewdiepie

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=https://localhost?query=#Query#
RegExp=(?siU)profilePicture":"(.*)".*displayname":"(.*)".*subscribers":"(.*)"
UpdateRate=600

[MeasureImage]
Measure=Plugin
Plugin=WebParser
URL=[MeasureSite]
Download=1
StringIndex=1
Download failed (res=0x800C0004, COM=0x000000000): https:\/\/yt3.ggpht.com\/-rJq9gk1QIis\/AAAAAAAAAAI\/AAAAAAAAAAA\/Kx4wkvKOfxY\/s88-c-k-no-mo-rj-c0xffffff\/photo.jpg
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Remove backslash

Post by jsmorley »

Code: Select all

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

[Variables]
Query=pewdiepie

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=https://localhost?query=#Query#
RegExp=(?siU)profilePicture":"(.*)".*displayname":"(.*)".*subscribers":"(.*)"
UpdateRate=600
FinishAction=[!CommandMeasure MeasureDownload "Update"][!UpdateMeasure MeasureDownload]

[MeasureImage]
Measure=Plugin
Plugin=WebParser
URL=[MeasureSite]
StringIndex=1
Substitute="\":""

[MeasureDownload]
Measure=Plugin
Plugin=WebParser
URL=[&MeasureImage]
Download=1
DynamicVariables=1

[MeterImage]
Meter=Image
MeasureName=MeasureDownload
So first, be sure you have DynamicWindowSize=1 in the [Rainmeter] section of the skin. If you don't, and the image is the only meter in the skin, it won't display. It comes from WebParser "after" the first update, and the skin window won't dynamically size to fit it if you don't have that setting.

Then, we are using Substitute to get rid of the backslash "\" chars from the string returned by MeasureImage. However, since the Substitute won't be applied to the Download=1 option, we need another WebParser measure that uses the string value of MeasureImage, as a section variable (preceeded by a "&" to tell WebParser that this is a section variable, and not just a normal reference to another WebParser measure).

So MeasureDownload will have the "substituted" string value of MeasureImage as its URL, and the Download=1 will work fine.
TimTim
Posts: 3
Joined: January 25th, 2017, 3:44 am

Re: Remove backslash

Post by TimTim »

That works wonders, thank you so much for your help :)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Remove backslash

Post by jsmorley »

Glad to help.