Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String from XML?
#1
I have a URL that retrieves XML.
Code:
Copy      Help
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?
#2
Same as in this post
https://www.quickmacros.com/forum/showth...2#pid33732
just change
x.RootElement.Child("state")
To
x.RootElement.Child("time")
#3
That part is helpful. I need to figure out how to get the result as a string from the URL. Thanks
#4
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.
Code:
Copy      Help
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
Code:
Copy      Help
<?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>
#5
need to use x.path to get that
Code:
Copy      Help
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
#6
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
Code:
Copy      Help
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! Smile

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.
#7
Here is another way to get the data from the vlc http server. Can do it directly from qm no external program needed
Code:
Copy      Help
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
#8
Wow. That works super. I like this because of fewer dependencies (really none). Thanks so much Kevin.
#9
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!
 
Code:
Copy      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
#10
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.
#11
this should cover it

Code:
Copy      Help
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
#12
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     Help - how to add the trigger to the macro
 
Code:
Copy      Help
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
,,,
#13
after looking at the documentation this can be done alot simpler
Macro VLCPosBck  
 
Code:
Copy      Help
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
Code:
Copy      Help
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
#14
Fantastic! Your expertise is unreal. Thank You
#15
Hi, I now want to use this same way to get two pieces of data. The difference is that they are not coming from XML. The first is also the time (e.g ''time'':314 is the line. resulting in just 314) that can be acquired by the "http://127.0.0.1:8080/requests/status.xml" data. However, I figured since I am reaching into the difference is to JSON here, I might as well keep it all JSON. The other part is the full path of the playing file. Handled by the 
 
Code:
Copy      Help
"http://127.0.0.1:8080/requests/playlist.json" 
It is found in a JSON Array with the current being next to a word current underneath it (e.g
 
Code:
Copy      Help
D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005408.mp4)
. like so:
 
Code:
Copy      Help
{
  "ro":"rw",
  "type":"node",
  "name":"",
  "id":"0",
  "children":[{
      "ro":"ro",
      "type":"node",
      "name":"Playlist",
      "id":"1",
      "children":[{
          "ro":"rw",
          "type":"leaf",
          "name":"IMG_005404.mp4",
          "id":"3",
          "duration":38,
          "uri":"file:///D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005404.mp4"
        },{
          "ro":"rw",
          "type":"leaf",
          "name":"IMG_005408.mp4",
          "id":"4",
          "duration":26,
          "uri":"file:///D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005408.mp4",
          "current":"current"
        },{
          "ro":"rw",
          "type":"leaf",
          "name":"IMG_005413.mp4",
          "id":"5",
          "duration":10,
          "uri":"file:///D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005413.mp4"
        }]
    },{
      "ro":"ro",
      "type":"node",
      "name":"Media Library",
      "id":"2",
      "children":[]
    }]
}
I was trying to configure and test. However I need help understanding how to work with JSON in here. I also was not having much luck with what I was trying with the regex function in QuickMacros. But i figured I could try a bit. But did not get to far.
 
Code:
Copy      Help
str s1 l2
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1

;--- Create HTTP request
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest p._create
h.Open("GET" "http://127.0.0.1:8080/requests/status.json")
p.Open("GET" "http://127.0.0.1:8080/requests/playlist.json")
h.setRequestHeader("content-type", "application/json")
h.setRequestHeader("content-type", "application/json")

;--- Basic auth (username:password) - just ":password" if no username
str enc.encrypt(4 ":vlcremote")
h.SetRequestHeader("Authorization", F"Basic {enc}")

;--- Send request
h.Send()
err
    out _error.description
    ret

;--- If successful
if h.Status=200
    str json = h.ResponseText
    str vlcState vlcTime vlcVolume filename

    ;--- Parse "state"
    str myTime = "''time'':"
    vlcTime = json.replacerx("(''time'':)\d+" "" )


        
        ;--- Output to console
        out vlcTime
        out myTime
    


        ;--- Write to file
        l2 = "C:\Temp\vlc.txt"
        s1 = F"{vlcTime},{filename}"
        s1.setfile(l2 -1 -1 1)
I don't know if I was on the correct track. Thanks for any help  Smile
#16
JSON parsing:
https://www.libreautomate.com/forum/show...p?tid=7832
#17
Thanks, my C# is so rusty these day... I want to look at and intergrate LibreAutomate C# soon. For now I came up with this. If there is anyway to get just the two lines I need that would awsome.
Code:
Copy      Help
str s1 l2 json1 json2
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest i._create

// First Request
h.Open("GET" "http://127.0.0.1:8080/requests/playlist.json")
h.setRequestHeader("content-type", "application/json")

str enc.encrypt(4 ":vlcremote") ;;replace ":vlcremote" with your password, if no username
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.Send()
err out _error.description; ret
if h.Status=200
    json1 = h.ResponseText

