Rank: Member
Groups: Approved
Joined: 3/31/2024(UTC) Posts: 14
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
V2
The directory should contain yt-dlp.exe and ffmpeg.exe Don't forget to change the path to your own. Code:
(function() {
const ytdlpPath = 'c:\\test\\test\\';
const ytdlpFileName = 'yt-dlp.exe';
const ffmpegFileName = 'ffmpeg.exe';
const originalDirectory = System.Environment.CurrentDirectory;
const originalClipboard = clip.GetText();
const keepCmdOpen = false; // Set to true to keep the CMD open, or false to close it
// Function to check if a file exists
function checkFile(filePath, fileName) {
return System.IO.File.Exists(`${filePath}\\${fileName}`)
|| !!(sp.MessageBox(`File ${fileName} not found in the directory: ${filePath}`, "Error") && false);
}
// Check if both files exist
if (!checkFile(ytdlpPath, ytdlpFileName) || !checkFile(ytdlpPath, ffmpegFileName)) {
return; // Stop script execution if at least one file is not found
}
try {
System.Environment.CurrentDirectory = ytdlpPath;
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]);
sp.Sleep(100);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
const cmdParameter = keepCmdOpen ? '/k' : '/c';
sp.RunProgram(
'cmd.exe',
`${cmdParameter} menu.bat "${ytdlpPath}" "${clip.GetText()}" "${ytdlpFileName}" ${keepCmdOpen}`,
'',
'',
true,
false,
false
);
} catch (error) {
sp.MessageBox("Failed to execute command. Error: " + error.message, "Error");
} finally {
System.Environment.CurrentDirectory = originalDirectory;
if (originalClipboard !== undefined && originalClipboard !== null) {
clip.SetText(originalClipboard);
}
}
})();
Create a file with this name and insert the code below. menu.bat It will look like this (for example): 1. Download video (MP4) 2. Download video (MP4 without archive) 3. Download audio (MP3) 4. Download audio (MP3 without archive) Code:
@echo off
REM Get the parameters
set ytdlpPath=%~1
set url=%~2
set ytdlpFileName=%~3
set keepCmdOpen=%~4
REM Change to the specified directory
cd /d "%ytdlpPath%"
:start
cls
echo Select download format:
echo 1. Download video (MP4)
echo 2. Download video (MP4 without archive)
echo 3. Download audio (MP3)
echo 4. Download audio (MP3 without archive)
echo 5. Exit
choice /c 12345 /n /m "Enter your choice: "
if errorlevel 5 goto exit
if errorlevel 4 goto download_audio2
if errorlevel 3 goto download_audio
if errorlevel 2 goto download_video2
if errorlevel 1 goto download_video
:download_video
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
"%ytdlpFileName%" -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -ci --download-archive archive.txt -f bestvideo[ext=mp4]+140 "%url%"
)
goto finish
:download_video2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
"%ytdlpFileName%" -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -f bestvideo[ext=mp4]+140 "%url%"
)
goto finish
:download_audio
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
"%ytdlpFileName%" -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -ci --download-archive archive.txt --extract-audio --audio-format "mp3" --audio-quality 0 "%url%"
)
goto finish
:download_audio2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
"%ytdlpFileName%" -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" --extract-audio --audio-format "mp3" --audio-quality 0 "%url%"
)
goto finish
:finish
echo Download completed.
if "%keepCmdOpen%"=="true" (
echo Press any key to return to the main menu...
pause >nul
goto start
)
goto exit
:exit
exit
V1
The directory should contain yt-dlp.exe and ffmpeg.exe Don't forget to change the path to your own. extracting MP3 from video
Code:
(function() {
const ytdlpPath = 'c:\\test\\test\\';
const ytdlpFileName = 'yt-dlp.exe';
const ffmpegFileName = 'ffmpeg.exe';
const originalDirectory = System.Environment.CurrentDirectory;
const originalClipboard = clip.GetText();
// Function to check if a file exists
function checkFile(filePath, fileName) {
return System.IO.File.Exists(`${filePath}\\${fileName}`)
|| !!(sp.MessageBox(`File ${fileName} not found in the directory: ${filePath}`, "Error") && false);
}
// Check if both files exist
if (!checkFile(ytdlpPath, ytdlpFileName) || !checkFile(ytdlpPath, ffmpegFileName)) {
return; // Stop script execution if at least one file is not found
}
try {
System.Environment.CurrentDirectory = ytdlpPath;
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]);
sp.Sleep(100);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.RunProgram(
'cmd.exe',
// /k to keep cmd open, /c to close it after execution
'/c ' + ytdlpFileName + ' ' + String.raw`-o "%(playlist_title)s-%(title)s-%(id)s.%(ext)s" --extract-audio --audio-format "mp3" --audio-quality 0 "${clip.GetText()}"`,
'',
'', //hidden if you want it to run hidden, or //minimized
true,
false,
false
);
} catch (error) {
sp.MessageBox("Failed to execute command. Error: " + error.message, "Error");
} finally {
System.Environment.CurrentDirectory = originalDirectory;
clip.SetText(originalClipboard); // Restore original clipboard content
}
})();
+menu.bat It will look like this (for example): 1. Download video (MP4) 2. Download video (MP4 without archive) 3. Download audio (MP3) 4. Download audio (MP3 without archive) Modify the code section to sp.RunProgram( 'cmd.exe', '/k ' + 'menu.bat ' + '"' + ytdlpPath + '" ' + '"' + clip.GetText() + '"', '', '', true, false, false ); Create a menu.bat file in the same directory.
Code:
@echo off
REM Get the path from the first argument
set ytdlpPath=%~1
REM Change to the specified directory
cd /d "%ytdlpPath%"
:start
cls
echo Select download format:
echo 1. Download video (MP4)
echo 2. Download video (MP4 without archive)
echo 3. Download audio (MP3)
echo 4. Download audio (MP3 without archive)
echo 5. Exit
choice /c 12345 /n /m "Enter your choice: "
if errorlevel 5 goto exit
if errorlevel 4 goto download_audio2
if errorlevel 3 goto download_audio
if errorlevel 2 goto download_video2
if errorlevel 1 goto download_video
:download_video
set url=%~2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
yt-dlp -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -ci --download-archive archive.txt -f bestvideo[ext=mp4]+140 "%url%"
)
goto exit
:download_video2
set url=%~2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
yt-dlp -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -f bestvideo[ext=mp4]+140 "%url%"
)
goto exit
:download_audio
set url=%~2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
yt-dlp -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" -ci --download-archive archive.txt --extract-audio --audio-format "mp3" --audio-quality 0 "%url%"
)
goto exit
:download_audio2
set url=%~2
if "%url%"=="" (
set /p "url=Enter YouTube video URL: " || set "url="
)
if defined url (
yt-dlp -o "%%(playlist_title)s-%%(title)s-%%(id)s.%%(ext)s" --extract-audio --audio-format "mp3" --audio-quality 0 "%url%"
)
goto exit
:exit
exit
Edited by user Friday, August 9, 2024 1:13:36 PM(UTC)
| Reason: v2
|