Skip to content

Instantly share code, notes, and snippets.

@wincmd64
Last active January 20, 2023 08:29
Embed
What would you like to do?
:: Скачивает видео из Интернета в папку "Загрузки" по ссылке из буфере обмена
:: Для правильной работы, поместить "yt-dlp.exe" и "ffmpeg.exe" рядом с .bat или в path
:: yt-dlp.exe -- https://github.com/yt-dlp/yt-dlp/releases
:: ffmpeg.exe -- https://gyan.dev/ffmpeg/builds
:: https://t.me/wincmd64
@echo off
:: находим папку Загрузки
FOR /F "USEBACKQ TOKENS=2,*" %%a IN (
`REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /V {374DE290-123F-4565-9164-39C4925E467B}`
) DO (
SET DOWNLOADS=%%b
)
:: берем значение из буфера обмена
for /f "delims=" %%i in ('mshta "javascript:var x=clipboardData.getData('text');if(x) new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(x);close();"') do set url=%%i
yt-dlp.exe -F -S vext "%url%"
if ERRORLEVEL 1 (goto ERROR) else (goto OK)
:ERROR
echo.
:: если url из буфера не считан - вводим руками
Set /p url="Enter the url: "
yt-dlp.exe -F -S vext "%url%"
if ERRORLEVEL 1 (goto ERROR)
:OK
echo.
set "num="
set /p num="Enter videoID+audioID (for example 137+140) or leave empty for bestvideo+bestaudio: "
echo.
if not defined num (
:: если явно не указали id, то качаем в лучшем качестве
yt-dlp.exe -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best" "%url%" -P %DOWNLOADS% -o "%%(title).50s.%%(ext)s" --no-part
if ERRORLEVEL 1 (goto OK)
) else (
yt-dlp.exe -f %num% "%url%" -P %DOWNLOADS% -o "%%(title).50s.%%(ext)s")
if ERRORLEVEL 1 (goto OK)
echo.
echo Downloaded in %DOWNLOADS%.
color 27
explorer %DOWNLOADS%
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment