JUNGU commited on
Commit
753ecf1
1 Parent(s): 2cca49c

Update youtube_extractor.py

Browse files
Files changed (1) hide show
  1. youtube_extractor.py +26 -10
youtube_extractor.py CHANGED
@@ -6,9 +6,6 @@ class YouTubeExtractor:
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
 
14
  def extract_info(self, youtube_url):
@@ -26,23 +23,42 @@ class YouTubeExtractor:
26
 
27
  formats = info.get('formats', [])
28
 
29
- best_video_only = next((f for f in formats if f['ext'] == 'mp4' and f.get('vcodec') != 'none' and f.get('acodec') == 'none'), None)
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
- return metadata, best_video_only, combined
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  except Exception as e:
35
- return None, None, None
36
 
37
- def format_output(self, metadata, best_video_only, combined):
38
  if not metadata:
39
  return "오류 발생: 메타데이터를 추출할 수 없습니다.", "다운로드 링크를 찾을 수 없습니다."
40
 
41
  metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
42
 
43
  video_only_link = f'<a href="{best_video_only["url"]}" target="_blank">비디오만 다운로드</a>' if best_video_only else ""
44
- combined_link = f'<a href="{combined["url"]}" target="_blank">비디오+오디오 다운로드</a>' if combined else ""
 
45
 
46
- download_links = f"{video_only_link}<br>{combined_link}" if video_only_link or combined_link else "다운로드 링크를 찾을 수 없습니다."
47
 
48
  return metadata_str, download_links
 
6
  'quiet': True,
7
  'no_warnings': True,
8
  'no_color': True,
 
 
 
9
  }
10
 
11
  def extract_info(self, youtube_url):
 
23
 
24
  formats = info.get('formats', [])
25
 
26
+ # 비디오 전용 (가장 높은 해상도)
27
+ best_video_only = max(
28
+ (f for f in formats if f.get('vcodec') != 'none' and f.get('acodec') == 'none'),
29
+ key=lambda x: x.get('height', 0),
30
+ default=None
31
+ )
32
 
33
+ # 오디오 전용 (가장 높은 비트레이트)
34
+ best_audio_only = max(
35
+ (f for f in formats if f.get('acodec') != 'none' and f.get('vcodec') == 'none'),
36
+ key=lambda x: x.get('abr', 0),
37
+ default=None
38
+ )
39
+
40
+ # 비디오+오디오 결합 (가장 높은 해상도)
41
+ best_combined = max(
42
+ (f for f in formats if f.get('vcodec') != 'none' and f.get('acodec') != 'none'),
43
+ key=lambda x: x.get('height', 0),
44
+ default=None
45
+ )
46
+
47
+ return metadata, best_video_only, best_audio_only, best_combined
48
 
49
  except Exception as e:
50
+ return None, None, None, None
51
 
52
+ def format_output(self, metadata, best_video_only, best_audio_only, best_combined):
53
  if not metadata:
54
  return "오류 발생: 메타데이터를 추출할 수 없습니다.", "다운로드 링크를 찾을 수 없습니다."
55
 
56
  metadata_str = "\n".join([f"{k}: {v}" for k, v in metadata.items()])
57
 
58
  video_only_link = f'<a href="{best_video_only["url"]}" target="_blank">비디오만 다운로드</a>' if best_video_only else ""
59
+ audio_only_link = f'<a href="{best_audio_only["url"]}" target="_blank">오디오만 다운로드</a>' if best_audio_only else ""
60
+ combined_link = f'<a href="{best_combined["url"]}" target="_blank">비디오+오디오 다운로드</a>' if best_combined else ""
61
 
62
+ download_links = f"{video_only_link}<br>{audio_only_link}<br>{combined_link}" if any([video_only_link, audio_only_link, combined_link]) else "다운로드 링크를 찾을 수 없습니다."
63
 
64
  return metadata_str, download_links