-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-YoutubeDL.ps1
166 lines (131 loc) · 3.78 KB
/
Invoke-YoutubeDL.ps1
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
function Invoke-YoutubeDL {
param ([hashtable] $opts)
$argv = @()
# general options
$argv += "--ignore-errors"
# network options
$argv += "--force-ipv4"
# video selection
if ($opts.ContainsKey("playlist_start")) {
$argv += "--playlist-start", $opts.playlist_start
}
if ($opts.ContainsKey("playlist_end")) {
$argv += "--playlist-end", $opts.playlist_end
}
if ($opts.ContainsKey("max_downloads")) {
$argv += "--max-downloads", $opts.max_downloads
}
if ($opts.ContainsKey("min_filesize")) {
$argv += "--min-filesize", $opts.min_filesize
}
if ($opts.ContainsKey("max_filesize")) {
$argv += "--max-filesize", $opts.max_filesize
}
if ($opts.ContainsKey("on_date")) {
$argv += "--date", $opts.on_date
}
if ($opts.ContainsKey("date_before")) {
$argv += "--datebefore", $opts.date_before
}
if ($opts.ContainsKey("date_after")) {
$argv += "--dateafter", $opts.date_after
}
if ($opts.ContainsKey("min_views")) {
$argv += "--min-views", $opts.min_views
}
if ($opts.ContainsKey("max_views")) {
$argv += "--max-views", $opts.max_views
}
if (!$opts.ContainsKey("sys_dl_log")) {
$opts.sys_dl_log = "sys_dl.log"
}
$argv += @(
"--download-archive", $opts.sys_dl_log
# we're not gonna download livestreams
"--match-filter", $($opts.match_filter ?? "!is_live & !live")
)
# download options
if ($opts.ContainsKey("concurrent_fragments")) {
argv += "--concurrent-fragments", $opts.concurrent_fragments
}
if ($opts.ContainsKey("limit_rate")) {
$argv += "--limit-rate", $($opts.limit_rate)
}
if ($opts.ContainsKey("retries")) {
$argv += "--retries $($opts.retries)"
}
if ($opts.playlist_reverse) {
$argv += "--playlist-reverse"
}
# filesystem options
if ($opts.ContainsKey("batch_file")) {
$argv += "--batch-file", $($opts.batch_file)
}
$default_output = "archives/%(upload_date)s_%(uploader)s_%(title)s_%(id)s.%(ext)s"
$argv += @(
"--output", $($opts.output ?? $default_output)
"--no-overwrites"
)
if ($opts.no_continue) {
$argv += "--no-continue"
}
$argv += @(
"--mtime"
"--write-description"
"--write-info-json"
"--write-annotations"
"--write-playlist-metafiles"
)
# thumbnail images
$argv += @(
"--write-thumbnail"
"--write-all-thumbnails"
)
# internet shortcut options
$argv += "--write-desktop-link"
# verbosity and simulation options
$argv += "--verbose"
# workarounds
if ($opts.ContainsKey("sleep_requests")) {
argv += "--sleep-requests", $opts.sleep_requests
}
$argv += @(
"--min-sleep-interval", $($opts.min_sleep_interval ?? 05)
"--max-sleep-interval", $($opts.max_sleep_interval ?? 30)
"--sleep-subtitles" , $($opts.sleep_subtitles ?? 01)
)
# video format options
$argv += "--merge-output-format", $($opts.format ?? "mkv")
# subtitle options
$argv += @(
"--write-subs"
"--no-write-auto-subs"
"--all-subs"
"--sub-format", $($opts.sub_format ?? "best")
)
# authentication options
if ($opts.ContainsKey("auth")) {
$argv += @(
"--username", $opts.auth.username
"--password", $opts.auth.password
)
}
# post processing options
if (!$opts.ContainsKey("usr_dl_log")) {
$opts.usr_dl_log = "usr_dl.log"
}
$argv += @(
"--embed-subs"
"--embed-thumbnail"
"--add-metadata"
"--exec", "pwsh $PSScriptRoot\Write-DownloadLog.ps1 $($opts.usr_dl_log) {}"
)
if ($opts.ContainsKey("urls")) {
if ($opts.urls -is [array]) {
$argv += $opts.urls
} else {
throw "opts.urls must be a string array!"
}
}
yt-dlp $argv
}