接受已复制到剪贴板的 URL 的 MS-DOS 的 YT-DLP 批处理文件是什么样的?

接受已复制到剪贴板的 URL 的 MS-DOS 的 YT-DLP 批处理文件是什么样的?

请查看下面的批处理文件。

目标

...是在批处理文件中运行 yt-dlp,然后它会给你一个包含六个选项的菜单:

  • yt-dlp “%temp_file%”
  • yt-dlp -f 最佳“%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%"

我想到的方法是使用一个变量,我称之为temp_file,它将填充剪贴板的内容,这是一个 youtube 视频的 URL,它将通过命令行传递(通过管道传递?)给 yt-dlp 程序。但遗憾的是它不起作用。问题可能出在步骤 B 中。 将剪贴板的内容复制到临时文件。这根本不会发生。

我尝试执行步骤B:

  • 使用 Powershell Command-let获取剪贴板
  • CLIP.EXE 应用程序
  • 创建临时文件

但这些不起作用,或者,我做错了什么。错误消息是: "The syntax of the command is incorrect."

问题:

您能告诉我下面的批处理文件哪里出错并产生此错误消息吗?以及如何修复它以便它接受剪贴板的内容并将其内容传输到...钇离子

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```

答案1

我想我找到了。当您将 URL 复制到剪贴板时,下载 YouTube 视频的 MS-DOS 批处理文件如下所示:

@echo off
setlocal EnableDelayedExpansion
echo  setlocal EnableDelayedExpansion
pause

:: B. Copy the contents of the clipboard to the temporary file
FOR /F "usebackq delims=" %%i IN (`powershell -command "Get-Clipboard"`) DO SET temp_file=%%i
 

echo %temp_file% 
pause

:: C. 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)

:: D. Get user input
set /p choice=Enter your choice:

:: E. 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.
)

:: F. Pause the script so that you can see the output
pause

:: G. Delete the temporary file
:: del "%temp_file%"

:: H.Exit the script
exit /B

我希望每个读到这篇文章的人都能在自己的系统和操作系统上测试它。它的优点很明显,它是一种无病毒的下载大量 Youtube 视频的方法,无需输入大量内容或粘贴任何内容。

这为您提供了六个选项,供您下载 Youtube 时选择雅拓DLP

任何人都可以根据自己的喜好扩展菜单。

我将批处理文件固定到任务栏,以便它始终可用。

这个批处理文件应该再做一些调整,从步骤 G 开始,是否应该保持阻塞状态?我不确定这是否必要,因为批处理文件确实有效。

我只是不想下载一些我不知道是否有病毒的 GUI。

相关内容