Windows .bat script using Curl with the HTTP password possible?

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
pjghangouts
New Cone
New Cone
Posts: 3
Joined: 18 Jul 2022 01:03

Windows .bat script using Curl with the HTTP password possible?

Postby pjghangouts » 18 Jul 2022 01:08

Hey All,

So I use VLC to play a stream from another local machine, but if the network has a hiccup for whatever reason, VLC will stop.

I know there is a /requests/status.xml, so I tried to CURL it, to a text file, that I can scan to see if it's playing or not, but use the webui being on, so I can control volume remotely, I have the PW set.

I'm not 100% with CURL, so I was wondering if anybody knew a was to pass the PW that VLC needs via the CLI/BAT so the status is output to a text file for me to scan?

Hope this makes sense, and sorry if it's in the wrong place, but it is a Web and Scripting question, so I figured this is the place.

Thanks in advance.
Regards
PJ

emcodem
Blank Cone
Blank Cone
Posts: 10
Joined: 05 Jul 2022 12:12

Re: Windows .bat script using Curl with the HTTP password possible?

Postby emcodem » 19 Jul 2022 09:46

When vlc commandline is started with http-pass only but not username:
-I http
--http-host 127.0.0.1
--http-port 8001,
--http-pass vlc

Code: Select all

curl.exe -u ":vlc" http://localhost:8001/requests/status.xml
if you want a username too, use curl option -u "username:passwd"

Alternatively you could also set the authorisation-basic header but that requires you to "encode" the username and password combination accordingly, there are lots of tutorials about curl and auth basic out there.

pjghangouts
New Cone
New Cone
Posts: 3
Joined: 18 Jul 2022 01:03

Re: Windows .bat script using Curl with the HTTP password possible?

Postby pjghangouts » 19 Jul 2022 16:19

When vlc commandline is started with http-pass only but not username:
-I http
--http-host 127.0.0.1
--http-port 8001,
--http-pass vlc

Code: Select all

curl.exe -u ":vlc" http://localhost:8001/requests/status.xml
if you want a username too, use curl option -u "username:passwd"

Alternatively you could also set the authorisation-basic header but that requires you to "encode" the username and password combination accordingly, there are lots of tutorials about curl and auth basic out there.
Thank you. I'm unsure why mine wasn't working (well, I am, it was wrong) but by copying yours and then just typing over the values I needed and adding -o "vlc_status.txt" I'll now be able to parse vlc_status.txt and check if <state>playing</state> is there, if it's not (or stopped, I believe) I'll be able to refresh the player and keep the music going.

Again, I thank you for your response.
Have a great rest of your day.

emcodem
Blank Cone
Blank Cone
Posts: 10
Joined: 05 Jul 2022 12:12

Re: Windows .bat script using Curl with the HTTP password possible?

Postby emcodem » 20 Jul 2022 17:15

No need to write the status to a file and read that in extra steps, you could just use findstr:

Code: Select all

curl -u ":vlc" http://localhost:8001/requests/status.xml | findstr "<state>playing"
after that, %ERRORLEVEL% is 0 if state is playing or 1 if state is different.

pjghangouts
New Cone
New Cone
Posts: 3
Joined: 18 Jul 2022 01:03

Re: Windows .bat script using Curl with the HTTP password possible?

Postby pjghangouts » 20 Jul 2022 19:23

No need to write the status to a file and read that in extra steps, you could just use findstr:

Code: Select all

curl -u ":vlc" http://localhost:8001/requests/status.xml | findstr "<state>playing"
after that, %ERRORLEVEL% is 0 if state is playing or 1 if state is different.
I might rejig my code, but I'm more of a 'google frankenstein' code builder, and I ended up with this below, it works, could be coded better, but I'm happy it works. :)

Code: Select all

@echo off curl -u ":password" -o "D:\!ChangeTracks\vlc_status.txt" http://localhost:port/requests/status.xml >nul find "<state>playing" D:\!ChangeTracks\vlc_status.txt && ( echo "playing" was found VLC Is Playing. ) || ( echo VLC is not playing IF EXIST "D:\music_stream.pls" ( echo 'File EXIST!' taskkill /f /im vlc.exe start "" "C:\Program Files\VideoLAN\VLC\vlc.exe" --extraintf=http --http-password=password --http-port=port D:\music_stream.pls exit ) ELSE ( echo 'No Music Stream file, aborting!' exit )
Again, thanks for your input.


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 13 guests