It is currently June 16th, 2021, 9:54 am

How to substitute part of url for image webparser download

General topics related to Rainmeter.
User avatar
death.crafter
Posts: 174
Joined: April 24th, 2021, 8:13 pm

Re: How to substitute part of url for image webparser download

Post by death.crafter »

SlowCircuit wrote: April 18th, 2021, 9:47 pm That definitely worked, thanks! It's a shame I have to use a workaround like this though, because there are 30 images I need to do this with, so I need 30 more measures for getting the URL, 30 variables to store the URLs, etc.
Actually if you look into PowershellRM(can be used for scripting) or Lua Scripting you can do it without having to use 30 measures.
from the Realm of Death
User avatar
balala
Rainmeter Sage
Posts: 12782
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to substitute part of url for image webparser download

Post by balala »

death.crafter wrote: May 13th, 2021, 1:22 pm Actually if you look into PowershellRM(can be used for scripting) or Lua Scripting you can do it without having to use 30 measures.
Don't contest it can be done, however an example always would be nice. Post it please.
User avatar
death.crafter
Posts: 174
Joined: April 24th, 2021, 8:13 pm

Re: How to substitute part of url for image webparser download

Post by death.crafter »

balala wrote: May 13th, 2021, 5:16 pm Don't contest it can be done, however an example always would be nice. Post it please.
Skin file:

Code: Select all

[Variables]
RSSLink0=
RSSLink1=
RSSLink2=
...

[MeasureScript]
Measure=Script
ScriptFile=ImageParser.lua
ImageCount=30
UpdateDivider=-1

[Feed]
Measure=WebParser
Url=[#RSSLink[#CurrentNum]]
RegExp="(?siU)#RegexPattern#
 
[ItemImage]
Measure=WebParser
Url=[Feed]
StringIndex=3
DynamicVariables=1
DecodeCharacterReference=1
Substitute=#Substitutes#

[MeasureDownloadImage]
Measure=WebParser
Url=[ItemImage]
Download=1
DownloadFile=[#CurrentNum].png
UpdateRate=600
DynamicVariables=1
Disabled=1

[Item0Thumbnail]
Meter=Image
ImageName=0.png
Lua:

Code: Select all

function Initialize()
    local imageCount=SELF:GetOption("ImageCount")
    for i=0, imageCount-1, 1 do
        SKIN:Bang('!SetVariable', 'CurrentNum', i)
        SKIN:Bang('!UpdateMeasure', 'Feed')
        SKIN:Bang('!CommandMeasure', 'ItemImage', 'Update')
        SKIN:Bang('!EnableMeasure', 'MeasureDownloadImage')
        SKIN:Bang('!CommandMeasure', 'MeasureDownloadImage', 'Update')
        SKIN:Bang('!UpdateMeter', 'Item'..i..'Thumbnail')
        SKIN:Bang('!Redraw')
    end
end
from the Realm of Death
User avatar
death.crafter
Posts: 174
Joined: April 24th, 2021, 8:13 pm

Re: How to substitute part of url for image webparser download

Post by death.crafter »

death.crafter wrote: May 16th, 2021, 3:07 am
Since lua is fast and download may not commence at this rate, there is a probability this lua may not work. And honestly I don't know how to add delay to a chain of action in lua. So I am attaching a PSRM script too...
Measure:

Code: Select all

[PSRM]
Measure=Plugin
Plugin=PowershellRM
ScriptFile=GetImages.ps1
UpdateDivider=-1
Script:

Code: Select all

function GetImages {
    $imageCount=30
    for ($i=0; $i -lt $imageCount; $i++) {
        $RmAPI.Bang("!SetVariable CurrentNum $i")
        $RmAPI.Bang("!UpdateMeasure Feed")
        Start-Sleep -Milliseconds 50
        $RmAPI.Bang("!UpdateMeasure ItemImage")
        $RmAPI.Bang("!UpdateMeasure MeasureDownloadImage")
        $Start-Sleep -Milliseconds 100
        $RmAPI.Bang("[!UpdateMeter Item$("$i"+'Thumbnail')][!Redraw]")
        Start-Sleep -Milliseconds 100
    }
}
This script would give 4 images per second, which may seem pretty slow but it's an alternative if Lua doesn't work, just to be safe.

And since we have to execute this script, we can add an action somewhere,
for example:

Code: Select all

OnRefreshAction=!Command Measure PSRM "GetImages"
from the Realm of Death