Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import subprocess
|
2 |
import uuid
|
3 |
-
import ffmpeg
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
title_and_description = """
|
7 |
# Download de clipes da Twitch
|
@@ -20,48 +20,23 @@ Sinta-se à vontade para usar e gerar seus próprios videoclipes!
|
|
20 |
Para baixar o vídeo é só clicar no botão de download em cima do vídeo. Seta apontada para baixo.
|
21 |
"""
|
22 |
|
23 |
-
# Function to download Twitch clip using
|
24 |
-
def download_twitch_clip(url
|
25 |
-
# Generate a UUID for the file name
|
26 |
unique_id = uuid.uuid4()
|
27 |
-
output_filename = f"{unique_id}.
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# Add authentication token if provided
|
33 |
-
if auth_token.strip():
|
34 |
-
command.extend(["-a", auth_token])
|
35 |
-
|
36 |
-
# Execute the download command
|
37 |
-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
38 |
-
stdout, stderr = process.communicate()
|
39 |
-
|
40 |
-
if process.returncode != 0:
|
41 |
-
raise Exception(f"Error in video download: {stderr.decode('utf-8')}")
|
42 |
|
43 |
return output_filename
|
44 |
|
45 |
-
# Function to convert MKV to MP4 using ffmpeg-python
|
46 |
-
def convert_to_mp4(input_file):
|
47 |
-
output_file = input_file.replace('.mkv', '.mp4')
|
48 |
-
|
49 |
-
try:
|
50 |
-
(
|
51 |
-
ffmpeg
|
52 |
-
.input(input_file)
|
53 |
-
.output(output_file, vcodec='libx264', acodec='aac')
|
54 |
-
.run(overwrite_output=True)
|
55 |
-
)
|
56 |
-
return output_file
|
57 |
-
except ffmpeg.Error as e:
|
58 |
-
print(f"Error in file conversion: {e}")
|
59 |
-
return None
|
60 |
-
|
61 |
# Gradio interface
|
62 |
-
def gradio_interface(url
|
63 |
-
|
64 |
-
mp4_file = convert_to_mp4(mkv_file)
|
65 |
return mp4_file, mp4_file # Return the file path twice, for both the video and file components
|
66 |
|
67 |
with gr.Blocks() as app:
|
@@ -69,19 +44,18 @@ with gr.Blocks() as app:
|
|
69 |
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
-
result_video = gr.Video(label="
|
73 |
-
download_link = gr.File(label="Download MP4")
|
74 |
|
75 |
with gr.Row():
|
76 |
with gr.Column():
|
77 |
url_input = gr.Textbox(label="Twitch Clip URL")
|
78 |
-
auth_token_input = gr.Textbox(label="Authentication Token (optional)", type="password")
|
79 |
run_btn = gr.Button("Download Clip")
|
80 |
|
81 |
run_btn.click(
|
82 |
gradio_interface,
|
83 |
-
inputs=[url_input
|
84 |
-
outputs=[result_video, download_link]
|
85 |
)
|
86 |
|
87 |
app.queue()
|
|
|
1 |
import subprocess
|
2 |
import uuid
|
|
|
3 |
import gradio as gr
|
4 |
+
from youtube_dl import YoutubeDL
|
5 |
|
6 |
title_and_description = """
|
7 |
# Download de clipes da Twitch
|
|
|
20 |
Para baixar o vídeo é só clicar no botão de download em cima do vídeo. Seta apontada para baixo.
|
21 |
"""
|
22 |
|
23 |
+
# Function to download Twitch clip using youtube-dl
|
24 |
+
def download_twitch_clip(url):
|
|
|
25 |
unique_id = uuid.uuid4()
|
26 |
+
output_filename = f"{unique_id}.mp4"
|
27 |
+
ydl_opts = {
|
28 |
+
'format': 'best[ext=mp4]',
|
29 |
+
'outtmpl': output_filename
|
30 |
+
}
|
31 |
|
32 |
+
with YoutubeDL(ydl_opts) as ydl:
|
33 |
+
ydl.download([url])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
return output_filename
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Gradio interface
|
38 |
+
def gradio_interface(url):
|
39 |
+
mp4_file = download_twitch_clip(url)
|
|
|
40 |
return mp4_file, mp4_file # Return the file path twice, for both the video and file components
|
41 |
|
42 |
with gr.Blocks() as app:
|
|
|
44 |
|
45 |
with gr.Row():
|
46 |
with gr.Column():
|
47 |
+
result_video = gr.Video(label="Video Output")
|
48 |
+
download_link = gr.File(label="Download MP4")
|
49 |
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
url_input = gr.Textbox(label="Twitch Clip URL")
|
|
|
53 |
run_btn = gr.Button("Download Clip")
|
54 |
|
55 |
run_btn.click(
|
56 |
gradio_interface,
|
57 |
+
inputs=[url_input],
|
58 |
+
outputs=[result_video, download_link]
|
59 |
)
|
60 |
|
61 |
app.queue()
|