-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnas Youtube Downloader V2.3.1.bat
361 lines (338 loc) · 11.9 KB
/
Annas Youtube Downloader V2.3.1.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@Echo off
:Begin
setlocal EnableDelayedExpansion
if not %ERRORLEVEL%==0 (
cecho {0C}SOMETHING WENT WRONG...{#}
CALL :LOG "Initializing error."
goto :ERROR
)
set "basePath=%~dp0"
set "logFile=%basePath%/Anna-YTD Log.txt"
if exist "%logFile%" (
for %%F in ("%logFile%") do set fileSize=%%~zF
if !fileSize! GTR 20971520 (
del "%logFile%"
CALL :LOG "The log file was larger than 20MB and has been deleted."
echo The log file was larger than 20MB and has been deleted.
)
)
if not exist "%logFile%" (
echo Log file created on %DATE% at %TIME% > "%logFile%"
)
CALL :LOG "Script started on %DATE% at %TIME%"
set "playlist=0"
set "test_link=!link!"
:back1
echo Please enter a file name. Do NOT use any spaces or forbidden characters like greater than/less than, : \ " / \ \ | ? or *:
set "name="
set "webm="
set /P "name=>" || goto linkER
set "name=%name:"=%"
if not defined name goto linkER
if not "%name%"=="%name: =%" goto linkER
for %%G in ("%name%") do if /I not "%%~xG" == ".webm" if "%%~xG" == "" (set "webm=%name%.mp4") else goto linkER
goto back2
:linkER
cecho {0C}INVALID ENTRY {#}
CALL :LOG "Invalid entry linkER."
goto back1
:back2
echo Please paste the YouTube link:
set /P "link=>" || goto Invalid
set "link=%link:"=%"
if not defined link goto Invalid
if not "%link:list=%" == "%link%" goto Playlist
if "%link:youtube=%" == "%link%" goto Youtube
goto start_time
:Invalid
cecho {0C}INVALID ENTRY {#}
CALL :LOG "Invalid entry %link%"
goto back2
:Youtube
cecho {0C}INVALID ENTRY: Must contain "Youtube" {#}
CALL :LOG "Invalid: not Youtube link."
goto back2
:Playlist
if %playlist%==0 (
cecho {0C}INVALID ENTRY: Must not use a link from a playlist {#}
echo.
echo Please use the "share" feature to download the 1 video. Otherwise, it will download the whole playlist.
cecho {0A}Paste the same link again to download the WHOLE playlist. {#}
echo.
cecho {0C}ERROR playlist downloads are not currently supported. {#}
echo Proceed if you wish, but only the very first video will be downloaded. All other videos, including the one you selected, will not be downloaded.
echo .
timeout 5
start %basePath%\ShareImageExample.png
set /a "playlist=%playlist%+1"
goto back2
) else (
if %playlist%==1 (
cecho {0A}Downloading whole playlist. {#}
echo.
echo If this was an error, please restart the program.
cecho {0C}ERROR playlist downloads are not currently supported. {#}
echo Proceed if you wish, but only the very first video will be downloaded. All other videos, including the one you selected, will not be downloaded.
set /p DUMMY=Hit ENTER to continue.
if "%link:youtube=%" == "%link%" goto Youtube
goto start_time
) else (
CALL :LOG "Error occured at playlist downloader"
cls
cecho {0C}An error has occurred... restarting batch {#}
goto Begin
)
)
:start_time
echo Please enter start time (0 for unchanged) (30 = 30 seconds, 120 = 2 minutes etc)
set /p "start_time=>"
echo %start_time%|findstr /r "^[0-9]*\.*[0-9]*$" >nul && (
goto end_time
) || (
echo %start_time% is NOT a valid number
goto start_time
)
goto end_time
:end_time
echo Please enter the video length (0 for unchanged) (30 = 30 seconds, 120 = 2 minutes etc)
set/p "end_time=>"
echo %end_time%|findstr /r "^[0-9]*\.*[0-9]*$" >nul && (
goto back3
) || (
echo %end_time% is NOT a valid number
goto end_time
)
goto back3
:back3
echo Please enter the output file type (example: ".mp3"):
echo Currently supported types: .mp3 ~ .webm ~ .mp4 ~ .wma ~ .wav ~ .gif ~ .mov
echo If you wish to conver to another file type, please contact Anna-Rose.
set /p "output_type=>"
set "output=%name%%output_type%"
if %output_type%==.gif goto back3_gif
echo Please ensure this is correct:
echo Name = %name%
echo Output = %output%
echo Link = %link%
echo Cut Start = %start_time% seconds
echo Clip length= %end_time% seconds
echo -------------------------------------------
set /p DUMMY=Hit ENTER to continue. If the above is not right, close and re-open this file.
CALL :LOG "User confirmed details: Name=%name%, Output=%output%, Link=%link%, Start=%start_time%, Length=%end_time%"
if %output_type%==.mp3 goto MP3
if %output_type%==.webm goto WEBM
if %output_type%==.mp4 goto mp4
if %output_type%==.wma goto WMA
if %output_type%==.wav goto WAV
if %output_type%==.gif goto GIF
if %output_type%==.mov goto MOV
cecho {0C}ERROR: Unknown File Type{#}
CALL :LOG "Unknown file type entered."
echo.
goto back3
:back3_gif
echo Since GIF files can get large quickly, please select an fps you would like. Enter '0' if you want to leave it unchanged
set /p "FPS=>"
echo %FPS%|findstr /r "^[0-9]*\.*[0-9]*$" >nul && (
echo Please ensure this is correct:
echo Name = %name%
echo Output = %output%
echo Link = %link%
echo Frames = %FPS% fps
echo Cut Start = %start_time% seconds
echo Clip length= %end_time% seconds
echo -------------------------------------------
set /p DUMMY=Hit ENTER to continue. If the above is not right, close and re-open this file.
goto GIF
CALL :LOG "User confirmed details: Name=%name%, Output=%output%, Link=%link%, FPS=%FPS% fps, Start=%start_time%, Length=%end_time%"
) || (
echo %FPS% is NOT a valid number
goto back3_gif
)
:MP3
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (ffmpeg -ss %start_time% -i %webm% -y -vn -acodec copy -c:a libmp3lame %output%
) else (
ffmpeg -ss %start_time% -t %end_time% -i %webm% -y -vn -acodec copy -c:a libmp3lame %output%
)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:mp4
set "output=1%webm%"
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (
if %start_time%==0 (
goto END_WEBM)
else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -n %output%)
else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -n %output%)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:WEBM
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:a libopus -c:v vp9 %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:a libopus -c:v vp9 -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:a libopus -c:v vp9 -n %output%)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:WMA
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:a wmav2 -vn %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:a wmav2 -vn -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:a wmav2 -vn -n %output%)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:WAV
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:a pcm_s24le -vn %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:a pcm_s24le -vn -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:a pcm_s24le -vn -n %output%)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:GIF
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %FPS%==0 (
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:v gif -an %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:v gif -an -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:v gif -an -n %output%)
) else (
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:v gif -an -fpsmax %FPS% %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:v gif -an -fpsmax %FPS% -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:v gif -an -fpsmax %FPS% -n %output%))
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "Complex ffmpeg (gif) encountered an error."
goto :ERROR
)
goto END_S
:MOV
yt-dlp "%link%" -o %webm%
if not %ERRORLEVEL%==0 (
cecho {0C}yt-dlp encountered an error.{#}
CALL :LOG "yt-dlp encountered an error."
goto :ERROR
)
if %end_time%==0 (
if %start_time%==0 (
ffmpeg -i %webm% -c:a aac -c:v h264 %output%
) else (ffmpeg -ss %start_time% -i %webm% -c:a aac -c:v h264 -n %output%)
) else (ffmpeg -ss %start_time% -t %end_time% -i %webm% -c:a aac -c:v h264 -n %output%)
if not %ERRORLEVEL%==0 (
cecho {0C}FFMPEG encountered an error.{#}
CALL :LOG "ffmpeg encountered an error."
goto :ERROR
)
goto END_S
:END_WEBM
if exist %USERPROFILE%\Downloads\Annas YT Downloader\ (move "%basePath%%webm%" "%USERPROFILE%\Downloads\Annas YT Downloader\%webm%") else (
cd %USERPROFILE%\Downloads
mkdir "Annas YT Downloader"
move "%basePath%%webm%" "%USERPROFILE%\Downloads\Annas YT Downloader\%webm%"
)
goto END
:END_S
del %webm%
if exist %USERPROFILE%\Downloads\Annas YT Downloader\ (move "%basePath%%output%" "%USERPROFILE%\Downloads\Annas YT Downloader\%output%") else (
cd %USERPROFILE%\Downloads
mkdir "Annas YT Downloader"
move "%basePath%%output%" "%USERPROFILE%\Downloads\Annas YT Downloader\%output%"
)
if not %ERRORLEVEL%==0 (
cecho {0C}Something went wrong at the very end but were not sure what...{#}
echo.
echo Try checking if your file is in "Downloads\Annas YT Downloader" If not, try checking %basePath%
CALL :LOG "End_s error."
goto :ERROR
)
goto END
:LOG
echo [%DATE% %TIME%] %~1 >> "%logFile%"
echo [%DATE% %TIME%] %~1
GOTO :EOF
:END
CALL :LOG "success"
echo [%DATE% %TIME%] %~1 >> "%logFile%"
echo [%DATE% %TIME%] %~1
echo ----------------------------------------------------------------------------------------------------
for /L %%i in (1, 1, 51) do (
cecho {00}--{#}
echo.
)
echo ----------------------------------------------------------------------------------------------------
cecho {0A}Success... You will find your file in "Downloads\Annas YT Downloader"!.{#}
echo.
set /p DUMMY=Press ENTER if you wish the script to repeat. If you're done, feel free to close me!
cd %basePath%
cls
goto :Begin
:ERROR
CALL :LOG "An error occurred with the last operation."
cecho {0C}An error occurred with the last operation.{#}
echo.
echo Sorry about that, something went wrong. If you want, try debugging it yourself! If you can't, contact Anna on Discord (phederal_phoenix) or in her server (https://discord.gg/FPSmSMzA4j) and send her your log stored in %basePath%%logFile%
echo Its best to make a copy of the log each time you encounter an error as each time you run this script there's a chance it will delete itself to save space.
echo.
cecho {0A}Press any button to CLOSE this session{#}
echo.
pause
:EOF
CALL :LOG "%*"