Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,53 @@
|
|
1 |
-
import gradio as gr
|
2 |
import subprocess
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import datetime
|
6 |
import uuid
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
# Função para baixar o clipe da Twitch
|
9 |
def download_twitch_clip(url, auth_token):
|
10 |
-
# Gerar um UUID
|
11 |
unique_id = uuid.uuid4()
|
12 |
-
|
13 |
-
# Criar um nome de arquivo único com o UUID
|
14 |
output_filename = f"{unique_id}.mkv"
|
15 |
|
|
|
16 |
command = ["twitch-dl", "download", url, "-q", "source", "-o", output_filename]
|
17 |
|
|
|
18 |
if auth_token.strip():
|
19 |
command.extend(["-a", auth_token])
|
20 |
|
|
|
21 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
22 |
stdout, stderr = process.communicate()
|
23 |
|
24 |
-
|
|
|
|
|
25 |
return output_filename
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Interface Gradio
|
28 |
def gradio_interface(url, auth_token=""):
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn=gradio_interface,
|
|
|
|
|
1 |
import subprocess
|
|
|
|
|
|
|
2 |
import uuid
|
3 |
+
import ffmpeg
|
4 |
+
import gradio as gr
|
5 |
+
import os
|
6 |
+
import re
|
7 |
|
8 |
+
# Função para baixar o clipe da Twitch usando twitch-dl
|
9 |
def download_twitch_clip(url, auth_token):
|
10 |
+
# Gerar um UUID para o nome do arquivo
|
11 |
unique_id = uuid.uuid4()
|
|
|
|
|
12 |
output_filename = f"{unique_id}.mkv"
|
13 |
|
14 |
+
# Comando para baixar o vídeo
|
15 |
command = ["twitch-dl", "download", url, "-q", "source", "-o", output_filename]
|
16 |
|
17 |
+
# Adiciona o token de autenticação, se fornecido
|
18 |
if auth_token.strip():
|
19 |
command.extend(["-a", auth_token])
|
20 |
|
21 |
+
# Executa o comando de download
|
22 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
23 |
stdout, stderr = process.communicate()
|
24 |
|
25 |
+
if process.returncode != 0:
|
26 |
+
raise Exception(f"Erro no download do vídeo: {stderr.decode('utf-8')}")
|
27 |
+
|
28 |
return output_filename
|
29 |
|
30 |
+
# Função para converter MKV para MP4 usando ffmpeg-python
|
31 |
+
def convert_to_mp4(input_file):
|
32 |
+
output_file = input_file.replace('.mkv', '.mp4')
|
33 |
+
|
34 |
+
try:
|
35 |
+
(
|
36 |
+
ffmpeg
|
37 |
+
.input(input_file)
|
38 |
+
.output(output_file, vcodec='libx264', acodec='aac')
|
39 |
+
.run(overwrite_output=True)
|
40 |
+
)
|
41 |
+
return output_file
|
42 |
+
except ffmpeg.Error as e:
|
43 |
+
print(f"Erro ao converter o arquivo: {e}")
|
44 |
+
return None
|
45 |
+
|
46 |
# Interface Gradio
|
47 |
def gradio_interface(url, auth_token=""):
|
48 |
+
mkv_file = download_twitch_clip(url, auth_token)
|
49 |
+
mp4_file = convert_to_mp4(mkv_file)
|
50 |
+
return mp4_file
|
51 |
|
52 |
iface = gr.Interface(
|
53 |
fn=gradio_interface,
|