-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYouTube-dlp Download + Embed.bat
104 lines (56 loc) · 3.42 KB
/
YouTube-dlp Download + Embed.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
@echo off
:: CD to current file
cd /D "%~dp0"
::Sets cmd to save and recognize Unicode 8 text files (For the thumbnail name). > nul hides activation.
chcp 65001 > nul
del Thumbnails.txt, Channel.txt, Title.txt >nul 2>&1
:start
set /p "url=Enter YouTube video URL: "
yt-dlp.exe %url% --list-formats
goto download
::-------------------------------------------------------------------------------------------
:download
set /p "download=Formats to download: "
yt-dlp.exe %url% -f %download% --embed-metadata --replace-in-metadata "title" "[:<>/\?*]" "" --replace-in-metadata "title" "[|]" "-" -o "Downloads/%%(uploader)s/%%(title)s-temp.%%(ext)s" --embed-subs --sub-lang en --merge-output-format mkv --print-to-file "%%(title)s" Title.txt --encoding utf8 --print-to-file "%%(uploader)s" Channel.txt --encoding utf8
set /p Title=<Title.txt
set /p Channel=<Channel.txt
goto Thumbnail
::-------------------------------------------------------------------------------------------
:Thumbnail
::Writes list of thumbnails to temp.txt instead of displaying them. Then used type to print contents of text file. This is done to temporarily store thumbnail urls in the text file.
yt-dlp.exe %url% --list-thumbnails > Thumbnails.txt
type Thumbnails.txt
:: Asks the user to select url by index number and searches for that line in text file. Then finds the string and extracts only the url and stores it in %ThumbnailURL%.
set /p index="Select Thumbnail: "
for /f "tokens=1-4" %%a in ('findstr /b /c:"%index% " Thumbnails.txt') do set ThumbnailURL=%%d
:: Extracts file extension from url
for %%a in (%ThumbnailURL%) do set ThumbnailExtension=%%~xa
::Combines title + thumbnail extension and stores it in %Filename% | Disabled
::set Filename=%Title%%ThumbnailExtension%
::-------------------------------------------------------------------------------------------
:Download Thumbnail
::Downloads image, stores it in Downloads\Channel\Filename.extension, prints message in cmd, and deletes temp.txt. echo. creates blank lines in cmd.
echo.
cURL %ThumbnailURL% --output "Downloads\%Channel%\temp%ThumbnailExtension%"
rename "Downloads\%Channel%\temp%ThumbnailExtension%" "%Title%%ThumbnailExtension%"
echo.
echo Saved Thumbnail to "Downloads\%Channel%\%Title%%ThumbnailExtension%"
::-------------------------------------------------------------------------------------------
:Embed Thumbnail
if "%ThumbnailExtension%" == ".webp" (
rename "Downloads\%Channel%\%Title%-temp.mkv" "%Title%.mkv"
goto :End
)
if "%ThumbnailExtension%" == ".jpg" (set "mimetype=image/jpeg")
if "%ThumbnailExtension%" == ".jpeg" (set "mimetype=image/jpeg")
if "%ThumbnailExtension%" == ".png" (set "mimetype=image/png")
if "%ThumbnailExtension%" == ".webp" (set "mimetype=image/webp")
ffmpeg -i "Downloads\%Channel%\%Title%-temp.mkv" -map 0 -c copy -attach "Downloads\%Channel%\%Title%%ThumbnailExtension%" -metadata:s:t mimetype=%mimetype% -metadata:s:t:0 filename="cover%ThumbnailExtension%" "Downloads\%Channel%\%Title%.mkv" >nul 2>&1
::-------------------------------------------------------------------------------------------
:End
echo Embedded Thumbnail in "Downloads\%Channel%\%Title%.mkv"
del Thumbnails.txt, Channel.txt, Title.txt, "Downloads\%Channel%\%Title%-temp.mkv" >nul 2>&1
::Goes back to start to enter a new video url
goto start
:: Stop .bat from exiting
cmd /k