Spaces:
Sleeping
Sleeping
File size: 1,233 Bytes
89df459 8eefd04 c98b0b5 89df459 1badb48 c98b0b5 89df459 1badb48 89df459 8eefd04 89df459 c98b0b5 89df459 1badb48 89df459 80798c8 1badb48 89df459 4765650 89df459 |
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 |
import gradio as gr
import subprocess
import os
import re
import datetime
# Função para baixar o clipe da Twitch
def download_twitch_clip(url, auth_token):
# Gera um timestamp para usar no nome do arquivo
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_pattern = f"{timestamp}_{{id}}_{{channel_login}}_{{title_slug}}.{{format}}"
command = ["twitch-dl", "download", url, "-q", "source", "-o", output_pattern]
if auth_token.strip():
command.extend(["-a", auth_token])
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# O nome do arquivo é determinado pelo padrão de saída
file_name = output_pattern.format(id="unknown", channel_login="unknown", title_slug="unknown", format="mkv")
return file_name
# Interface Gradio
def gradio_interface(url, auth_token=""):
file_name = download_twitch_clip(url, auth_token)
return file_name
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()
)
# Executar a interface
iface.launch()
|