Update app.py
Browse files
app.py
CHANGED
@@ -22,18 +22,30 @@ def extract_info(youtube_url):
|
|
22 |
"길이 (초)": info.get('duration', 'N/A'),
|
23 |
}
|
24 |
|
25 |
-
# 사용 가능한 모든 포맷 중 가장 높은 품질의 mp4 찾기
|
26 |
formats = info.get('formats', [])
|
27 |
-
best_mp4 = max((f for f in formats if f['ext'] == 'mp4'), key=lambda x: x.get('quality', 0), default=None)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
except Exception as e:
|
36 |
-
return f"오류 발생: {str(e)}",
|
|
|
|
|
|
|
37 |
|
38 |
def on_download_click(url):
|
39 |
return f'<script>window.location.href = "{url}";</script>'
|
@@ -45,16 +57,22 @@ with gr.Blocks() as demo:
|
|
45 |
youtube_url_input = gr.Textbox(label="YouTube URL 입력")
|
46 |
extract_button = gr.Button("정보 추출")
|
47 |
output = gr.Textbox(label="추출된 정보", lines=10)
|
48 |
-
|
|
|
49 |
|
50 |
extract_button.click(
|
51 |
fn=extract_info,
|
52 |
inputs=youtube_url_input,
|
53 |
-
outputs=[output,
|
|
|
|
|
|
|
|
|
|
|
54 |
)
|
55 |
-
|
56 |
fn=on_download_click,
|
57 |
-
inputs=
|
58 |
outputs=gr.HTML()
|
59 |
)
|
60 |
|
|
|
22 |
"길이 (초)": info.get('duration', 'N/A'),
|
23 |
}
|
24 |
|
|
|
25 |
formats = info.get('formats', [])
|
|
|
26 |
|
27 |
+
# 최고 품질의 mp4 (비디오만)
|
28 |
+
best_video_only = max((f for f in formats if f['ext'] == 'mp4' and f.get('vcodec') != 'none' and f.get('acodec') == 'none'),
|
29 |
+
key=lambda x: x.get('height', 0), default=None)
|
30 |
+
|
31 |
+
# 최고 품질의 통합 스트림 (비디오+오디오)
|
32 |
+
best_combined = max((f for f in formats if f['ext'] == 'mp4' and f.get('vcodec') != 'none' and f.get('acodec') != 'none'),
|
33 |
+
key=lambda x: x.get('height', 0), default=None)
|
34 |
+
|
35 |
+
metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
|
36 |
+
|
37 |
+
video_only_url = best_video_only['url'] if best_video_only else None
|
38 |
+
combined_url = best_combined['url'] if best_combined else None
|
39 |
+
|
40 |
+
return (metadata_str,
|
41 |
+
video_only_url, combined_url,
|
42 |
+
gr.update(visible=bool(video_only_url)),
|
43 |
+
gr.update(visible=bool(combined_url)))
|
44 |
except Exception as e:
|
45 |
+
return (f"오류 발생: {str(e)}",
|
46 |
+
None, None,
|
47 |
+
gr.update(visible=False),
|
48 |
+
gr.update(visible=False))
|
49 |
|
50 |
def on_download_click(url):
|
51 |
return f'<script>window.location.href = "{url}";</script>'
|
|
|
57 |
youtube_url_input = gr.Textbox(label="YouTube URL 입력")
|
58 |
extract_button = gr.Button("정보 추출")
|
59 |
output = gr.Textbox(label="추출된 정보", lines=10)
|
60 |
+
video_only_button = gr.Button("비디오만 다운로드", visible=False)
|
61 |
+
combined_button = gr.Button("비디오+오디오 다운로드", visible=False)
|
62 |
|
63 |
extract_button.click(
|
64 |
fn=extract_info,
|
65 |
inputs=youtube_url_input,
|
66 |
+
outputs=[output, video_only_button, combined_button, video_only_button, combined_button]
|
67 |
+
)
|
68 |
+
video_only_button.click(
|
69 |
+
fn=on_download_click,
|
70 |
+
inputs=video_only_button,
|
71 |
+
outputs=gr.HTML()
|
72 |
)
|
73 |
+
combined_button.click(
|
74 |
fn=on_download_click,
|
75 |
+
inputs=combined_button,
|
76 |
outputs=gr.HTML()
|
77 |
)
|
78 |
|