Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
-
from pathlib import Path
|
5 |
|
6 |
def download_video(url, quality, format_choice, download_playlist, cookies_file):
|
7 |
try:
|
@@ -13,7 +12,6 @@ def download_video(url, quality, format_choice, download_playlist, cookies_file)
|
|
13 |
|
14 |
# Sử dụng file cookie nếu được upload
|
15 |
if cookies_file is not None:
|
16 |
-
# Lưu file cookie tạm thời
|
17 |
cookie_path = "temp_cookies.txt"
|
18 |
with open(cookie_path, "wb") as f:
|
19 |
f.write(cookies_file)
|
@@ -49,7 +47,7 @@ def download_video(url, quality, format_choice, download_playlist, cookies_file)
|
|
49 |
info = ydl.extract_info(url, download=True)
|
50 |
filename = ydl.prepare_filename(info)
|
51 |
|
52 |
-
# Xóa file cookie tạm thời
|
53 |
if cookies_file is not None and os.path.exists(cookie_path):
|
54 |
os.remove(cookie_path)
|
55 |
|
@@ -63,32 +61,14 @@ interface = gr.Interface(
|
|
63 |
fn=download_video,
|
64 |
inputs=[
|
65 |
gr.Textbox(label="Dán URL video vào đây", placeholder="https://..."),
|
66 |
-
gr.Dropdown(
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
info="Best: Cao nhất, Medium: 720p, Low: 480p"
|
71 |
-
),
|
72 |
-
gr.Dropdown(
|
73 |
-
choices=["MP4", "MKV", "Audio Only (MP3)"],
|
74 |
-
label="Định dạng đầu ra",
|
75 |
-
value="MP4",
|
76 |
-
info="Chọn định dạng file xuất ra"
|
77 |
-
),
|
78 |
-
gr.Checkbox(
|
79 |
-
label="Tải toàn bộ playlist (nếu có)",
|
80 |
-
value=False,
|
81 |
-
info="Check để tải toàn bộ playlist"
|
82 |
-
),
|
83 |
-
gr.File(
|
84 |
-
label="Upload file cookie (nếu cần)",
|
85 |
-
type="binary",
|
86 |
-
info="Upload file cookie (.txt) để tải video yêu cầu đăng nhập"
|
87 |
-
)
|
88 |
],
|
89 |
outputs=gr.Textbox(label="Kết quả"),
|
90 |
title="Trình tải video trên Hugging Face Spaces",
|
91 |
-
description="Dán URL video và
|
92 |
)
|
93 |
|
94 |
# Khởi chạy ứng dụng
|
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
|
|
4 |
|
5 |
def download_video(url, quality, format_choice, download_playlist, cookies_file):
|
6 |
try:
|
|
|
12 |
|
13 |
# Sử dụng file cookie nếu được upload
|
14 |
if cookies_file is not None:
|
|
|
15 |
cookie_path = "temp_cookies.txt"
|
16 |
with open(cookie_path, "wb") as f:
|
17 |
f.write(cookies_file)
|
|
|
47 |
info = ydl.extract_info(url, download=True)
|
48 |
filename = ydl.prepare_filename(info)
|
49 |
|
50 |
+
# Xóa file cookie tạm thời
|
51 |
if cookies_file is not None and os.path.exists(cookie_path):
|
52 |
os.remove(cookie_path)
|
53 |
|
|
|
61 |
fn=download_video,
|
62 |
inputs=[
|
63 |
gr.Textbox(label="Dán URL video vào đây", placeholder="https://..."),
|
64 |
+
gr.Dropdown(choices=["Best", "Medium", "Low"], label="Chất lượng video", value="Best"),
|
65 |
+
gr.Dropdown(choices=["MP4", "MKV", "Audio Only (MP3)"], label="Định dạng đầu ra", value="MP4"),
|
66 |
+
gr.Checkbox(label="Tải toàn bộ playlist (nếu có)", value=False),
|
67 |
+
gr.File(label="Upload file cookie (nếu cần)", type="binary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
],
|
69 |
outputs=gr.Textbox(label="Kết quả"),
|
70 |
title="Trình tải video trên Hugging Face Spaces",
|
71 |
+
description="Dán URL video và upload file cookie nếu cần (xuất từ trình duyệt bằng extension)."
|
72 |
)
|
73 |
|
74 |
# Khởi chạy ứng dụng
|