Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
import re
|
5 |
from pydub import AudioSegment
|
6 |
|
7 |
-
#
|
8 |
os.makedirs("downloads", exist_ok=True)
|
9 |
|
10 |
def sanitize_filename(filename):
|
@@ -27,7 +27,7 @@ def process_youtube_or_audio(url, uploaded_audio, start_time, end_time):
|
|
27 |
filename = ydl.prepare_filename(info)
|
28 |
song_name = sanitize_filename(info['title'])
|
29 |
|
30 |
-
|
31 |
if not filename.endswith(".m4a"):
|
32 |
possible_file = f"downloads/{song_name}.m4a"
|
33 |
if os.path.exists(possible_file):
|
@@ -50,11 +50,11 @@ def process_youtube_or_audio(url, uploaded_audio, start_time, end_time):
|
|
50 |
|
51 |
trimmed_audio = audio[start_ms:end_ms]
|
52 |
|
53 |
-
#
|
54 |
mp3_filename = f"downloads/{song_name}.mp3"
|
55 |
trimmed_audio.export(mp3_filename, format="mp3")
|
56 |
|
57 |
-
#
|
58 |
m4a_filename = filename
|
59 |
m4r_filename = f"downloads/{song_name}.m4r"
|
60 |
os.rename(m4a_filename, m4r_filename)
|
@@ -65,7 +65,7 @@ def process_youtube_or_audio(url, uploaded_audio, start_time, end_time):
|
|
65 |
print(f"Error: {e}")
|
66 |
return None, None
|
67 |
|
68 |
-
#
|
69 |
with gr.Blocks() as interface:
|
70 |
gr.HTML("""
|
71 |
<h1 style="font-size: 2rem; text-align: center;"><i class="fas fa-music"></i> PYTR - Python YouTube Ringtones</h1>
|
|
|
4 |
import re
|
5 |
from pydub import AudioSegment
|
6 |
|
7 |
+
#downloads directory
|
8 |
os.makedirs("downloads", exist_ok=True)
|
9 |
|
10 |
def sanitize_filename(filename):
|
|
|
27 |
filename = ydl.prepare_filename(info)
|
28 |
song_name = sanitize_filename(info['title'])
|
29 |
|
30 |
+
|
31 |
if not filename.endswith(".m4a"):
|
32 |
possible_file = f"downloads/{song_name}.m4a"
|
33 |
if os.path.exists(possible_file):
|
|
|
50 |
|
51 |
trimmed_audio = audio[start_ms:end_ms]
|
52 |
|
53 |
+
#MP3
|
54 |
mp3_filename = f"downloads/{song_name}.mp3"
|
55 |
trimmed_audio.export(mp3_filename, format="mp3")
|
56 |
|
57 |
+
#M4R
|
58 |
m4a_filename = filename
|
59 |
m4r_filename = f"downloads/{song_name}.m4r"
|
60 |
os.rename(m4a_filename, m4r_filename)
|
|
|
65 |
print(f"Error: {e}")
|
66 |
return None, None
|
67 |
|
68 |
+
#Gradio
|
69 |
with gr.Blocks() as interface:
|
70 |
gr.HTML("""
|
71 |
<h1 style="font-size: 2rem; text-align: center;"><i class="fas fa-music"></i> PYTR - Python YouTube Ringtones</h1>
|