87 lines
2.2 KiB
Lua
Executable File
87 lines
2.2 KiB
Lua
Executable File
#!/usr/bin/env lua
|
||
|
||
local lfs = require("lfs")
|
||
|
||
local function file_rename(file)
|
||
local patterns = "[%(%)[%]{}%s]"
|
||
local new_name = string.gsub(file, patterns, "_")
|
||
os.rename(file, new_name)
|
||
os.rename(new_name, string.gsub(new_name, "mkv.", ""))
|
||
os.rename(new_name, string.gsub(new_name, "webm.", ""))
|
||
if file ~= new_name then
|
||
print("Файл " .. file .. " был переименован ==> " .. new_name)
|
||
end
|
||
end
|
||
|
||
-- -----------------------------------------------
|
||
-- Скачивание файлов
|
||
-- -----------------------------------------------
|
||
local function downloads(url)
|
||
local tempdir = "temp"
|
||
lfs.mkdir(tempdir)
|
||
|
||
lfs.chdir(tempdir)
|
||
print("Качаем видео...")
|
||
os.execute("yt-dlp -o '%(title)s.%(ext)s' " .. url)
|
||
print("Качаем перевод...")
|
||
os.execute("vot-cli " .. url .. " --output .")
|
||
|
||
local video_t = ""
|
||
local audio_t = ""
|
||
|
||
for f in lfs.dir(".") do
|
||
local mode = lfs.attributes("./" .. f, "mode")
|
||
local ext = f:match("[^.]+$")
|
||
if mode == "file" and (ext == "webm" or ext == "mkv" or ext == "mp4") then
|
||
video_t = f
|
||
elseif mode == "file" and ext == "mp3" then
|
||
audio_t = f
|
||
else
|
||
print("Файлы не найдены...")
|
||
end
|
||
end
|
||
|
||
print("Конвертируем...")
|
||
os.execute(
|
||
'ffmpeg -i "'
|
||
.. video_t
|
||
.. '" -i '
|
||
.. audio_t
|
||
.. ' -c:v copy -filter_complex "[0:a] volume=0.15 [original]; [original][1:a] amix=inputs=2:duration=longest [audio_out]" -map 0:v -map "[audio_out]" -y ../'
|
||
.. '"'
|
||
.. video_t
|
||
.. '"'
|
||
)
|
||
|
||
print("Удаляется файл ==> ", video_t)
|
||
os.remove(video_t)
|
||
print("Удаляется файл ==> ", audio_t)
|
||
os.remove(audio_t)
|
||
|
||
lfs.chdir("../")
|
||
|
||
print("Удаляется директория ==> " .. tempdir)
|
||
lfs.rmdir(tempdir)
|
||
end
|
||
|
||
-- Открываем файл для чтения
|
||
local file = io.open(arg[1], "r")
|
||
|
||
if file then
|
||
-- Читаем и выводим построчно содержимое файла
|
||
for line in file:lines() do
|
||
downloads(line)
|
||
end
|
||
-- Закрываем файл
|
||
file:close()
|
||
else
|
||
print("Не удалось открыть файл")
|
||
end
|
||
|
||
for f in lfs.dir(".") do
|
||
local mode = lfs.attributes("./" .. f, "mode")
|
||
if mode == "file" then
|
||
file_rename(f)
|
||
end
|
||
end
|