divython commited on
Commit
4b7eb7e
·
verified ·
1 Parent(s): 96d9c1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -3,22 +3,23 @@ import yt_dlp
3
  import whisper
4
  import tempfile
5
 
6
- def download_audio(url, cookies_path):
7
- with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as tmpfile:
8
- ydl_opts = {
9
- 'format': 'bestaudio/best',
10
- 'outtmpl': tmpfile.name,
11
- 'quiet': True,
12
- 'cookiefile': cookies_path,
13
- 'postprocessors': [{
14
- 'key': 'FFmpegExtractAudio',
15
- 'preferredcodec': 'mp3',
16
- 'preferredquality': '192',
17
- }]
18
- }
19
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
- ydl.download([url])
21
- return tmpfile.name
 
22
 
23
  def process_video(url, cookies_path):
24
  audio_file = download_audio(url, cookies_path)
 
3
  import whisper
4
  import tempfile
5
 
6
+ import os
7
+ import yt_dlp
8
+
9
+ def download_audio(url):
10
+ cookies_path = os.path.join(os.getenv('HF_HOME', '/home/user/app'), 'cookies.txt')
11
+ ydl_opts = {
12
+ 'format': 'bestaudio/best',
13
+ 'outtmpl': 'audio.%(ext)s',
14
+ 'postprocessors': [{
15
+ 'key': 'FFmpegExtractAudio',
16
+ 'preferredcodec': 'wav',
17
+ 'preferredquality': '192',
18
+ }],
19
+ 'cookiefile': cookies_path
20
+ }
21
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
22
+ ydl.download([url])
23
 
24
  def process_video(url, cookies_path):
25
  audio_file = download_audio(url, cookies_path)