Please view the batch file below.
The goal
... is to run yt-dlp in a batch file, which then gives you a menu with six options:
- yt-dlp "%temp_file%"
- yt-dlp -f best "%temp_file%"
- yt-dlp --write-sub "%temp_file%"
- yt-dlp --sub-lang en "%temp_file%"
- yt-dlp -cit "%temp_file%"
- yt-dlp -x --audio-format mp3 "%temp_file%"
The method I came up with was to use a variable, which I called temp_file
, which would be filled with the contents of the clipboard, this is the URL of a youtube video, which would be passed on, (piped to?), the yt-dlp program on the command-line. But it regrettably doesn't work. The problem might be in step B.
Copy the contents of the clipboard to the temporary file. This doesn't happen, at all.
What I tried to do step B:
- using Powershell Command-let Get-clipboard
- the CLIP.EXE application
- creating a temp file
But these don't work, or, I've done something wrong. The error message is:
"The syntax of the command is incorrect."
Question:
Can you tell me where the batch file below goes wrong and produces this error message? And how to fix it so that it accepts the contents of the clip board and pipes the content of that ... to Yt-Dlp?
set "temp_file=%TEMP%\%RANDOM%"
EDIT
:: B. Copy the contents of the clipboard to the temporary file
powershell -command "Add-Type -AssemblyName PresentationCore; [Windows.Clipboard]::GetText() | Out-File -FilePath 'temp_file.txt'"
:: clip < NUL > "%temp_file%"
:: I left this in by accident, sorry about that. This only puts things
:: **on** the clipboard, while I thought this would get things *out* of
:: the clipboard. Which doesn't seem so unreasonable?
:: Display the menu
echo Please select an option:
echo 1. Download with yt-dlp
echo 2. Download with yt-dlp (best quality)
echo 3. Download with yt-dlp (with subtitles)
echo 4. Download with yt-dlp (with English subtitles)
echo 5. Download with yt-dlp (with captions)
echo 6. Download with yt-dlp (audio only)
:: Get user input
set /p choice=Enter your choice:
:: Process the user's choice
if "%choice%"=="1" (
yt-dlp "%temp_file%"
) else if "%choice%"=="2" (
yt-dlp -f best "%temp_file%"
) else if "%choice%"=="3" (
yt-dlp --write-sub "%temp_file%"
) else if "%choice%"=="4" (
yt-dlp --sub-lang en "%temp_file%"
) else if "%choice%"=="5" (
yt-dlp -cit "%temp_file%"
) else if "%choice%"=="6" (
yt-dlp -x --audio-format mp3 "%temp_file%"
) else (
echo Invalid choice. Please try again.
)
:: Pause the script so that you can see the output
pause
:: Delete the temporary file
del "%temp_file%"
:: Exit the script
exit /B```
clip
command appears to be to put text on the clipboard rather than copying data from it. Where did you get the syntax for it? If I runclip /?
then the only description isRedirects output of command line tools to the Windows clipboard.
notRedirect clipboard to command line
powershell get-clipboard > 1.txt
see How to Access the System Clipboard (Copy/Paste) from the Command Line | by Zack | Level Up CodingThe system cannot find the path specified.
\Please select an option:
\1. Download with yt-dlp
\2. 3. 4. 5.
\.
\6. Download with yt-dlp (audio)
\Enter your choice:1
\[generic] Extracting URL:
\ERROR: [generic] '' is not a valid URL. Set --default-search "ytsearch" (or run yt-dlp "ytsearch:" ) to search YouTube
\Press any key to continue...
\C:\Programs\*, Are you sure (Y/N)? n
\