JUNGU commited on
Commit
6b782ad
·
verified ·
1 Parent(s): 4ddbe7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -2,7 +2,14 @@ import gradio as gr
2
  import yt_dlp
3
 
4
  def extract_info(youtube_url):
5
- ydl_opts = {'quiet': True}
 
 
 
 
 
 
 
6
  try:
7
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
8
  info = ydl.extract_info(youtube_url, download=False)
@@ -12,13 +19,13 @@ def extract_info(youtube_url):
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
- # 최고 품질의 mp4 형식 찾기
21
- best_mp4 = next((f for f in info['formats'] if f['ext'] == 'mp4' and f.get('quality') == 1), None)
 
 
22
  if best_mp4:
23
  metadata["다운로드 URL"] = best_mp4['url']
24
  else:
@@ -28,15 +35,7 @@ def extract_info(youtube_url):
28
  except Exception as e:
29
  return f"오류 발생: {str(e)}"
30
 
31
- with gr.Blocks() as demo:
32
- gr.Markdown("## YouTube 메타데이터 및 다운로드 링크 추출기")
33
- gr.Markdown("주의: 이 도구를 사용하여 저작권이 있는 콘텐츠를 무단으로 다운로드하는 것은 불법입니다.")
34
-
35
- youtube_url_input = gr.Textbox(label="YouTube URL 입력")
36
- extract_button = gr.Button("정보 추출")
37
- output = gr.Textbox(label="추출된 정보", lines=10)
38
-
39
- extract_button.click(fn=extract_info, inputs=youtube_url_input, outputs=output)
40
 
41
  if __name__ == "__main__":
42
  demo.launch()
 
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)
 
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
+ # 사용 가능한 모든 포맷 중 가장 높은 품질의 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
  if best_mp4:
30
  metadata["다운로드 URL"] = best_mp4['url']
31
  else:
 
35
  except Exception as e:
36
  return f"오류 발생: {str(e)}"
37
 
38
+ # Gradio 인터페이스 코드는 이전과 동일
 
 
 
 
 
 
 
 
39
 
40
  if __name__ == "__main__":
41
  demo.launch()