|
import subprocess |
|
import uuid |
|
import ffmpeg |
|
import gradio as gr |
|
import os |
|
import re |
|
|
|
|
|
def download_twitch_clip(url, auth_token): |
|
|
|
unique_id = uuid.uuid4() |
|
output_filename = f"{unique_id}.mkv" |
|
|
|
|
|
command = ["twitch-dl", "download", url, "-q", "source", "-o", output_filename] |
|
|
|
|
|
if auth_token.strip(): |
|
command.extend(["-a", auth_token]) |
|
|
|
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
stdout, stderr = process.communicate() |
|
|
|
if process.returncode != 0: |
|
raise Exception(f"Erro no download do vídeo: {stderr.decode('utf-8')}") |
|
|
|
return output_filename |
|
|
|
|
|
def convert_to_mp4(input_file): |
|
output_file = input_file.replace('.mkv', '.mp4') |
|
|
|
try: |
|
( |
|
ffmpeg |
|
.input(input_file) |
|
.output(output_file, vcodec='libx264', acodec='aac') |
|
.run(overwrite_output=True) |
|
) |
|
return output_file |
|
except ffmpeg.Error as e: |
|
print(f"Erro ao converter o arquivo: {e}") |
|
return None |
|
|
|
|
|
def gradio_interface(url, auth_token=""): |
|
mkv_file = download_twitch_clip(url, auth_token) |
|
mp4_file = convert_to_mp4(mkv_file) |
|
return mp4_file |
|
|
|
iface = gr.Interface( |
|
fn=gradio_interface, |
|
inputs=[ |
|
gr.Textbox(label="URL do Clipe da Twitch"), |
|
gr.Textbox(label="Token de Autenticação (opcional)") |
|
], |
|
outputs=gr.Video() |
|
) |
|
|
|
|
|
iface.launch() |
|
|