Link to home
Start Free TrialLog in
Avatar of chaoticmaster
chaoticmaster

asked on

Regex for Rainmeter

Can someone please help with the Regexp below. I am using the webparser plugin in Rainmeter to pull now watching data from plex.

RegExp=(?siU)<Part container=.*\\(.*)".*<User id="1".*title="(.*)"

Results:
01=> Videos\TV Shows\24\Season 07\24 - 7x04 - Day 7 1100 A.M. - 1200 P.M
02=> chaoticmaster

I would like it to be:

 01=>24 - 7x04 - Day 7 1100 A.M. - 1200 P.M
 02=> chaoticmaster

Also is there anyway to get the code to the Regex based on the number of users.

So results would be:

01=> 24 - 7x04 - Day 7 1100 A.M. - 1200 P.M
02=> chaoticmaster
03=> Airplane II (1982)
04=> johndoe


I captured the user count information in a previous parse called ConnectedUsers

<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="2">
<Video addedAt="1396456678" art="/library/metadata/832/art/1402972060" contentRating="TV-14" duration="2592548" grandparentKey="/library/metadata/832" grandparentRatingKey="832" grandparentTheme="/library/metadata/832/theme/1402972060" grandparentThumb="/library/metadata/832/thumb/1402972060" grandparentTitle="24" guid="com.plexapp.agents.thetvdb://76290/7/4?lang=en" index="4" key="/library/metadata/34109" librarySectionID="2" originallyAvailableAt="2009-01-12" parentIndex="7" parentKey="/library/metadata/983" parentRatingKey="983" parentThumb="/library/metadata/983/thumb/1377743587" rating="7.4" ratingKey="34109" sessionKey="12" summary="Buchanan takes Jack to &quot;CTU&quot;, a secret hideout where he and Chloe had been working with Tony to uncover the conspiracy within the US government. Tony had been undercover with the terrorists aiding Juma to discover the moles. Jack agrees to help get Tony back in play by joining Emerson&apos;s crew himself.&#xA;&#xA;Taylor is forced to meet with Matobo to inform him that she may be required to withdraw her forces from Sangala to protect American lives. Her Chief of Staff Ethan Kanin agrees with this decision, but Taylor is not yet convinced.&#xA;&#xA;Henry meets with Samantha, Roger&apos;s former girlfriend, who tells him that Roger was indeed murdered and provides him with proof." thumb="/library/metadata/34109/thumb/1396456712" title="Day 7: 11:00 A.M. - 12:00 P.M." type="episode" updatedAt="1396456712" viewOffset="2590" year="2009">
<Media aspectRatio="1.78" audioChannels="2" audioCodec="mp3" bitrate="1132" container="avi" duration="2592548" height="352" id="32574" videoCodec="mpeg4" videoFrameRate="24p" videoResolution="sd" width="624">
<Part container="avi" duration="2592548" file="S:\Videos\TV Shows\24\Season 07\24 - 7x04 - Day 7 1100 A.M. - 1200 P.M.avi" id="32651" key="/library/parts/32651/file.avi" size="366778368">
<Stream bitDepth="8" bitrate="987" chromaSubsampling="4:2:0" codec="mpeg4" codecID="XVID" colorSpace="yuv" duration="2592548" frameRate="23.976" gmc="0" height="352" id="88935" index="0" level="5" profile="asp" qpel="0" scanType="progressive" streamType="1" title="" width="624" />
<Stream bitrate="128" bitrateMode="vbr" channels="2" codec="mp3" codecID="55" duration="2592504" id="88936" index="1" samplingRate="48000" selected="1" streamType="2" title="" />
</Part>
</Media>
<Writer count="19" id="22117" tag="David Fury" />
<Writer count="22" id="22153" tag="Alex Gansa" />
<Director count="47" id="22090" tag="Brad Turner" />
<User id="1" thumb="http://www.gravatar.com/avatar/eeb6c8eefb714b4f903161fc704f5b61?d=404" title="chaoticmaster" />
<Player machineIdentifier="8bfa9c3c-40b1-e9d6-9619-b380c351d54f" platform="Android" product="Plex for Android" state="paused" title="My Nexus 5" />
<TranscodeSession key="8bfa9c3c-40b1-e9d6-9619-b380c351d54f" throttled="1" progress="79.900001525878906" speed="0" duration="2592000" videoDecision="transcode" audioDecision="transcode" protocol="dash" container="mp4" videoCodec="h264" audioCodec="aac" audioChannels="2" width="419" height="236" />
</Video>
<Video addedAt="1377740339" art="/library/metadata/30/art/1377740577" duration="5020480" guid="com.plexapp.agents.imdb://tt2400312?lang=en" key="/library/metadata/30" lastViewedAt="1413838376" librarySectionID="1" ratingKey="30" sessionKey="13" summary="" thumb="/library/metadata/30/thumb/1377740577" title="&quot;At the Movies&quot; Tootsie/The Verdict/Sophies Choice/Airplane II (TV ..." type="movie" updatedAt="1377740577" viewOffset="994964">
<Media aspectRatio="1.78" audioChannels="2" audioCodec="ac3" bitrate="7477" container="mkv" duration="5020480" height="720" id="30" videoCodec="h264" videoFrameRate="24p" videoResolution="720" width="1280">
<Part container="mkv" duration="5020480" file="S:\Videos\Movies\Airplane II (1982)\Airplane II (1982).mkv" id="32" key="/library/parts/32/file.mkv" size="4692465149">
<Stream bitDepth="8" bitrate="7090" cabac="1" chromaSubsampling="4:2:0" codec="h264" codecID="V_MPEG4/ISO/AVC" colorSpace="yuv" duration="5020479" frameRate="23.976" frameRateMode="cfr" hasScalingMatrix="0" height="720" id="102014" index="0" language="English" languageCode="eng" level="41" profile="high" refFrames="4" scanType="progressive" streamType="1" title="" width="1280" />
<Stream bitDepth="16" bitrate="384" bitrateMode="cbr" channels="2" codec="ac3" codecID="A_AC3" dialogNorm="-27" duration="5020480" id="102015" index="1" language="English" languageCode="eng" samplingRate="48000" selected="1" streamType="2" title="" />
</Part>
</Media>
<User id="1" thumb="http://www.gravatar.com/avatar/eeb6c8eefb714b4f903161fc704f5b61?d=404" title="johndoe" />
<Player machineIdentifier="v8d5xnt7w4620529" platform="Chrome" product="Plex Web" state="playing" title="Plex Web (Chrome)" />
<TranscodeSession key="ytzymbky87zf47vi" throttled="1" progress="71" speed="0" duration="1304000" videoDecision="copy" audioDecision="transcode" protocol="http" container="matroska" videoCodec="h264" audioCodec="aac" audioChannels="2" width="1280" height="720" />
</Video>
</MediaContainer>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(?siU)<Part container=.*\\([^\\]*)".*<User id="1".*title="(.*)"
Avatar of chaoticmaster
chaoticmaster

ASKER

@wilcoxon

Using ozo correct REGEX below. I modified it slightly for my needs.

I will set a variable:
get=<Part container=.*\\([^\\]*)\.\w{3,4}".*<User id="1".*title="(.*)".*

When 1 User is connected:
RegExp="(?siU)#get#"

When 2 Users are connected:
RegExp="(?siU)#get##get#

Part two of my question was asking if it is possible to have one REGEX that can capture all the data for indiscriminate of the number of users . The XML data will always be in the same predictable sequence.
What do you mean using ozo's correct REGEX?  His regex is identical to the one I provided (just minus the Regexp=).

It probably is not possible unless what you have supports array repeated captures.  In perl, you should be able to do something like:
my @cap = m{(?:<Part container=.*\\([^\\]*)\.\w{3,4}".*<User id="1".*title="(.*)".*)+}si;

Open in new window


However, I don't think that will work for you (you have "perl" listed as a zone but the syntax of Rainmeter/webparser is definitely different.
I actually didnt notice that you posted code. I will award you the points since you posted first.