Youtube-dl OUTPUT TEMPLATE %(title)s.%(ext)s is not working with set /p in windows - youtube

I used the batch file with commands :-
set /p ytlink="Enter the link of Youtube Video:- "
youtube-dl -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "D:\Videos\%(title)s.%(ext)s" %ytlink%
pause
but the output file name is (ext)s.webm ,it seems cmd is treating %(title)s.% in -o "D:\Videos\%(title)s.%(ext)s" as variable.So how to get video title?
OS=Windows 10 64bit 1909
youtube-dl=2020.01.24

You have to use double % in a batch file.
set /p ytlink="Enter the link of Youtube Video:- "
youtube-dl -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "D:\Videos\%%(title)s.%%(ext)s" %ytlink%
pause

Maybe someone will need it. Based on 1957classic answer. Download video and audio in the best quality to your desktop with the original name with the url taken from the clipboard.
setlocal enabledelayedexpansion
for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
set getclip=powershell "Add-Type -AssemblyName System.Windows.Forms;$tb=New-Object System.Windows.Forms.TextBox;$tb.Multiline=$true;$tb.Paste();$tb.Text"
)
for /f "delims=" %%I in ('%getclip% ^| findstr /n "^"') do (
set "line=%%I" & set "line=!line:*:=!"
)
set "psCommand="[Environment]::GetFolderPath('DesktopDirectory')""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "Desktop=%%I"
%~d0"%~p0"youtube-dl.exe -f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" -o "!Desktop!\%%(title)s.%%(ext)s" !line!

Related

How to print multiple PDF files in different folders?

An example would be:
 Folder 1:
  a.pdf
  b.pdf
   Folder11
   c.pdf
  Folder 2:
  a.pdf
  b.pdf
   Folder21:
   c.pdf
printing all files between folders
And the cmd would have a way to find the file only putting part of the words?
Example
TEXT : ABC*.PDF
PRINT ABCDF.PDF
1. To loop over multiple files recursively:
FOR /f "tokens=*" %%F in ('dir /s /b *.pdf') DO echo "%%F"
dir /s /b *.pfd finds all pdfs (*.pdf), in all subdirectories (/s), in bare format - ie just the path name (/b)
DO echo "%%F" just echo's the result to the console.
"tokens=*" adds the whole line into %%F regardless of white spaces / other tokens
/F makes it run the ('dir ...') command
2. To print from command line use: From this question
AcroRd32.exe /t "C:\Folder\File.pdf" "Brother MFC-7820N USB Printer" "Brother MFC-7820N USB Printer" "IP_192.168.10.110"
Note: Path to AcroRd32.exe must be in your path environment variable
3. Putting it all together -- edit -- 'I've added taskkill to close acrord32 after printing
FOR /f "tokens=*" %%F in ('dir /s /b *.pdf') DO AcroRd32.exe /t "%%~F" "Brother MFC-7820N USB Printer" "Brother MFC-7820N USB Printer" "IP_192.168.10.110" & taskkill /IM AcroRd32.exe

Parsing contents of file in CMD/Batch not working?

I have a simple text file with some numbers in it:
1122
2244
But when I run the CMD
FOR /F %i IN (CIFLIST.TXT) DO ECHO %i
Nothing is output to the screen?
I've also tried from a batch file as
FOR /F %%i IN (CIFLIST.TXT) DO ECHO %%i
But again, no output? Any ideas?
[I've been through How do you loop through each line in a text file using a windows batch file? but can't find anything obvious)
try this:
FOR /F "delims=" %%i IN ('type CIFLIST.TXT') DO ECHO %%i
FOR /F "delims=" %%i IN ('cmd /A /C type CIFLIST.TXT') DO ECHO %%i

parse batch line by line

