|
import gradio as gr |
|
import subprocess |
|
import os |
|
import re |
|
import datetime |
|
|
|
|
|
def download_twitch_clip(url, auth_token): |
|
|
|
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() |
|
|
|
|
|
file_name = output_pattern.format(id="unknown", channel_login="unknown", title_slug="unknown", format="mkv") |
|
return file_name |
|
|
|
|
|
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() |
|
) |
|
|
|
|
|
iface.launch() |
|
|