Spaces:
Running
Running
this is my own fault
Browse files
app.py
CHANGED
@@ -77,7 +77,17 @@ def download_and_convert_youtube_audio(url: str) -> str:
|
|
77 |
Returns the path to the final temporary WAV file.
|
78 |
"""
|
79 |
temp_dir = tempfile.mkdtemp()
|
|
|
80 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
output_tmpl = os.path.join(temp_dir, "audio.%(ext)s")
|
82 |
ydl_opts = {
|
83 |
"format": "bestaudio/best",
|
@@ -91,6 +101,10 @@ def download_and_convert_youtube_audio(url: str) -> str:
|
|
91 |
},
|
92 |
"quiet": True,
|
93 |
}
|
|
|
|
|
|
|
|
|
94 |
|
95 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
96 |
ydl.download([url])
|
@@ -108,6 +122,9 @@ def download_and_convert_youtube_audio(url: str) -> str:
|
|
108 |
|
109 |
return dest_path
|
110 |
finally:
|
|
|
|
|
|
|
111 |
shutil.rmtree(temp_dir)
|
112 |
|
113 |
def handle_transcription(file, url):
|
|
|
77 |
Returns the path to the final temporary WAV file.
|
78 |
"""
|
79 |
temp_dir = tempfile.mkdtemp()
|
80 |
+
cookie_file_path = None
|
81 |
try:
|
82 |
+
# Check for YouTube cookies in secrets and write to a temporary file
|
83 |
+
youtube_cookies = os.environ.get("YOUTUBE_COOKIES")
|
84 |
+
if youtube_cookies:
|
85 |
+
# Use NamedTemporaryFile to handle the file creation and cleanup
|
86 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as tmp_cookie_file:
|
87 |
+
tmp_cookie_file.write(youtube_cookies)
|
88 |
+
cookie_file_path = tmp_cookie_file.name
|
89 |
+
print("Using YouTube cookies from secrets.")
|
90 |
+
|
91 |
output_tmpl = os.path.join(temp_dir, "audio.%(ext)s")
|
92 |
ydl_opts = {
|
93 |
"format": "bestaudio/best",
|
|
|
101 |
},
|
102 |
"quiet": True,
|
103 |
}
|
104 |
+
|
105 |
+
# Add cookiefile to options if it exists
|
106 |
+
if cookie_file_path:
|
107 |
+
ydl_opts['cookiefile'] = cookie_file_path
|
108 |
|
109 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
110 |
ydl.download([url])
|
|
|
122 |
|
123 |
return dest_path
|
124 |
finally:
|
125 |
+
# Clean up the cookie file if it was created
|
126 |
+
if cookie_file_path and os.path.exists(cookie_file_path):
|
127 |
+
os.remove(cookie_file_path)
|
128 |
shutil.rmtree(temp_dir)
|
129 |
|
130 |
def handle_transcription(file, url):
|