// Second Request
i.Open("GET" "http://127.0.0.1:8080/requests/status.json")
i.setRequestHeader("content-type", "application/json")
i.SetRequestHeader("Authorization", F"Basic {enc}")
i.Send()
err out _error.description; ret
if i.Status=200
    json2 = i.ResponseText

// Merge JSONs
s1 = F"{{''playlist'': {json1}, ''status'': {json2}}"

// Save to file
l2 = "C:\Users\Chris\data.json"
s1.setfile(l2 0 -1 1)

// need a way to get the line with syntax "time":### in s1
// need a way to get the line directly above syntax "current":"current" in s1
// do not really want to deal with an external file.
Thanks for any help.
#18
After combining the JSON results I was able to use the findrx function to get pretty close.
 
Code:
Copy      Help
s1 = F"{{''playlist'': {json1}, ''status'': {json2}}"

str pat1 rx1 sub1 pat2 rx2 sub2
pat1 = "''time'':\d+"
rx1 = findrx(s1 pat1 0 1 sub1)
pat2 = "''uri''\s*:\s*''([^'']+)''[^}]*?''current''\s*:\s*''current''"
rx2 = findrx(s1 pat2 0 1 sub2)

out rx1
out sub1
out sub2
Even though I could work with this result in my target app, I would like to refine (clean perfectly) the result in to somthing like so:
 
Code:
Copy      Help
120,D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005662.mp4
88,D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005782.mp4
321,D:/Sandbox/Test%20Work/250529%20_SNA_MIA_SDQ_Workspace/Trip%20Full%20Pics/IMG_005259.mp4
Or construct a JSON like output, because my target app will work well with that. Thanks for any help
#19
unless I'm missing something, you can get the data output in xml format as well if that makes it easier for you
#20
Hello, and thanks for the replay. Thank you for all the help you have given with this post in general. If it is possible to get the full path via XML, I would love to see it. I was under the impression it was not. The XML version is still super useful. I use it for the original purpose, but all I can receive is the filename (no path) and the time. Now the need has emerged to get the full path. However, I was able to achieve exactly what I wanted and figured out some more very useful stuff about Quick Macros. This program is so great. However, please show me how to get the full file path from XML. Thank you again for all the great replies.
Code:
Copy      Help
str s1 l2 json1 json2
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest i._create

// First Request
h.Open("GET" "http://127.0.0.1:8080/requests/playlist.json")
h.setRequestHeader("content-type", "application/json")

str enc.encrypt(4 ":vlcremote") ;;replace ":vlcremote" with your password, if no username
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.Send()
err out _error.description; ret
if h.Status=200
    json1 = h.ResponseText

// Second Request
i.Open("GET" "http://127.0.0.1:8080/requests/status.json")
i.setRequestHeader("content-type", "application/json")
i.SetRequestHeader("Authorization", F"Basic {enc}")
i.Send()
err out _error.description; ret
if i.Status=200
    json2 = i.ResponseText

// Merge JSONs
s1 = F"{{''playlist'': {json1}, ''status'': {json2}}"

str pat1 rx1 sub1 pat2 rx2 sub2 rep1 rep2 rep3 finz
pat1 = "''time'':\d+"
rx1 = findrx(s1 pat1 0 1 sub1)
pat2 = "''uri''\s*:\s*''([^'']+)''[^}]*?''current''\s*:\s*''current''"
rx2 = findrx(s1 pat2 0 1 sub2)

out
out rx1
out sub1
out sub2

rep1 = "''time'':"
rep2 = "''uri'':''file:"
rep3 = "'',\n.+''current'':''current''"
out rep3
// excuse all the test code it just helps me understand better :)
out sub1.replacerx(rep1 "" 1|8)
out sub1
out sub2.replacerx(rep2 "" 1|8)
out sub2.replacerx(rep3 "" 1|8)
finz = F"{sub1},{sub2}"
out finz
l2 = "C:\Temp\vlc.txt"
finz.setfile(l2 -1 -1 1)
To be clear when I was saying I did not want to work with a external file. I mean I did not want to send my result to a *.JSON file and then try to read it and process it. I did not need specific JSON processing here like Gintaras suggests. I just need quick extraction of some text in this result. In the end when ready I produce the comma separated text result this achieves, and it is saved to an external file. It is working great!
#21
The output Vlc sends is specific to the call. It will give the same data in json or xml just need to change the call
to get the data in xml just use

h.Open("GET" "http://127.0.0.1:8080/requests/playlist.xml")
h.setRequestHeader("content-type", "application/xml")

i.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
i.setRequestHeader("content-type", "application/xml")
#22
sorry for the delay was not near pc

From what i see the time request will only show the current time position of currently playing track
so for the others in your playlist it wont show the time. this will get the time for current track or will get the total time for all others

Function Function457
Code:
Copy      Help
str s1 s2 final
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest i._create