i am trying to parse the output of another function which is output line by line. to understand the function, it returns several lines of parameter and numbers like "top=123456789" or "low=123456789" (without the quotations) -
i try to parse the lines now with
for /F "delims=" %%a in ('%%I ^| findstr top') do set updir=%%1
set "updir=%1:~4%"
echo. %updir%
i am trying to get the pure numbers by trimming the known keywords like top, which would need then to be set to a var to return (%~1% ???) to a calling function back (other batch file).
could anyone help me with this please? shure it would be better to trim right from "=".
UPDATE:
this is the code returning the lines from the script i linked. i tried several ways to parse the return but i seem to be blind or too stupid to see, all is going weird.
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
rem process the HTML line-by-line
org echo(%%I
try1 (echo %%I|findstr top
try2 for /F "delims=" %%a in ('%%I ^| findstr top') do set updir=%%a
try2 echo. %updir%
try3 for /F "delims=" %%a in ('%%I') do findstr top
try3 echo. %2%
)
didn't work either
for /F "tokens=1,2delims==" %%a in ('%%I') do if %1 == top set updir=%%b
echo %updir%
i tried both delim version beneath (too the tokens/delims version) but i don't get it right.
UPDATE SOLUTION:
for the ones reading the question here some additional comment:
rem trim whitespace from beginning and end of line
for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"
rem test that trimmed line matches "variable=number"
to find a single item like e.g. "top" you have to add "to" or adjust whole first token
echo !line! | findstr /i "^to[a-z]=[0-9]" >NUL && (
rem test was successful. Scrape number.
for /f "tokens=2 delims==" %%x in ("%%I") do set "value=%%x"
echo !value!
)
If all you wish to do is to is to skip all lines until you find one that matches "text=numerals", then scrape the numeric portion of that line, all you need to do is this:
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
rem trim whitespace from beginning and end of line
for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"
rem test that trimmed line matches "variable=number"
echo !line! | findstr /i "^[a-z]*=[0-9]*$" >NUL && (
rem test was successful. Scrape number.
for /f "tokens=2 delims==" %%x in ("%%I") do set "value=%%x"
)
)
I think that's right, anyway. I didn't test it.
But I suspect that this is not going to work as you intend, since what you are scraping will probably include HTML tags. We will probably not be able to help you scrape the HTML unless you pastebin the HTML source of an example page, and explain what you wish to scrape from that source example.
does this fit your needs?
for /F "delims=" %%a in ('type file.txt ^| findstr "top low"') do set /a %%a
set top
set low
echo %top%, %low%
Try this:
for /F "tokens=2delims==" %%a in ('findstr top file.txt') do set "updir=%%a"
echo.%updir%
According to your comment my new code:
#echo off &setlocal enabledelayedexpansion
set "string=%%I"
set "string=!string:*top=!"
for /f "delims== " %%z in ("!string!") do set "string=%%z"
echo !string!
.. output:
123456789
Edit2: "added.

Noobs approach to automate x264 cmd

