Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import os
|
4 |
|
5 |
-
def
|
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 |
-
# Create a list of (filename, file path) tuples for Gradio File component
|
31 |
-
file_tuples = [(f, f) for f in downloaded_files if os.path.exists(f)]
|
32 |
-
message = f"Successfully downloaded {len(file_tuples)} videos."
|
33 |
-
return file_tuples, message
|
34 |
-
else:
|
35 |
-
return None, "Download failed. Please check the URLs and try again."
|
36 |
-
|
37 |
-
with gr.Blocks() as interface:
|
38 |
-
gr.Markdown("## YouTube Batch Video Downloader")
|
39 |
-
urls_input = gr.Textbox(label="Enter YouTube links (one per line) 🔗", lines=5)
|
40 |
-
download_button = gr.Button("Download Videos")
|
41 |
-
output = gr.File(label="Downloaded Videos", file_count="multiple")
|
42 |
-
message = gr.Markdown()
|
43 |
-
|
44 |
-
download_button.click(
|
45 |
-
fn=app,
|
46 |
-
inputs=urls_input,
|
47 |
-
outputs=[output, message],
|
48 |
-
api_name="download"
|
49 |
-
)
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from yt_dlp import YoutubeDL
|
|
|
3 |
|
4 |
+
def extract_metadata(youtube_url):
|
5 |
+
ydl_opts = {'quiet': True}
|
6 |
+
try:
|
7 |
+
with YoutubeDL(ydl_opts) as ydl:
|
8 |
+
info = ydl.extract_info(youtube_url, download=False)
|
9 |
+
|
10 |
+
metadata = {
|
11 |
+
"제목": info.get('title', 'N/A'),
|
12 |
+
"채널": info.get('channel', 'N/A'),
|
13 |
+
"업로드 날짜": info.get('upload_date', 'N/A'),
|
14 |
+
"조회수": info.get('view_count', 'N/A'),
|
15 |
+
"좋아요 수": info.get('like_count', 'N/A'),
|
16 |
+
"길이 (초)": info.get('duration', 'N/A'),
|
17 |
+
"설명": info.get('description', 'N/A')[:500] + '...' # 설명 일부만 표시
|
18 |
+
}
|
19 |
+
|
20 |
+
return "\n".join([f"{k}: {v}" for k, v in metadata.items()])
|
21 |
+
except Exception as e:
|
22 |
+
return f"오류 발생: {str(e)}"
|
23 |
+
|
24 |
+
def check_yt_dlp_version():
|
25 |
+
return f"yt-dlp 버전: {YoutubeDL.version.__version__}"
|
26 |
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## YouTube 메타데이터 추출기")
|
29 |
+
gr.Markdown(check_yt_dlp_version())
|
30 |
|
31 |
+
with gr.Row():
|
32 |
+
youtube_url_input = gr.Textbox(label="YouTube URL 입력")
|
33 |
+
extract_button = gr.Button("메타데이터 추출")
|
34 |
|
35 |
+
output = gr.Textbox(label="추출된 메타데이터", lines=10)
|
36 |
|
37 |
+
extract_button.click(fn=extract_metadata, inputs=youtube_url_input, outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
+
demo.launch()
|