// First Request
h.Open("GET" "http://127.0.0.1:8080/requests/playlist.xml")
h.setRequestHeader("content-type", "application/xml")
str enc.encrypt(4 ":vlcremote") ;;replace ":vlcremote" with your password, if no username
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.Send()
err out _error.description; ret
if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,ARRAY(IXmlNode) a; 
,x.Path(".//leaf" a)
,for _i 0 a.len
,,IXmlNode attr attr1 attr2 attr3; attr=a[_i].Attribute("uri")
,,s2=attr.Value
,,s2.escape(8);; remove url formatting showing true path
,,s2.replacerx("file:///" "")
,,attr2=a[_i].Attribute("current")
,,if(attr2)
,,,// Second Request gets current time of currently playing playlist track
,,,i.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
,,,i.setRequestHeader("content-type", "application/xml")
,,,i.SetRequestHeader("Authorization", F"Basic {enc}")
,,,i.Send()
,,,err out _error.description; ret
,,,if i.Status=200
,,,,IXml x1._create
,,,,x1.FromString(i.ResponseText)
,,,,attr3=x1.Path("root/time")
,,,,if(attr3)
,,,,,s1= attr3.Value
,,else
,,,attr1=a[_i].Attribute("duration")
,,,s1=attr1.Value
,,final.addline(F"{s1},{s2}")
out final.rtrim

edited the previous post.Had some code double removed now.
#23
I see, thanks. I am going to run some tests. That is... accessing XML vs JSON as to which is faster. I say faster because since it is a extra node of "current" in both to determine which is the playing file. There needs to be a loop to get to it. Do you know the which is faster, XML JSON looping? I will report back what I can find out. Thanks so much!
#24
Kevin, how can the code you last posted be modified to only show the time and uri for the line that is current? Thanks

Something like this but I know you will show best practice.
 
Code:
Copy      Help
Macro [b]Macro74[/b] [help1][/help1]
[code]str s1 s2 final
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest i._create

// First Request
h.Open("GET" "http://127.0.0.1:8080/requests/playlist.xml")
h.setRequestHeader("content-type", "application/xml")
str enc.encrypt(4 ":vlcremote") ;; replace with your password if needed
h.SetRequestHeader("Authorization", F"Basic {enc}")
h.Send()
err out _error.description; ret

if h.Status=200
,IXml x._create
,x.FromString(h.ResponseText)
,ARRAY(IXmlNode) a
,x.Path(".//leaf" a)
,for _i 0 a.len
,,IXmlNode attr attr2 attr3; attr=a[_i].Attribute("uri")
,,attr2=a[_i].Attribute("current")
,,if(attr2)
,,,s2=attr.Value
,,,s2.escape(8)
,,,s2.replacerx("file:///" "")
,,,
,,,// Second Request for current playback time
,,,i.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
,,,i.setRequestHeader("content-type", "application/xml")
,,,i.SetRequestHeader("Authorization", F"Basic {enc}")
,,,i.Send()
,,,err out _error.description; ret
,,,if i.Status=200
,,,,IXml x1._create
,,,,x1.FromString(i.ResponseText)
,,,,attr3=x1.Path("root/time")
,,,,if(attr3)
,,,,,s1 = attr3.Value
,,,final = F"{s1},{s2}"
,,,break ;; stop after finding current item
out
out final
[/code]
#25
here ya go sorry for the delay 

Function Function460
 
Code:
Copy      Help
str s1 s2 final
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest h._create
WinHttp.WinHttpRequest i._create
str enc.encrypt(4 ":vlcremote") ;;replace ":vlcremote" with your password, if no username
IXml x._create; IXml x1._create
IXmlNode attr attr1 attr2 attr3;
i.Open("GET" "http://127.0.0.1:8080/requests/status.xml")
i.setRequestHeader("content-type", "application/xml")
i.SetRequestHeader("Authorization", F"Basic {enc}")
i.Send()
err out _error.description; ret
if i.Status=200
,x1.FromString(i.ResponseText)
,attr3=x1.Path("root/time")
,if(attr3)
,,s1= attr3.Value
,h.Open("GET" "http://127.0.0.1:8080/requests/playlist.xml")
,h.setRequestHeader("content-type", "application/xml")
,h.SetRequestHeader("Authorization", F"Basic {enc}")
,h.Send()
,err out _error.description; ret
,if h.Status=200
,,x.FromString(h.ResponseText)
,,ARRAY(IXmlNode) a; 
,,x.Path(".//leaf" a)
,,for _i 0 a.len
,,,attr=a[_i].Attribute("uri")
,,,s2=attr.Value
,,,s2.escape(8);; remove url formatting showing true path
,,,s2.replacerx("file:///" "")
,,,attr2=a[_i].Attribute("current")
,,,if(attr2)
,,,,final=F"{s1},{s2}"
,,,,out final


Forum Jump:


Users browsing this thread: 1 Guest(s)