so here is my script to loop through specific video extensions » add a manual profile » generate necessary *.bat & finally a final 'loader' batch file to execute previous *.bat files sequentially & necessary logging (this gives quiet a deal of freedom if you so want)
::==
:: gets lines into vars c1 v2 v...
#echo off
:: user input required
cd /d "d:\Trainers\out\"
setLocal EnableDelayedExpansion
dir /B /O:N | findstr ".wmv$ " >filename.txt
echo. >log.txt
:: user input required
for /f "tokens=* delims= " %%a in ('type filename.txt ^|findstr ".wmv$"') do (
set /a n+=1
echo. >file!n!.bat
set in=%in%%%a
:: user input required
set out=!in:.wmv=.mp4!
:: user input required
set v=x264 --crf 23 --level 3.1 --tune film -o "d:\Trainers\out\!in!" "d:\Trainers\out\!out!"
echo. !v!>file!n!.bat
)
dir /B /O:N | findstr ".bat$ " >x264_home.txt
for /f "tokens=* delims= " %%a in (x264_home.txt) do (
set /a n+=1
:: mtee is an external library Google it
set "z=call %%a | mtee /d/c/t/+ log.txt"
echo. !z! >> x264_home.bat
)
echo. #echo off > newFile.bat
type x264_home.bat >> newFile.bat
type newFile.bat > x264_home.bat
del newFile.bat,x264_home.txt,filename.txt
echo. pause >> x264_home.bat
echo. #echo All Operation done... >> x264_home.bat
:: user input required
move "d:\Trainers\out\*.bat" "d:\Program Files\x264_auto\test\"
:: user input required
move "d:\Trainers\out\log.txt" "d:\Program Files\x264_auto\test\"
::==
Now the above code which is fairly easy to understand (bcz its written by a noob) run perfectly & create necessary files. For instance one of the file1.bat looks like this:
x264 --crf 23 --level 3.1 --tune film --preset veryslow --deblock -2:-1 --zones 24233,25324,q=20 --acodec aac --abitrate 80 -o "d:\Trainers\out\1.wmv" "d:\Trainers\out\1.mp4"
...& the loader .bat file looks like
#echo off
call file1.bat | mtee /d/c/t/+ log.txt
call file2.bat | mtee /d/c/t/+ log.txt
call file3.bat | mtee /d/c/t/+ log.txt
#echo All Operation done...
You see this is a quiet flexible approach in that you can use special filestr » set another loop » set another profile. Furthermore every batch file can be latter edited especiialy when you heavily use --zone x264 feature
I am successful because there is no error in any output ...but its the x264.exe (provider/compiler x264GUI) throws error which it otherwise don't?
d:\Program Files\x264_auto\test>x264 --crf 23 --level 3.1 --tune film --preset
veryslow --deblock -2:-1 --zones 24233,25324,q=20 --acodec aac --abitrate 80 -o
"d:\Trainers\out\1.wmv" "d:\Trainers\out\1.mp4"
ffms [error]: could not create index
lavf [error]: could not open input file
raw [error]: raw input requires a resolution.
x264 [error]: could not open input file `d:\Trainers\out\1.mp4' via any method!
its the x264 thats the culprit perhaps a senior guide is required here
Is your x264 compiled with mp4 input support? (I believe that needs lavc/lavformat, just download precompiled x264 from x264.nl which has all extras)
Do you get the same error if you run the same command directly? (not through bat files)
If yes, does it only happen when you use zones? (if it does, then post an example of your command line as x264 bug to x264-devel mailing list)
If no, are you sure you are running the exact same x264? (perhaps there are several in different places on your system)
I recommend doing what you're doing either (a) in python with subprocess.call(...) or (b) in cygwin/bash/shell script, or . bat files are pretty much the wrong answer to any problem :) The nice thing about either of those two is that they have simple, regular escaping rules for program arguments.

How to check the existence of a Windows service in a batch file

How can I check the existence of a Windows service in a batch file?
The user is inputting a service name, and I want to check that the service does exist before continuing with my script.
Try this:
>NET START | FIND "Workstation"
where "Workstation" is the name of the service
#echo off
color 1F
SET KEYS=HKLM\SYSTEM\CurrentControlSet\services\ACPI
for /f "tokens=3" %%i in ('REG QUERY "%KEYS%" ^| find "Start"') do set START=%%i
IF "%START%" == "%START%" ECHO %START% | find /I "%START%" && IF "%START%" NEQ "0x3" REG ADD %KEYS% /v "Start" /t REG_DWORD /d 3 /f >> %COMPUTERNAME%_MODIFIER.TXT
IF ERRORLEVEL 1 ECHO %KEYS% >> %COMPUTERNAME%_SERVICE_MISSING.TXT
OR
#echo off
color 1F
#sc query >%COMPUTERNAME%_START.TXT
ECHO REPORT MISSING INSTALL SERVICES >%COMPUTERNAME%.TXT
find /I "AcPrfMgrSvc" %COMPUTERNAME%_START.TXT >nul
IF ERRORLEVEL 1 NET START "AcPrfMgrSvc"
IF ERRORLEVEL 1 ECHO AcPrfMgrSvc >>%COMPUTERNAME%.TXT

Resources