Posts: 64
Threads: 19
Joined: Nov 2012
I have a URL that retrieves XML.
http://127.0.0.1:8080/requests/status.xml
How could I get the data and then only extract the parts I want? For example the XML shows data between a <time></time> tag. How could I create a string from what is inside the <time> tag?
Posts: 1,336
Threads: 61
Joined: Jul 2006
Same as in this post
https://www.quickmacros.com/forum/showth...2#pid33732
just change
x.RootElement.Child("state")
To
x.RootElement.Child("time")
Posts: 64
Threads: 19
Joined: Nov 2012
That part is helpful. I need to figure out how to get the result as a string from the URL. Thanks
Posts: 64
Threads: 19
Joined: Nov 2012
03-06-2022, 09:34 AM
(This post was last modified: 03-06-2022, 09:50 AM by pctechtv.)
I figured out how to get the file. I chose to use wget to handle the text file creation. If anyone would like me to share the wget process just shout. It works well for XML or JSON online or localhost. So this works very well.
str sxml wg fil
fil = "C:\BASE\file1.txt"
wg = "C:\Temp\wg.bat"
;out wg
run(wg)
sxml.getfile(fil)
IXml x._create
x.FromString(sxml)
IXmlNode e = x.RootElement.Child("time")
IXmlNode f = x.RootElement.Child("volume")
out e.Value
out f.Value
However, my XML looking like this I cannot seem to grab info from a tag named info. There are multiple with that name. I need a specific one. I need to get the value inside of the info tag with the name=" filename" attribute. To be clear the exact information I would need here would be SheetRockWork.mp4 Thanks
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<root>
<fullscreen>false</fullscreen>
<aspectratio>default</aspectratio>
<audiodelay>0</audiodelay>
<apiversion>3</apiversion>
<currentplid>3</currentplid>
<time>20</time>
<volume>51</volume>
<length>32</length>
<random>false</random>
<audiofilters>
<filter_0></filter_0></audiofilters>
<rate>1</rate>
<videoeffects>
<hue>0</hue>
<saturation>1</saturation>
<contrast>1</contrast>
<brightness>1</brightness>
<gamma>1</gamma></videoeffects>
<state>playing</state>
<loop>false</loop>
<version>3.0.16 Vetinari</version>
<position>0.64083784818649</position>
<repeat>false</repeat>
<subtitledelay>0</subtitledelay>
<equalizer></equalizer><information>
<category name="meta">
<info name='encoded_by'>Lavf58.29.100</info><info name='filename'>SheetRockWork.mp4</info> </category>
<category name='Stream 0'><info name='Type'>Video</info><info name='Frame rate'>120</info><info name='Video resolution'>1920x1080</info><info name='Codec'>H264 - MPEG-4 AVC (part 10) (avc1)</info><info name='Decoded format'></info><info name='Buffer dimensions'>1920x1088</info><info name='Chroma location'>Left</info><info name='Language'>English</info><info name='Orientation'>Top left</info></category><category name='Stream 1'><info name='Codec'>MPEG AAC Audio (mp4a)</info><info name='Channels'>Stereo</info><info name='Bits per sample'>32</info><info name='Sample rate'>48000 Hz</info><info name='Language'>English</info><info name='Type'>Audio</info></category> </information>
<stats>
<lostabuffers>0</lostabuffers>
<readpackets>756</readpackets>
<lostpictures>7</lostpictures>
<demuxreadbytes>9144282</demuxreadbytes>
<demuxbitrate>0.32542899250984</demuxbitrate>
<playedabuffers>1021</playedabuffers>
<demuxcorrupted>0</demuxcorrupted>
<sendbitrate>0</sendbitrate>
<sentbytes>0</sentbytes>
<displayedpictures>2469</displayedpictures>
<demuxreadpackets>0</demuxreadpackets>
<sentpackets>0</sentpackets>
<inputbitrate>0.33028799295425</inputbitrate>
<demuxdiscontinuity>2</demuxdiscontinuity>
<averagedemuxbitrate>0</averagedemuxbitrate>
<decodedvideo>4997</decodedvideo>
<averageinputbitrate>0</averageinputbitrate>
<readbytes>9227183</readbytes>
<decodedaudio>2043</decodedaudio>
</stats>
</root>
Posts: 1,336
Threads: 61
Joined: Jul 2006
need to use x.path to get that
IXml x._create
x.FromString(sxml)
IXmlNode e
e=x.RootElement.Child("time")
str t=e.Value
e=x.RootElement.Child("volume")
str v=e.Value
e=x.Path("root/information/category/info[@name='filename']")
str f= e.Value
out t
out v
out f
Posts: 64
Threads: 19
Joined: Nov 2012
03-06-2022, 09:10 PM
(This post was last modified: 03-06-2022, 09:18 PM by pctechtv.)
That is super. Let me tell you why. Before I posted I read some messages on this forum that used the x.Path syntax. I tried them like this
x.Path("root/information/category/info" a)
Already I could see the point. I learned JavaScript around the time JSON was becoming popular. Let's say all concerns for me pointed more towards JSON not XML. However, when I saw XPath stuff I always wondered what it so related to. Even with C++ my studies have leaned more toward JSON. So after all this time, I see some of the usefulness of XPath related to XML.
Kevin, this works like a charm here. However, I have tons of useful ideas now. Thanks so much!
To share more if ever it useful to other members... this is for VLC Player. I do a lot of things in the media world. We are always dealing with gigantic HiRes video files. When we see the content we need to remember what and where. This button for us will allow us to quickly make a record of what we are seeing. By having the filename and position of the video we will be able to find and understand our ideas later. If anybody would need similar just shout and I can help explain how to set it up if needed.
Posts: 1,336
Threads: 61
Joined: Jul 2006
Here is another way to get the data from the vlc http server. Can do it directly from qm no external program needed
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
h.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
h.setRequestHeader("content-type", "application/xml");
str enc.encrypt(4 ":test");;password for vlc http server(username:password) if no usename then just :password
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,str vlcTime=x.RootElement.Child("time").Value
,,str vlcVolume=x.RootElement.Child("volume").Value
,,str filename=x.Path("root/information/category/info[@name='filename']").Value
,,out vlcTime
,,out vlcVolume
,,out filename
,else
,,out x.RootElement.Child("state").Value
Posts: 64
Threads: 19
Joined: Nov 2012
Wow. That works super. I like this because of fewer dependencies (really none). Thanks so much Kevin.
Posts: 64
Threads: 19
Joined: Nov 2012
05-23-2023, 04:29 AM
(This post was last modified: 05-23-2023, 04:33 AM by pctechtv.)
Hi, good friends. I wanted to do more after the super help (thanks to Kevin) I received with this. So here I ran a test to see if I could get the play head to 80% of the video playing. Viola, it worked like a charm.
I ultimately would like to use a percentage like 20 to move the play head in 20% increments. To do so I need to increment the amount. Off course bringing it back to 20 again once at 80. I do not know how I would get the value to store. I know how to do something like that in a text file. However, I am asking if there is a simpler, more efficient way to do this. I would imagine some type of a loop. Thanks for any help!
str s1 l2
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
h.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
h.setRequestHeader("content-type", "application/xml");
str enc.encrypt(4 ":vlcremote");;password for vlc http server(username:password) if no usename then just :password
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,str vlcTime=x.RootElement.Child("length").Value
,,str vlcVolume=x.RootElement.Child("volume").Value
,,str filename=x.Path("root/information/category/info[@name='filename']").Value
,,out vlcTime
,,out vlcVolume
,,out filename
,,int i
,,i=val(vlcTime); out i
,,str s02=(i/5) * 4; out s02
,,s1=F"http://127.0.0.1:8080/requests/status.xml?command=seek&val={s02}"
,,WinHttp.WinHttpRequest j._create
,,j.Open("GET" s1)
,,j.setRequestHeader("content-type", "application/xml");
,,j.SetRequestHeader("Authorization", F"Basic {enc}")
,,j.send()
,else
,,out x.RootElement.Child("state").Value
Posts: 64
Threads: 19
Joined: Nov 2012
05-23-2023, 12:51 PM
(This post was last modified: 05-23-2023, 01:34 PM by pctechtv.)
Thinking about this more... I don't need to store it. The current playing location is the "storage" that needs to be calculated. I already have this. I need to come up with the equation.
Posts: 1,336
Threads: 61
Joined: Jul 2006
this should cover it
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
str s1="http://127.0.0.1:8080/requests/status.xml"
h.Open("GET" s1)
h.setRequestHeader("content-type", "application/xml");
str enc.encrypt(4 ":vlcremote");;password for vlc http server(username:password) if no usename then just :password
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,str vlcLength=x.RootElement.Child("length").Value
,,str vlcTime=x.RootElement.Child("time").Value
,,str vlcVolume=x.RootElement.Child("volume").Value
,,str filename=x.Path("root/information/category/info[@name='filename']").Value
,,out vlcLength
,,out vlcTime
,,out vlcVolume
,,out filename
,,double d=val(vlcTime 2) / val(vlcLength 2)
,,str seek
,,if(d<0.20)
,,,seek="20%"
,,if(d>=0.20 and d<0.40)
,,,seek="40%"
,,if(d>=0.40 and d<0.60)
,,,seek="60%"
,,if(d>=0.60 and d<0.80)
,,,seek="80%"
,,if(d>=0.80)
,,,seek="20%"
,,seek.escape(9)
,,s1=F"http://127.0.0.1:8080/requests/status.xml?command=seek&val={seek}"
,,h.Open("GET" s1)
,,h.setRequestHeader("content-type", "application/xml");
,,h.SetRequestHeader("Authorization", F"Basic {enc}")
,,h.send()
,else
,,out x.RootElement.Child("state").Value
Posts: 64
Threads: 19
Joined: Nov 2012
That is super! I learn something every time I come here. I also realize my idea about using <time> needs to be relooked at. The way you answered was perfect. However, my question/idea is not. The reason is the one second intervals VLC updates in is too much for a key press. To be clear, there is always potential to get stuck there. No change is able to be compared to using >=. I am taking a look at using <position>. The position divides the length by 1/0.00000000000000, so the number changes quicker than a millisecond. Here is what I got to work. I will keep working on it. I now need to come up with the logic to go backward. This is a little more tricky because it needs a reasonable time it advances to, for it to be eligible to go back. Thanks so much!
Macro VLCPosFwd
Trigger CF18
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
str s1="http://127.0.0.1:8080/requests/status.xml"
h.Open("GET" s1)
h.setRequestHeader("content-type", "application/xml");
str enc.encrypt(4 ":vlcremote");;password for vlc http server(username:password) if no usename then just :password
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,;str vlcLength=x.RootElement.Child("length").Value
,,int vlcLength=1
,,str vlcTime=x.RootElement.Child("position").Value
,,str vlcVolume=x.RootElement.Child("volume").Value
,,str filename=x.Path("root/information/category/info[@name='filename']").Value
,,out vlcLength
,,out vlcTime
,,out vlcVolume
,,out filename
,,double d=val(vlcTime 2) / vlcLength
,,str seek
,,if(d<0.05)
,,,seek="5%"
,,if(d>=0.05 and d<0.10)
,,,seek="10%"
,,if(d>=0.10 and d<0.15)
,,,seek="15%"
,,if(d>=0.15 and d<0.20)
,,,seek="20%"
,,if(d>=0.20 and d<0.25)
,,,seek="25%"
,,if(d>=0.25 and d<0.30)
,,,seek="30%"
,,if(d>=0.30 and d<0.35)
,,,seek="35%"
,,if(d>=0.35 and d<0.40)
,,,seek="40%"
,,if(d>=0.40 and d<0.45)
,,,seek="45%"
,,if(d>=0.45 and d<0.50)
,,,seek="50%"
,,if(d>=0.50 and d<0.55)
,,,seek="55%"
,,if(d>=0.55 and d<0.60)
,,,seek="60%"
,,if(d>=0.60 and d<0.65)
,,,seek="65%"
,,if(d>=0.65 and d<0.70)
,,,seek="70%"
,,if(d>=0.70 and d<0.75)
,,,seek="75%"
,,if(d>=0.75 and d<0.80)
,,,seek="80%"
,,if(d>=0.80 and d<0.85)
,,,seek="85%"
,,if(d>=0.85 and d<0.90)
,,,seek="90%"
,,if(d>=0.90 and d<0.95)
,,,seek="95%"
,,if(d>=0.95)
,,,seek="5%"
,,seek.escape(9)
,,s1=F"http://127.0.0.1:8080/requests/status.xml?command=seek&val={seek}"
,,h.Open("GET" s1)
,,h.setRequestHeader("content-type", "application/xml");
,,h.SetRequestHeader("Authorization", F"Basic {enc}")
,,h.send()
,,out seek
,else
,,out x.RootElement.Child("state").Value
,,,
Posts: 1,336
Threads: 61
Joined: Jul 2006
05-27-2023, 12:08 PM
(This post was last modified: 05-27-2023, 12:11 PM by Kevin.)
after looking at the documentation this can be done alot simpler
Macro VLCPosBck
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
str s1="http://127.0.0.1:8080/requests/status.xml"
str enc.encrypt(4 ":vlcremote");;password for vlc http server(username:password) if no usename then just :password
h.Open("GET" s1)
h.setRequestHeader("content-type", "application/xml"); h.SetRequestHeader("Authorization", F"Basic {enc}")
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,str vlcPosition=x.RootElement.Child("position").Value
,,double d=val(vlcPosition 2)
,,str seek
,,if(d<=0.05)
,,,seek="95%"
,,else
,,,seek="-5%"
,,seek.escape(9)
,,s1=F"http://127.0.0.1:8080/requests/status.xml?command=seek&val={seek}"
,,h.Open("GET" s1)
,,h.setRequestHeader("content-type", "application/xml"); h.SetRequestHeader("Authorization", F"Basic {enc}")
,,h.send()
,else
,,out x.RootElement.Child("state").Value
Macro VLCPosFwd
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
str s1="http://127.0.0.1:8080/requests/status.xml"
str enc.encrypt(4 ":vlcremote");;password for vlc http server(username:password) if no usename then just :password
h.Open("GET" s1)
h.setRequestHeader("content-type", "application/xml"); h.SetRequestHeader("Authorization", F"Basic {enc}");
h.send()
err
,out _error.description
,ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,str vlcState =x.RootElement.Child("state").Value
,if vlcState !="stopped"
,,str vlcPosition=x.RootElement.Child("position").Value
,,double d=val(vlcPosition 2)
,,str seek
,,if(d>=0.95)
,,,seek="5%"
,,else
,,,seek="+5%"
,,seek.escape(9)
,,s1=F"http://127.0.0.1:8080/requests/status.xml?command=seek&val={seek}"
,,h.Open("GET" s1)
,,h.setRequestHeader("content-type", "application/xml"); h.SetRequestHeader("Authorization", F"Basic {enc}")
,,h.send()
,else
,,out x.RootElement.Child("state").Value
Posts: 64
Threads: 19
Joined: Nov 2012
Fantastic! Your expertise is unreal. Thank You
|