Spaces:
Sleeping
Sleeping
artificialguybr
commited on
Commit
•
c98b0b5
1
Parent(s):
e1eb4d4
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,15 @@ import gradio as gr
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
import re
|
|
|
5 |
|
6 |
# Função para baixar o clipe da Twitch
|
7 |
def download_twitch_clip(url, auth_token):
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
if auth_token.strip():
|
11 |
command.extend(["-a", auth_token])
|
@@ -13,17 +18,10 @@ def download_twitch_clip(url, auth_token):
|
|
13 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
14 |
stdout, stderr = process.communicate()
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
if match:
|
19 |
-
file_name = match.group(1)
|
20 |
-
else:
|
21 |
-
# Forneça uma mensagem de erro mais descritiva ou tente um método alternativo
|
22 |
-
raise Exception("Não foi possível encontrar o nome do arquivo de vídeo na saída do comando.")
|
23 |
-
|
24 |
return file_name
|
25 |
|
26 |
-
|
27 |
# Interface Gradio
|
28 |
def gradio_interface(url, auth_token=""):
|
29 |
file_name = download_twitch_clip(url, auth_token)
|
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
import re
|
5 |
+
import datetime
|
6 |
|
7 |
# Função para baixar o clipe da Twitch
|
8 |
def download_twitch_clip(url, auth_token):
|
9 |
+
# Gera um timestamp para usar no nome do arquivo
|
10 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
11 |
+
output_pattern = f"{timestamp}_{{id}}_{{channel_login}}_{{title_slug}}.{{format}}"
|
12 |
+
|
13 |
+
command = ["twitch-dl", "download", url, "-q", "source", "-o", output_pattern]
|
14 |
|
15 |
if auth_token.strip():
|
16 |
command.extend(["-a", auth_token])
|
|
|
18 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
19 |
stdout, stderr = process.communicate()
|
20 |
|
21 |
+
# O nome do arquivo é determinado pelo padrão de saída
|
22 |
+
file_name = output_pattern.format(id="unknown", channel_login="unknown", title_slug="unknown", format="mkv")
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
return file_name
|
24 |
|
|
|
25 |
# Interface Gradio
|
26 |
def gradio_interface(url, auth_token=""):
|
27 |
file_name = download_twitch_clip(url, auth_token)
|