Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,19 +16,19 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
16 |
filename = None
|
17 |
song_name = None
|
18 |
|
19 |
-
|
20 |
if url:
|
21 |
ydl_opts = {
|
22 |
'format': 'bestaudio/best',
|
23 |
'outtmpl': 'downloads/%(id)s.%(ext)s',
|
24 |
-
'cookiefile': 'cookies.txt' #
|
25 |
}
|
26 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
27 |
info = ydl.extract_info(url, download=True)
|
28 |
filename = os.path.join('downloads', f"{info['id']}.webm")
|
29 |
song_name = sanitize_filename(info['title'])
|
30 |
|
31 |
-
|
32 |
elif recorded_audio:
|
33 |
filename = recorded_audio
|
34 |
song_name = "recorded_audio"
|
@@ -36,13 +36,13 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
36 |
if not filename or not os.path.exists(filename):
|
37 |
return None, None
|
38 |
|
39 |
-
|
40 |
mp3_filename = f"downloads/{song_name}.mp3"
|
41 |
if not os.path.exists(mp3_filename):
|
42 |
audio = AudioSegment.from_file(filename)
|
43 |
audio.export(mp3_filename, format="mp3")
|
44 |
|
45 |
-
|
46 |
ringtone_filename_m4r = f"downloads/{song_name}.m4r"
|
47 |
if not os.path.exists(ringtone_filename_m4r):
|
48 |
ringtone_audio = AudioSegment.from_file(mp3_filename)[:20000] # 20 seconds
|
|
|
16 |
filename = None
|
17 |
song_name = None
|
18 |
|
19 |
+
|
20 |
if url:
|
21 |
ydl_opts = {
|
22 |
'format': 'bestaudio/best',
|
23 |
'outtmpl': 'downloads/%(id)s.%(ext)s',
|
24 |
+
'cookiefile': 'cookies.txt' #cookies.txt
|
25 |
}
|
26 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
27 |
info = ydl.extract_info(url, download=True)
|
28 |
filename = os.path.join('downloads', f"{info['id']}.webm")
|
29 |
song_name = sanitize_filename(info['title'])
|
30 |
|
31 |
+
|
32 |
elif recorded_audio:
|
33 |
filename = recorded_audio
|
34 |
song_name = "recorded_audio"
|
|
|
36 |
if not filename or not os.path.exists(filename):
|
37 |
return None, None
|
38 |
|
39 |
+
|
40 |
mp3_filename = f"downloads/{song_name}.mp3"
|
41 |
if not os.path.exists(mp3_filename):
|
42 |
audio = AudioSegment.from_file(filename)
|
43 |
audio.export(mp3_filename, format="mp3")
|
44 |
|
45 |
+
|
46 |
ringtone_filename_m4r = f"downloads/{song_name}.m4r"
|
47 |
if not os.path.exists(ringtone_filename_m4r):
|
48 |
ringtone_audio = AudioSegment.from_file(mp3_filename)[:20000] # 20 seconds
|