-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia-dl.lua
More file actions
executable file
·62 lines (52 loc) · 2.35 KB
/
media-dl.lua
File metadata and controls
executable file
·62 lines (52 loc) · 2.35 KB
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
#!/usr/bin/env luajit
local helptext = [[
Actions:
video: Highest quality video (maximum 720p).
backup, clone, copy: English subtitles (including automatic subtitles),
thumbnail, description, highest quality video (max 720p).
music, audio: Highest quality audio only.
metadata, meta: English subtitles (including automatic subtitles),
thumbnail, description.
]]
package.path = (arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)")) .. "lib" .. package.config:sub(1, 1) .. "?.lua;" .. package.path
local utility = require "utility"
local argparse = utility.require("argparse")
local parser = argparse():description("Download media and metadata from anything supported by YT-DLP."):epilog(helptext)
parser:argument("action", "What media and/or metadata to select."):choices{"video", "backup", "clone", "copy", "music", "audio", "metadata", "meta"}
:default("video"):defmode("arg"):args("?")
parser:flag("--file", "The URL specified is actually a file of one URL per line to be processed.")
parser:argument("url", "Source URL. Can be from anywhere supported by YT-DLP."):args(1)
local options = parser:parse()
-- BUG even though this is specified as an optional argument, argparse won't handle it correctly
if not options.action then options.action = "video" end
utility.required_program("yt-dlp")
local core_command = "yt-dlp --retries 100 "
local metadata_options = "--write-sub --write-auto-sub --sub-lang \"en.*\" --write-thumbnail --write-description "
local quality_ceiling_720 = "-f \"bestvideo[height<=720]+bestaudio/best[height<=720]\" "
local execute = {
backup = function(url)
os.execute(core_command .. metadata_options .. quality_ceiling_720 .. url:enquote())
end,
music = function(url)
os.execute(core_command .. "-x --audio-quality 0 " .. url:enquote())
end,
metadata = function(url)
os.execute(core_command .. metadata_options .. "--skip-download " .. url:enquote())
end,
video = function(url)
os.execute(core_command .. quality_ceiling_720 .. url:enquote())
end,
}
execute.clone = execute.backup
execute.copy = execute.backup
execute.audio = execute.music
execute.meta = execute.metadata
if options.file then
pcall(function()
for line in io.lines(options.url) do
execute[options.action](line)
end
end)
else
execute[options.action](options.url)
end