It is currently September 30th, 2024, 1:20 am

Display image(s) based on contents of XML file?

General topics related to Rainmeter.
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Display image(s) based on contents of XML file?

Post by darcilicious »

I have a skin where I want to display different images based on what is or isn't in an XML file (served from a local web server) related to a personal DVR program.

For example, when the DVR is recording, something like this will show up in the XML file:

Code: Select all

<title>The Bourne Ultimatum</title>
along with a bunch of other data.

When the DVR is not recording, the XML file will be much smaller and have very little data in it. There won't be a <title> element for example.

So basically, when the XML file has <title>something</title> in it, I want to display an image and when it's not, I don't want to display that image.

I'm familiar with the WebParser plugin (have used it to parse another XML file to display the upcoming recording schedule, for example) but I'm not quite clear on how I would go about implement this kind of off/on status in the skin.

Any pointers?

(I'll need something similar showing a different system status image based on the values of 0, 1, 2, and 3, where 0 means don't show an image, 1=blue, 2=yellow, and 3=red image).

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

Re: Display image(s) based on contents of XML file?

Post by jsmorley »

It would be better if you can post at least a snippet of the XML code you are parsing (preferable two versions, one when <title> is there and one when not), so we can have something to work with / test. There is probably an easy way to get what you want.

Also, is the only goal in reading the XML to detect "recording / not recording"? If you want more info from the XML at the same time, that will change the approach.

You might need to get into more details about what in the XML drives the 0/1/2/3 as well, so we can help with that if needed.
User avatar
jsmorley
Developer
Posts: 22793
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Display image(s) based on contents of XML file?

Post by jsmorley »

Just based on what you literally have asked so far, I would do something like:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureXML]
Measure=Plugin
Plugin=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp="(?siU).*<Title>(.*)</Title>"
StringIndex=1
Substitute="":"-1"
FinishAction=!EnableMeasure MeasureCheck

[MeasureCheck]
Measure=Calc
Formula=[MeasureXML]
IfEqualValue=-1
IfEqualAction=!SetOption MeterRecording ImageName "#@#Images\RedLight.png"
IfAboveValue=-1
IfAboveAction=!SetOption MeterRecording ImageName "#@#Images\GreenLight.png"
DynamicVariables=1
Disabled=1

[MeterRecording]
Meter=Image
W=40
H=40
ImageName=#@#Images\OffLight.png
What it does is look for <Title>, if it is not found, it substitutes the empty "" string returned by WebParser with the string "-1"

Then it fires up a Calc measure that converts the string from WebParser to a number. It will either be -1 or 0 (any actual string, like the name of a movie, will convert to the number 0).

Then we test for -1 (no movie) or 0 (movie) and set the image in the meter to the appropriate one.

Here is the Text.html test file I used to parse:

Code: Select all

<Item>
	<Title>The Red Badge of Courage</Title>
</Item>
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Re: Display image(s) based on contents of XML file?

Post by darcilicious »

Thanks so much for the help so far -- here's (nearly) the first half of the XML file when there's a recording active:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sageShowInfo PUBLIC "-//NIELM//DTD SAGESHOWINFO XML 1.3//EN" "http://sageplugins.sourceforge.net/nielm_modules/sagexmlinfo/sageshowinfo_1_3.dtd">
<sageShowInfo version="1.3">
    <systemInfo>
        <alertLevel description="Status" level="0"/>
    </systemInfo>
    <channelList>
        <channel channelId="42642">
            <channelName>TNTHD</channelName>
            <channelDescription>Turner Network TV HD</channelDescription>
            <channelNetwork>Digital</channelNetwork>
            <channelNumber>551</channelNumber>
        </channel>
    </channelList>
    <favoriteList/>
    <showList>
        <show epgId="MV1951140000">
            <title>The Bourne Ultimatum</title>
            <duration>6900</duration>
            <category>Movie</category>
            <subCategory>Action</subCategory>
