-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpc.lua
executable file
·73 lines (63 loc) · 1.75 KB
/
pc.lua
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
#!/usr/bin/lua
-- SPDX-License-Identifier: GPL-2.0
-- Copyright 2024-2025 - Fábio Rodrigues Ribeiro and contributors
x = os.execute
local s = require "sai"
local function limpa()
x "rm -rf list.txt output.flac output.mp3 *.mp3"
end
local function arquivos()
local handle = assert(io.popen "\\ls -1 | sort -V")
if not handle then error "Erro ao executar o comando." end
local result = handle:read "*a"
handle:close()
return result
end
local function gera_lista(result)
local filename = "list.txt"
local file = assert(io.open(filename, "w"))
if not file then error (("Erro ao abrir o arquivo %s para escrita."):format(filename)) end
for linha in result:gmatch("[^\n]+") do file:write(("file '%s'\n"):format(linha)) end -- Imprime diretamente a linha no formato 'file'
file:close()
print (("%s criado com sucesso."):format(filename))
end
local function ind_mp3(result)
for linha in result:gmatch("[^\n]+") do x (("ffmpeg -i '%s' -vn -ar 44100 -ac 2 -b:a 192k '%s'"):format(linha, linha:gsub("%.flac", ".mp3"))) end -- Converte arquivos flac para mp3
end
local function podcast_flac()
limpa()
gera_lista(arquivos())
x "ffmpeg -f concat -safe 0 -i list.txt -c:a flac output.flac"
end
local function podcast_mp3()
local cmd = "ffmpeg -i output.flac -vn -ar 44100 -ac 2 -b:a 192k output.mp3"
limpa()
local file = assert(io.open("output.flac", "r"))
if file then
file:close()
x(cmd)
else
file:close()
podcast_flac()
x(cmd)
end
end
handlers ={
limpa = limpa,
["ind_mp3"] = function ()
limpa()
ind_mp3(arquivos())
end,
podcast_flac = podcast_flac,
podcast_mp3 = podcast_mp3,
["all"] = function ()
local result = arquivos()
limpa()
gera_lista(result)
ind_mp3(result)
podcast_flac()
podcast_mp3()
end
}
s.ca_none()
handlers[arg[1]]()