JUNGU commited on
Commit
6221a29
·
verified ·
1 Parent(s): 2815236

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -41
app.py CHANGED
@@ -1,45 +1,11 @@
1
  import gradio as gr
2
- import yt_dlp
3
 
4
- def extract_info(youtube_url):
5
- ydl_opts = {
6
- 'quiet': True,
7
- 'no_warnings': True,
8
- 'no_color': True,
9
- 'youtube_include_dash_manifest': False,
10
- 'youtube_include_hls_manifest': False,
11
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
12
- }
13
- try:
14
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
15
- info = ydl.extract_info(youtube_url, download=False)
16
-
17
- metadata = {
18
- "제목": info.get('title', 'N/A'),
19
- "채널": info.get('channel', 'N/A'),
20
- "업로드 날짜": info.get('upload_date', 'N/A'),
21
- "조회수": info.get('view_count', 'N/A'),
22
- "길이 (초)": info.get('duration', 'N/A'),
23
- }
24
-
25
- formats = info.get('formats', [])
26
-
27
- best_video_only = next((f for f in formats if f['ext'] == 'mp4' and f.get('vcodec') != 'none' and f.get('acodec') == 'none'), None)
28
-
29
- # 간단히 비디오와 오디오가 모두 있는 첫 번째 mp4 포맷을 선택
30
- combined = next((f for f in formats if f['ext'] == 'mp4' and f.get('vcodec') != 'none' and f.get('acodec') != 'none'), None)
31
-
32
- metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
33
-
34
- video_only_link = f'<a href="{best_video_only["url"]}" target="_blank">비디오만 다운로드</a>' if best_video_only else ""
35
- combined_link = f'<a href="{combined["url"]}" target="_blank">비디오+오디오 다운로드</a>' if combined else ""
36
-
37
- download_links = f"{video_only_link}<br>{combined_link}" if video_only_link or combined_link else "다운로드 링크를 찾을 수 없습니다."
38
-
39
- return metadata_str, download_links
40
 
41
- except Exception as e:
42
- return f"오류 발생: {str(e)}", "다운로드 링크를 찾을 수 없습니다."
 
43
 
44
  with gr.Blocks() as demo:
45
  gr.Markdown("## YouTube 메타데이터 및 다운로드 링크 추출기")
@@ -51,8 +17,8 @@ with gr.Blocks() as demo:
51
  download_links = gr.HTML(label="다운로드 링크")
52
 
53
  extract_button.click(
54
- fn=extract_info,
55
- inputs=youtube_url_input,
56
  outputs=[output, download_links]
57
  )
58
 
 
1
  import gradio as gr
2
+ from youtube_extractor import YouTubeExtractor
3
 
4
+ extractor = YouTubeExtractor()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ def process_youtube_url(youtube_url):
7
+ metadata, best_video_only, combined = extractor.extract_info(youtube_url)
8
+ return extractor.format_output(metadata, best_video_only, combined)
9
 
10
  with gr.Blocks() as demo:
11
  gr.Markdown("## YouTube 메타데이터 및 다운로드 링크 추출기")
 
17
  download_links = gr.HTML(label="다운로드 링크")
18
 
19
  extract_button.click(
20
+ fn=process_youtube_url,
21
+ inputs=youtube_url_input,
22
  outputs=[output, download_links]
23
  )
24