Here's the complete contents when there's no active recording:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sageShowInfo PUBLIC "-//NIELM//DTD SAGESHOWINFO XML 1.3//EN" "http://sageplugins.sourceforge.net/nielm_modules/sagexmlinfo/sageshowinfo_1_3.dtd">
<sageShowInfo version="1.3">
    <systemInfo>
        <alertLevel description="Status" level="0"/>
    </systemInfo>
    <channelList/>
    <favoriteList/>
    <showList/>
    <systemMessageList/>
</sageShowInfo>
In each case, the file has the current "System Status" within the systemIfno section.

Thanks again, this will be a great replacement for a Windows gadget that does similar things :)

I need some caffeine, I'll take a look at your code above shortly and start playing with it, thanks so much!
User avatar
jsmorley
Developer
Posts: 22793
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Display image(s) based on contents of XML file?

Post by jsmorley »

What are your "goals"? Will there be more than one <title> at a time that you want to detect and show an image for? What information do you want to retrieve to use? Just the fact that a <title> exists in the list, or the name(s) and or other information?
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Re: Display image(s) based on contents of XML file?

Post by darcilicious »

I only need to know if there's one active recording or no active recording; more doesn't matter -- if there's at least one, then the red recording image should be displayed until there are no active recordings. I picked <title> just because it's an obvious choice but the title data itself isn't needed (as it will already be displayed elsewhere in the skin as part of the list of titles that I've collected from another file). If it's better / less resource intensive to use something earlier in the file, I'm all for it :)

Here's what the skin looks like -- currently I'm always displaying the "recording" image but everything else is "live" from the local web server.

Image

I'm thinking that the system status will be much easier, which is why I asked about the "harder" one first :)

Thanks!
User avatar
jsmorley
Developer
Posts: 22793
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Display image(s) based on contents of XML file?

Post by jsmorley »

I think what I posted above should work pretty well for detecting the "recording" bit. As to the status, I would just do that in another WebParser measure and just parse out the "0/1/2/3" or whatever.

Note: I would be tempted to get the entire site with one WebParser measure and parse everything at once with a Lua script, but it is up to you if you want to dig deeper into it like that. Using a couple of WebParser measures and such will work fine.
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Re: Display image(s) based on contents of XML file?

Post by darcilicious »

Excellent! Thanks! I'll report back later today :)
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Re: Display image(s) based on contents of XML file?

Post by darcilicious »

jsmorley wrote:Note: I would be tempted to get the entire site with one WebParser measure and parse everything at once with a Lua script, but it is up to you if you want to dig deeper into it like that. Using a couple of WebParser measures and such will work fine.
Yeah, I'm not quite ready to dive into Lua just yet ;) But using Lua throughout this skin/project would definitely have some advantages over WebParser. Maybe for the second iteration :)
darcilicious
Posts: 34
Joined: May 1st, 2010, 5:34 pm

Re: Display image(s) based on contents of XML file?

Post by darcilicious »

Okay, just to be clear, there should only be two images displayed: one for when there's a recording (red light) and one for when there's no recording, called RecordingOn.png and RecordingOff.png respectively

Given this, I'm having trouble understanding how this meter displays the correct image:

Code: Select all

[MeterRecording]
Meter=Image
W=40
H=40
ImageName=#@#Images\OffLight.png
based on this:

Code: Select all

[MeasureCheck]
Measure=Calc
Formula=[MeasureXML]
IfEqualValue=-1
IfEqualAction=!SetOption MeterRecording ImageName "#@#Images\RedLight.png"
IfAboveValue=-1
IfAboveAction=!SetOption MeterRecording ImageName "#@#Images\GreenLight.png"
DynamicVariables=1
Disabled=1
I would switch RedLight.png to RecordingOn.png and GreenLight.png to RecordingOff.png but I have no idea what Offlight.png is for or how it's getting updated when a recording starts then stops. It seems llike Offlight.png is always going to get displayed??

I'm probably missing something obvious here, sorry.