JUNGU commited on
Commit
cf0c38d
·
verified ·
1 Parent(s): c0b7006

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -36
app.py CHANGED
@@ -32,21 +32,15 @@ def extract_info(youtube_url):
32
 
33
  metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
34
 
35
- video_only_url = best_video_only['url'] if best_video_only else None
36
- combined_url = best_combined['url'] if best_combined else None
37
 
38
- return (metadata_str,
39
- video_only_url, combined_url,
40
- gr.update(visible=bool(video_only_url)),
41
- gr.update(visible=bool(combined_url)))
42
- except Exception as e:
43
- return (f"오류 발생: {str(e)}",
44
- None, None,
45
- gr.update(visible=False),
46
- gr.update(visible=False))
47
 
48
- def on_download_click(url):
49
- return f'<script>window.location.href = "{url}";</script>'
50
 
51
  with gr.Blocks() as demo:
52
  gr.Markdown("## YouTube 메타데이터 및 다운로드 링크 추출기")
@@ -55,33 +49,12 @@ with gr.Blocks() as demo:
55
  youtube_url_input = gr.Textbox(label="YouTube URL 입력")
56
  extract_button = gr.Button("정보 추출")
57
  output = gr.Textbox(label="추출된 정보", lines=10)
58
- video_only_button = gr.Button("비디오만 다운로드", visible=False)
59
- combined_button = gr.Button("비디오+오디오 다운로드", visible=False)
60
-
61
- video_only_url = gr.State()
62
- combined_url = gr.State()
63
-
64
- def update_urls(metadata, video_url, combined_url, video_visibility, combined_visibility):
65
- return (metadata,
66
- gr.update(visible=video_visibility),
67
- gr.update(visible=combined_visibility),
68
- video_url,
69
- combined_url)
70
 
71
  extract_button.click(
72
  fn=extract_info,
73
  inputs=youtube_url_input,
74
- outputs=[output, video_only_button, combined_button, video_only_url, combined_url]
75
- )
76
- video_only_button.click(
77
- fn=on_download_click,
78
- inputs=video_only_url,
79
- outputs=gr.HTML()
80
- )
81
- combined_button.click(
82
- fn=on_download_click,
83
- inputs=combined_url,
84
- outputs=gr.HTML()
85
  )
86
 
87
  if __name__ == "__main__":
 
32
 
33
  metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
34
 
35
+ video_only_link = f'<a href="{best_video_only["url"]}" target="_blank">비디오만 다운로드</a>' if best_video_only else ""
36
+ combined_link = f'<a href="{best_combined["url"]}" target="_blank">비디오+오디오 다운로드</a>' if best_combined else ""
37
 
38
+ download_links = f"{video_only_link}<br>{combined_link}" if video_only_link or combined_link else "다운로드 링크를 찾을 수 없습니다."
39
+
40
+ return metadata_str, download_links
 
 
 
 
 
 
41
 
42
+ except Exception as e:
43
+ return f"오류 발생: {str(e)}", "다운로드 링크를 찾을 수 없습니다."
44
 
45
  with gr.Blocks() as demo:
46
  gr.Markdown("## YouTube 메타데이터 및 다운로드 링크 추출기")
 
49
  youtube_url_input = gr.Textbox(label="YouTube URL 입력")
50
  extract_button = gr.Button("정보 추출")
51
  output = gr.Textbox(label="추출된 정보", lines=10)
52
+ download_links = gr.HTML(label="다운로드 링크")
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  extract_button.click(
55
  fn=extract_info,
56
  inputs=youtube_url_input,
57
+ outputs=[output, download_links]
 
 
 
 
 
 
 
 
 
 
58
  )
59
 
60
  if __name__ == "__main__":