mirror of
https://github.com/TangentFoxy/.lua-files.git
synced 2024-11-20 21:34:23 +00:00
subtitle downloader is better
This commit is contained in:
parent
bfc44da3d3
commit
b962dacf7b
@ -1,12 +1,45 @@
|
|||||||
local source = "URL"
|
#!/usr/bin/env luajit
|
||||||
|
|
||||||
os.execute("yt-dlp --flat-playlist --print-to-file \"%(id)s\" download-list.txt --skip-download \"" .. source .. "\"")
|
local source = arg[1]
|
||||||
os.execute("yt-dlp --flat-playlist --print-to-file \"%(id)s=%(title)s\" VIDEO-TITLES.txt --skip-download \"" .. source .. "\"")
|
assert(source and #source > 0, "Specify a URL!")
|
||||||
|
|
||||||
|
local function make_safe(file_name)
|
||||||
|
-- return file_name:gsub("[%w%s%_%-%,%.%[%]%(%)%'%+]", "") -- this is the literal opposite of what I needed, oops
|
||||||
|
-- return file_name:gsub("[%\"%:%\\%!%@%#%$%%%^%&%*%=%{%}%|%;%<%>%?%/]", "") -- this should handle everything but I'm not certain! :D
|
||||||
|
|
||||||
|
file_name = file_name:gsub("[%\"%:%\\%!%@%#%$%%%^%*%=%{%}%|%;%<%>%?%/]", "") -- everything except the &
|
||||||
|
file_name = file_name:gsub(" %&", ",") -- replacing & with a comma works for 99% of things
|
||||||
|
file_name = file_name:gsub("%&", ",") -- replacing & with a comma works for 99% of things
|
||||||
|
file_name = file_name:gsub("[%s+]", " ") -- more than one space in succession should be a single space
|
||||||
|
return file_name
|
||||||
|
end
|
||||||
|
|
||||||
|
local function download_subtitle(id, file_name)
|
||||||
|
os.execute("sleep 6") -- up-front in case chromium isn't ready / delay from previous download to prevent rate limit issues
|
||||||
|
os.execute("chromium \"https://www.downloadyoutubesubtitles.com/?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D" .. id .. "\"")
|
||||||
|
os.execute("sleep 12")
|
||||||
|
os.execute("curl \"https://www.downloadyoutubesubtitles.com/get2.php?i=" .. id .. "&format=txt&hl=en&a=\" > \"./subtitles/" .. (file_name or id) .. ".txt\"")
|
||||||
|
end
|
||||||
|
|
||||||
|
os.execute("pwsh -command chromium") -- open browser first, to make sure it is ready by the time we start using it
|
||||||
|
|
||||||
|
os.execute("yt-dlp --flat-playlist --print-to-file \"%(id)s=%(title)s\" videos.txt --skip-download \"" .. source .. "\"")
|
||||||
os.execute("mkdir subtitles")
|
os.execute("mkdir subtitles")
|
||||||
|
|
||||||
for line in io.lines("download-list.txt") do
|
local videos = {}
|
||||||
os.execute("chromium \"https://www.downloadyoutubesubtitles.com/?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D" .. line .. "\"")
|
|
||||||
os.execute("sleep 12")
|
local file = io.open("videos.txt", "r")
|
||||||
os.execute("curl \"https://www.downloadyoutubesubtitles.com/get2.php?i=" .. line .. "&format=txt&hl=en&a=\" > \"./subtitles/" .. line .. ".txt\"")
|
assert(file, "videos.txt doesn't exist.. somehow")
|
||||||
os.execute("sleep 6")
|
for line in file:lines() do
|
||||||
|
local i, j = line:find("%=")
|
||||||
|
videos[#videos + 1] = {
|
||||||
|
id = line:sub(1, i - 1),
|
||||||
|
title = line:sub(j + 1),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
for index, video in ipairs(videos) do
|
||||||
|
print(index, #videos, video.title)
|
||||||
|
download_subtitle(video.id, make_safe(video.title))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user