1

Im trying to make a little Batch script to navigate to different Chromecasts around my place, and for a place to copy pasta the URL to stream more conveniently.

Normally you can open VLC, play a video, go Render > select the named device.

I found a CMD line that works for this:

vlc "https://www.youtube.com/watch?v=YoUrVidEoHerE" --sout "#chromecast" --sout-chromecast-ip=192.168.0.00 --demux-filter=demux_chromecast

So naturally I wanted to automate it.

Here is where I'm at:

@echo off
setlocal enableextensions enabledelayedexpansion

:: Below, set DEBUG to 1 to enable displaying more messages for diagnosis
SET DEBUG=0
SET DBG=REM
IF "%DEBUG%"=="1" (SET DBG=ECHO ** DEBUG : )

GOTO start

:ascii_art
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do echo(%%A
:::
:::            @@@@@@@@@@@@@@@@@@@@@@@@@@@        
:::       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:::     @@@@@@@@@@@Chromecast Streamer@@@@@@@@@@@
:::    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:::   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:::   @@@@@@@@@@@@@@  '.@@@@@@@@@@@@@@@@@.--.@@@@@@@@@
:::     @@@@@@@@\   @@  @@ @@@@@@@@@@@ '@@ ___..@@@@@@
:::      @@@@@@@@|                 @    .'@@@@@@@@@@
:::         @@@@@@\                    /@@@@@@@@
:::                \                  /
:::                |   .--'|__|'--.   |
:::                |  /.--'/  \'--.\  |
:::    __  ___     /      /____\      \     ___
:::  _(  )(   )_  |     .' .''. '.     |  _(   )__  __      __
::: (           )_|    |__/    \__|    |_(        )(  )_   (
:::              /                      \__             )_(_
::: _______.---./    .'       COPY          \_.--._ ___________
:::   --'''        _/    __  PASTA                '--..      
:::              ''    .'   THE URL AND PRESS ENTER BELOW!!!
GOTO :eof


:start
cls
call :ascii_art
ECHO.
ECHO 1 - Kitchen
ECHO 2 - Living Room
ECHO 3 - My Room
ECHO 4 - EXIT

:: the choice command

set pass=
choice /c 1234 /n /m ""
set pass=%errorlevel%

:: Setting default input message and IP Address parameter, then changing them if needed,
:: depending on the user's choice
SET Param=
SET MSG=PASTE URL HERE: 
IF "%pass%"=="1" SET Param=192.168.0.01
IF "%pass%"=="2" SET Param=-192.168.0.02
IF "%pass%"=="3" SET Param=192.168.0.03
IF "%pass%"=="4" GOTO exit
goto do_it

:do_it
cls
call :ascii_art
ECHO.
%DBG% User choice was : %pass%
SET URL=
set /p URL=%MSG%
IF [%URL%]==[] GOTO start
SET VLCstr="%URL%" --sout "#chromecast" --sout-chromecast-ip=%Param% --demux-filter=demux_chromecast
SET Command="X:\Software\Applications\win64\VLC\vlc.exe" %VLCstr%

%DBG% Running command : %Command%
%Command%
cls
call :ascii_art
ECHO.
ECHO Your stream has been vanquished.
pause
goto start

:exit
ENDLOCAL

Currently If you replace the %URL% in the line with VLCstr= with an actual URL, it works perfectly fine.

Theres something up with how I'm asking for the last input, and how its being put into the string.

I would like it to keep it where it accepts Weburls, and local files too.

Is there something simple I'm missing?

Compo
  • 30,301
  • 4
  • 20
  • 32
  • 2
    Well my first advice is to change, `IF [%URL%]==[]` to `IF "%URL%"==""`. If this fails to fix your stated issue, could you please provide us with at least one failing URL you pasted into the prompt, or let us know if they all fail. – Compo Jan 05 '20 at 23:33
  • 2
    IP addresses do not have leading zeros in an octet. Nor should it have a dash before it. – Squashman Jan 06 '20 at 00:15
  • Appreciate both your inputs! I indeed did leave a dash in one of the lines, like a dummy. The IPS were just a random number at the end so I changed for the conciseness of the post. And "%URL%"=="" did the job! Thanks a lot! – Spencer Ritter Jan 06 '20 at 00:21
  • `::` doesn't work inside code blocks and within `setlocal ENABLEDELAYEDEXPANSION`. You must use `rem` instead [How to “comment-out” (add comment) in a batch/cmd?](https://stackoverflow.com/a/16839602/995714) – phuclv Jan 06 '20 at 01:32
  • 1
    I would probably move the `GoTo :EOF` following the ASCII art to just before it. If the art has to waste screen real estate, it doesn't need to be parsed during line reads, _(as it's only used with `FindStr` within the called for loop)_. – Compo Jan 06 '20 at 02:34
  • 1
    @phuclv, `::` should not fail with delayed expansion enabled, the delayed expansion state does not at all affect the illegal-label-style comments... – aschipfl Jan 06 '20 at 18:30

0 Answers0