ozhegovvv

yt-dlp_menu.bat

Sep 7th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. REM Set the name of the yt-dlp executable
  5. set "yt_dlp_exe=yt-dlp.exe"
  6.  
  7. set "ytdlpPath=%~1"
  8. set "url=%~2"
  9. set "ytdlpFileName=%~3"
  10. set "choice=%~4"
  11. set "keepCmdOpen=%~5"
  12.  
  13. for /L %%i in (0,1,12) do (
  14. if %%i==0 (
  15. set "menu[%%i]=-F (List available formats)"
  16. set "option[%%i]=-F "
  17. set "output_template[%%i]="
  18. ) else if %%i==1 (
  19. set "menu[%%i]=<=1080p (MP4)"
  20. set "option[%%i]=-f bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4][height<=1080]/bv*[height<=1080]+ba/best --download-archive archive-video.txt -N 4"
  21. set "output_template[%%i]=download/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  22. ) else if %%i==2 (
  23. set "menu[%%i]=<=1080p (MP4 without archive)"
  24. set "option[%%i]=-f bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4][height<=1080]/bv*[height<=1080]+ba/best -N 4"
  25. set "output_template[%%i]=download/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  26. ) else if %%i==3 (
  27. set "menu[%%i]=bestvideo (MP4 without archive)"
  28. set "option[%%i]=-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best -N 6"
  29. set "output_template[%%i]=download/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  30. ) else if %%i==4 (
  31. set "menu[%%i]=with cookies (mp4)"
  32. set "option[%%i]=-f bestvideo[ext=mp4]/bestaudio/0 --download-archive archive-video.txt -N 4 --cookies youtube.txt"
  33. set "output_template[%%i]=download/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  34. set "menu[%%i_sep]=--"
  35. ) else if %%i==5 (
  36. set "menu[%%i]=audio (MP3)"
  37. set "option[%%i]=-f bestaudio[ext=mp3]/bestaudio/0 --extract-audio --audio-format mp3 --audio-quality 0 --download-archive archive-audio.txt -N 4"
  38. set "output_template[%%i]=download/%%(title)s-%%(id)s.%%(ext)s"
  39. ) else if %%i==6 (
  40. set "menu[%%i]=audio (MP3 without archive)"
  41. set "option[%%i]=-f bestaudio[ext=mp3]/bestaudio/0 --extract-audio --audio-format mp3 --audio-quality 0 -N 4"
  42. set "output_template[%%i]=download/%%(title)s-%%(id)s.%%(ext)s"
  43. ) else if %%i==7 (
  44. set "menu[%%i]=with cookies (mp3)"
  45. set "option[%%i]=-f bestaudio[ext=mp3]/bestaudio/0 --extract-audio --audio-format mp3 --audio-quality 0 --download-archive archive-audio.txt --cookies youtube.txt -N 4"
  46. set "output_template[%%i]=download/%%(title)s-%%(id)s.%%(ext)s"
  47. set "menu[%%i_sep]=--"
  48. ) else if %%i==8 (
  49. set "menu[%%i]=from list_video.txt (mp4)"
  50. set "option[%%i]=-f bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4][height<=1080]/bv*[height<=1080]+ba/best --download-archive archive-video.txt -N 6 -a list_video.txt"
  51. set "output_template[%%i]=download/video/%%(playlist_title)s/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  52. set "skip_url_prompt[%%i]=1"
  53. ) else if %%i==9 (
  54. set "menu[%%i]=from list_audio.txt (mp3)"
  55. set "option[%%i]=-f bestaudio[ext=mp3]/bestaudio/0 --extract-audio --audio-format mp3 --audio-quality 0 --download-archive archive-audio.txt -a list_audio.txt -N 4 "
  56. set "output_template[%%i]=download/audio/%%(playlist_title)s/%%(title)s[%%(height)sp][%%(id)s].%%(ext)s"
  57. set "skip_url_prompt[%%i]=1"
  58. rem set "menu[%%i_sep]=--"
  59. rem) else if %%i==10 (
  60. rem set "menu[%%i]=test"
  61. rem set "option[%%i]="
  62. rem set "output_template[%%i]="
  63.  
  64. )
  65. )
  66.  
  67. if not "%choice%"=="" goto execute
  68.  
  69. :start
  70. cd /d %ytdlpPath%
  71.  
  72. echo Available commands:
  73. for /L %%i in (0,1,10) do (
  74. if defined menu[%%i] (
  75. echo %%i. !menu[%%i]!
  76. )
  77. if defined menu[%%i_sep] (
  78. echo !menu[%%i_sep]!
  79. )
  80. )
  81. echo.
  82.  
  83. set /p choice=Enter the command number or custom command:
  84.  
  85. :execute
  86. if "%choice%" geq "0" if "%choice%" leq "99" (
  87. set "commands=!option[%choice%]!"
  88. set "output_template=!output_template[%choice%]!"
  89.  
  90. REM Create the files if it doesn't exist
  91. if "%choice%"=="8" (
  92. if not exist list_video.txt (
  93. echo Creating list_video.txt...
  94. echo. > list_video.txt
  95. )
  96. )
  97.  
  98. if "%choice%"=="9" (
  99. if not exist list_audio.txt (
  100. echo Creating list_audio.txt...
  101. echo. > list_audio.txt
  102. )
  103. )
  104. ) else (
  105. REM Custom command
  106. set "commands=%choice%"
  107. set "output_template="
  108. )
  109.  
  110. if not defined skip_url_prompt[%choice%] (
  111. if not defined url (
  112. set /p url=Enter the URL:
  113.  
  114. REM Check if the URL was provided
  115. if not defined url (
  116. echo No URL provided. Returning to start...
  117. pause >nul
  118. goto start
  119. )
  120. )
  121. )
  122.  
  123. REM Attempt to execute the command, and handle errors
  124. echo Executing yt-dlp command:
  125. set "full_command=%yt_dlp_exe% !commands!"
  126. if defined output_template (
  127. set "full_command=!full_command! -o "!output_template!""
  128. )
  129. if not defined skip_url_prompt[%choice%] (
  130. if defined url (
  131. set "full_command=!full_command! "!url!""
  132. )
  133. )
  134.  
  135. echo !full_command!
  136. !full_command!
  137.  
  138. if %errorlevel% neq 0 (
  139. echo.
  140. echo Command failed with error level %errorlevel%. Please check the error message above.
  141. echo.
  142. rundll32.exe user32.dll,MessageBeep 0x00000010
  143. REM msg * "Error: Command failed with error level %errorlevel%. Please check the console output for details."
  144. pause >nul
  145. goto start
  146. ) else (
  147. echo.
  148. echo Download completed successfully.
  149. echo.
  150. if /i "%keepCmdOpen%"=="true" (
  151. echo Press any key to return to the main menu...
  152. pause >nul
  153. goto start
  154. ) else (
  155. exit /b
  156. )
  157. )
Advertisement
Add Comment
Please, Sign In to add comment