mguven61 commited on
Commit
a3641a5
·
verified ·
1 Parent(s): 087ac8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -17,24 +17,33 @@ def download_youtube_audio(url):
17
  temp_dir = tempfile.gettempdir()
18
  temp_file = os.path.join(temp_dir, 'temp_audio.wav')
19
 
 
20
  ydl_opts = {
21
  'format': 'bestaudio/best',
22
- 'postprocessors': [{
23
- 'key': 'FFmpegExtractAudio',
24
- 'preferredcodec': 'wav',
25
- }],
26
  'outtmpl': temp_file.replace('.wav', ''),
27
  'quiet': True,
28
  'no_warnings': True,
29
- 'extract_flat': True, # Sadece ses indir
30
- 'noplaylist': True, # Playlist değil
31
- 'no_warnings': True,
32
- 'ignoreerrors': True
 
 
 
33
  }
34
 
 
35
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
36
  logger.debug("Starting download...")
37
- ydl.download([url])
 
 
 
 
 
 
 
 
38
  logger.debug(f"Download complete. File saved to: {temp_file}")
39
 
40
  if os.path.exists(temp_file):
 
17
  temp_dir = tempfile.gettempdir()
18
  temp_file = os.path.join(temp_dir, 'temp_audio.wav')
19
 
20
+ # Basit yt-dlp ayarları
21
  ydl_opts = {
22
  'format': 'bestaudio/best',
 
 
 
 
23
  'outtmpl': temp_file.replace('.wav', ''),
24
  'quiet': True,
25
  'no_warnings': True,
26
+ 'extract_flat': True,
27
+ 'noplaylist': True,
28
+ 'ignoreerrors': True,
29
+ 'postprocessors': [{
30
+ 'key': 'FFmpegExtractAudio',
31
+ 'preferredcodec': 'wav',
32
+ }]
33
  }
34
 
35
+ # İndirme işlemi
36
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
37
  logger.debug("Starting download...")
38
+ info = ydl.extract_info(url, download=True)
39
+ logger.debug(f"Download info: {info}")
40
+
41
+ # Dosya adını düzelt
42
+ if os.path.exists(temp_file.replace('.wav', '.webm')):
43
+ os.rename(temp_file.replace('.wav', '.webm'), temp_file)
44
+ elif os.path.exists(temp_file.replace('.wav', '.m4a')):
45
+ os.rename(temp_file.replace('.wav', '.m4a'), temp_file)
46
+
47
  logger.debug(f"Download complete. File saved to: {temp_file}")
48
 
49
  if os.path.exists(temp_file):