.lua-files/video-dl.lua

76 lines
2.4 KiB
Lua
Raw Normal View History

2024-01-13 11:04:00 +00:00
#!/usr/bin/env luajit
2024-01-14 01:13:57 +00:00
local help = [[Usage:
2024-01-13 11:04:00 +00:00
2024-02-18 21:24:01 +00:00
video-dl.lua [action] [--file] <url>
2024-01-13 11:04:00 +00:00
[action]: What is desired.
video (default): Highest quality video (maximum 720p).
backup, clone, copy: English subtitles (including automatic
subtitles), thumbnail, description, highest quality video
(maximum 720p).
music, audio: Highest quality audio only.
metadata, meta: English subtitles (including automatic
subtitles), thumbnail, description.
2024-02-18 21:24:01 +00:00
[--file]: <url> is actually a file of URLs to open and execute [action]
on each.
2024-01-13 11:04:00 +00:00
<url>: Source. YouTube URL expected, but should work with anything
yt-dlp works with.
IMPORTANT: Expects Firefox to be installed with a YouTube account logged in to get cookies from.
2024-01-13 11:04:00 +00:00
]]
if os.execute("where yt-dlp") ~= 0 then
2024-01-13 23:37:46 +00:00
error("yt-dlp must be installed and in the path")
end
2024-01-13 11:04:00 +00:00
local action, url
if #arg < 2 then
if arg[1]:find("help") then
print(help)
return false
end
action = "video"
url = arg[1]
else
action = arg[1]
url = arg[2]
2024-02-18 21:24:01 +00:00
-- "--file" is handled just before execution
2024-01-13 11:04:00 +00:00
end
local execute = {
2024-02-18 21:24:01 +00:00
backup = function(url)
os.execute("yt-dlp --retries 100 --write-sub --write-auto-sub --sub-lang \"en.*\" --write-thumbnail --write-description -f \"bestvideo[height<=720]+bestaudio/best[height<=720]\" \"" .. url .."\" --cookies-from-browser \"firefox\"")
2024-01-13 11:04:00 +00:00
end,
2024-02-18 21:24:01 +00:00
music = function(url)
os.execute("yt-dlp --retries 100 -x --audio-quality 0 \"" .. url .."\" --cookies-from-browser \"firefox\"")
2024-01-13 11:04:00 +00:00
end,
2024-02-18 21:24:01 +00:00
metadata = function(url)
os.execute("yt-dlp --retries 100 --write-sub --write-auto-sub --sub-lang \"en.*\" --write-thumbnail --write-description --skip-download \"" .. url .."\" --cookies-from-browser \"firefox\"")
2024-01-13 11:04:00 +00:00
end,
2024-02-18 21:24:01 +00:00
video = function(url)
os.execute("yt-dlp --retries 100 -f \"bestvideo[height<=720]+bestaudio/best[height<=720]\" \"" .. url .. "\" --cookies-from-browser \"firefox\"")
2024-01-13 11:04:00 +00:00
end,
}
execute.clone = execute.backup
execute.copy = execute.backup
execute.audio = execute.music
execute.meta = execute.metadata
if execute[action] then
2024-02-18 21:24:01 +00:00
if url == "--file" then
pcall(function()
for line in io.lines(arg[3]) do
execute[action](line)
end
end)
else
execute[action](url)
end
2024-01-13 11:04:00 +00:00
else
2024-01-14 02:40:46 +00:00
print("Invalid [action]")
2024-01-13 11:04:00 +00:00
print("Received:", "action", action, "url", url)
2024-02-18 21:24:01 +00:00
return false
2024-01-13 11:04:00 +00:00
end