Windows .bat script using Curl with the HTTP password possible?
Posted: 18 Jul 2022 01:08
by pjghangouts
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
Re: Windows .bat script using Curl with the HTTP password possible?
Posted: 19 Jul 2022 09:46
by emcodem
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.
Re: Windows .bat script using Curl with the HTTP password possible?
Posted: 19 Jul 2022 16:19
by pjghangouts
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.
Re: Windows .bat script using Curl with the HTTP password possible?
Posted: 20 Jul 2022 17:15
by emcodem
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.
Re: Windows .bat script using Curl with the HTTP password possible?
Posted: 20 Jul 2022 19:23
by pjghangouts
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.