It is currently April 19th, 2024, 12:47 am

Why WebParser Download Stops Working?

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Why WebParser Download Stops Working?

Post by balala »

jsmorley wrote: December 15th, 2018, 6:49 pm I think in any case the browser-check is passed, but there is then a re-direct to the actual image. WebParser just can't deal with a re-direct like that, where the Powershell function seems to be able to.
Ok, thanks.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Why WebParser Download Stops Working?

Post by jsmorley »

I think the key to that may be the C#-based System.Net.WebClient, which is likely a slightly more robust animal than the C++ WinINet API calls used in WebParser.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Why WebParser Download Stops Working?

Post by balala »

jsmorley wrote: December 15th, 2018, 8:02 pm I think the key to that may be the C#-based System.Net.WebClient, which is likely a slightly more robust animal than the C++ WinINet API calls used in WebParser.
:confused: No comment for my part. Have no idea... :confused:
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Why WebParser Download Stops Working?

Post by jsmorley »

Skin just a bit shorter, and a test in the Powershell to avoid an unwanted log message.

GetMoon.ini

Code: Select all

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

[Variables]
URL=https://static.die.net/moon/800.jpg

[MeasureGetMoon]
Measure=Plugin
Plugin=RunCommand
OutputType=ANSI
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\GetMoon.ps1' '#URL#' '.\Moon.jpg'"
UpdateDivider=600
OnUpdateAction=[!CommandMeasure #CURRENTSECTION# "Run"]
FinishAction=[!SetOption MeterShowMoon ImageName "Moon.jpg"][!UpdateMeter MeterShowMoon][!Redraw]

[MeterContainer]
Meter=Shape
Shape=Ellipse 100,100,96 | StrokeWidth 0

[MeterShowMoon]
Meter=Image
Path=#CURRENTPATH#
W=200
PreserveAspectRatio=1
Container=MeterContainer
GetMoon.ps1:

Code: Select all

$url = $args[0]
$file = $args[1]

if (Test-Path $file) 
{
  Remove-Item $file
}

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $file)

1.png

GetImage_3.0.rmskin


No need for the separate Calc measure to execute the RunCommand. That measure can execute itself based on UpdateDivider.
You do not have the required permissions to view the files attached to this post.
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: Why WebParser Download Stops Working?

Post by GTI.H »

jsmorley wrote: December 16th, 2018, 12:59 am Skin just a bit shorter, and a test in the Powershell to avoid an unwanted log message.

GetMoon.ini

Code: Select all

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

[Variables]
URL=https://static.die.net/moon/800.jpg

[MeasureGetMoon]
Measure=Plugin
Plugin=RunCommand
OutputType=ANSI
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '.\GetMoon.ps1' '#URL#' '.\Moon.jpg'"
UpdateDivider=600
OnUpdateAction=[!CommandMeasure #CURRENTSECTION# "Run"]
FinishAction=[!SetOption MeterShowMoon ImageName "Moon.jpg"][!UpdateMeter MeterShowMoon][!Redraw]

[MeterContainer]
Meter=Shape
Shape=Ellipse 100,100,96 | StrokeWidth 0

[MeterShowMoon]
Meter=Image
Path=#CURRENTPATH#
W=200
PreserveAspectRatio=1
Container=MeterContainer
GetMoon.ps1:

Code: Select all

$url = $args[0]
$file = $args[1]

if (Test-Path $file) 
{
  Remove-Item $file
}

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $file)


1.png



GetImage_3.0.rmskin



No need for the separate Calc measure to execute the RunCommand. That measure can execute itself based on UpdateDivider.
I implemented this method and it worked like a charm!

Thank you very much.
Issue solved!
Last edited by GTI.H on December 23rd, 2018, 8:33 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Why WebParser Download Stops Working?

Post by jsmorley »

Great!
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: Why WebParser Download Stops Working?

Post by GTI.H »

There was one thing missing:
Since OnDownloadErrorAction does not work in Measure MeasureGetMoon, how to detect Download error in Measure MeasureGetMoon?

I tried my old trick

Code: Select all

IfMatchMode=1
IfMatch=.*\w+
IfNotMatchAction=[!Log "Not Match"]
IfMatchAction=[!Log "Match"]
and it did not work. :(
User avatar
khanhas
Posts: 40
Joined: October 26th, 2016, 5:00 pm

Re: Why WebParser Download Stops Working?

Post by khanhas »

GTI.H wrote: December 23rd, 2018, 3:26 am There was one thing missing:
Since OnDownloadErrorAction does not work in Measure MeasureGetMoon, how to detect Download error in Measure MeasureGetMoon?

I tried my old trick

Code: Select all

IfMatchMode=1
IfMatch=.*\w+
IfNotMatchAction=[!Log "Not Match"]
IfMatchAction=[!Log "Match"]
and it did not work. :(
IfMatch = .+
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: Why WebParser Download Stops Working?

Post by GTI.H »

khanhas wrote: December 23rd, 2018, 12:23 pm IfMatch = .+
Thanks khanhas, but IfMatch=.+ did not work for me (for example, when the URL is wrong) with the above MeasureGetMoon.
There seem to be more problems than regular expression.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Why WebParser Download Stops Working?

Post by balala »

GTI.H wrote: December 23rd, 2018, 3:26 am Since OnDownloadErrorAction does not work in Measure MeasureGetMoon, how to detect Download error in Measure MeasureGetMoon?
Try the followings: first remove the above set of IfMatch options from the [MeasureGetMoon] measure, then add the following String measure to your code:

Code: Select all

[MeasureGetMoonResult]
Measure=String
String=[MeasureGetMoon]
IfMatch=^$
IfNotMatchAction=[!Log "Error"]
IfMatchAction=[!Log "No error"]
DynamicVariables=1
UpdateDivider=-1
Disabled=1
Finally add the following two bangs to the FinishAction option of the [MeasureGetMoon] measure: [!EnableMeasure "MeasureGetMoonResult"][!UpdateMeasure "MeasureGetMoonResult"] (with these bangs, the complete FinishAction option becomes: FinishAction=[!EnableMeasure "MeasureGetMoonResult"][!UpdateMeasure "MeasureGetMoonResult"][!SetOption MeterShowMoon ImageName "Moon.jpg"][!UpdateMeter MeterShowMoon][!Redraw]).