Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from pydub import AudioSegment
|
|
5 |
import re
|
6 |
import subprocess
|
7 |
|
8 |
-
|
9 |
if not os.path.exists("downloads"):
|
10 |
os.makedirs("downloads")
|
11 |
|
@@ -18,7 +18,7 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
18 |
filename = None
|
19 |
song_name = None
|
20 |
|
21 |
-
|
22 |
if url:
|
23 |
ydl_opts = {
|
24 |
'format': 'bestaudio/best',
|
@@ -38,24 +38,24 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
38 |
if not filename or not os.path.exists(filename):
|
39 |
return None, None
|
40 |
|
41 |
-
|
42 |
audio = AudioSegment.from_file(filename)
|
43 |
|
44 |
-
|
45 |
if len(audio) > 20000:
|
46 |
audio = audio[:20000]
|
47 |
|
48 |
-
|
49 |
mp3_filename = f"downloads/{song_name}.mp3"
|
50 |
audio.export(mp3_filename, format="mp3")
|
51 |
|
52 |
-
|
53 |
m4a_filename = f"downloads/{song_name}.m4a"
|
54 |
subprocess.run([
|
55 |
'ffmpeg', '-i', mp3_filename, '-vn', '-acodec', 'aac', '-b:a', '192k', m4a_filename
|
56 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
57 |
|
58 |
-
|
59 |
m4r_filename = f"downloads/{song_name}.m4r"
|
60 |
os.rename(m4a_filename, m4r_filename)
|
61 |
|
@@ -84,8 +84,9 @@ with gr.Blocks(css="""
|
|
84 |
<h1><i class="fas fa-music"></i> PYTR</h1>
|
85 |
<p>Python YouTube Ringtones. Enter a YouTube URL or record audio to create ringtones.</p>
|
86 |
<p>
|
87 |
-
<a href="https://ringtone.JesseJesse.xyz" target="_blank">
|
88 |
<a href="https://sudo-self.github.io/pytr/" target="_blank">GitHub</a>
|
|
|
89 |
</p>
|
90 |
""")
|
91 |
|
@@ -99,7 +100,7 @@ with gr.Blocks(css="""
|
|
99 |
audio_record = gr.Audio(sources=["microphone"], type="filepath", show_label=False)
|
100 |
|
101 |
with gr.Row():
|
102 |
-
process_button = gr.Button("
|
103 |
|
104 |
with gr.Row():
|
105 |
with gr.Column(scale=1, min_width=250):
|
|
|
5 |
import re
|
6 |
import subprocess
|
7 |
|
8 |
+
|
9 |
if not os.path.exists("downloads"):
|
10 |
os.makedirs("downloads")
|
11 |
|
|
|
18 |
filename = None
|
19 |
song_name = None
|
20 |
|
21 |
+
|
22 |
if url:
|
23 |
ydl_opts = {
|
24 |
'format': 'bestaudio/best',
|
|
|
38 |
if not filename or not os.path.exists(filename):
|
39 |
return None, None
|
40 |
|
41 |
+
|
42 |
audio = AudioSegment.from_file(filename)
|
43 |
|
44 |
+
|
45 |
if len(audio) > 20000:
|
46 |
audio = audio[:20000]
|
47 |
|
48 |
+
|
49 |
mp3_filename = f"downloads/{song_name}.mp3"
|
50 |
audio.export(mp3_filename, format="mp3")
|
51 |
|
52 |
+
|
53 |
m4a_filename = f"downloads/{song_name}.m4a"
|
54 |
subprocess.run([
|
55 |
'ffmpeg', '-i', mp3_filename, '-vn', '-acodec', 'aac', '-b:a', '192k', m4a_filename
|
56 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
57 |
|
58 |
+
|
59 |
m4r_filename = f"downloads/{song_name}.m4r"
|
60 |
os.rename(m4a_filename, m4r_filename)
|
61 |
|
|
|
84 |
<h1><i class="fas fa-music"></i> PYTR</h1>
|
85 |
<p>Python YouTube Ringtones. Enter a YouTube URL or record audio to create ringtones.</p>
|
86 |
<p>
|
87 |
+
<a href="https://ringtone.JesseJesse.xyz" target="_blank">JesseJesse.xyz</a>
|
88 |
<a href="https://sudo-self.github.io/pytr/" target="_blank">GitHub</a>
|
89 |
+
<a href="https://youtube.com" target="_blank">YouTube</a>
|
90 |
</p>
|
91 |
""")
|
92 |
|
|
|
100 |
audio_record = gr.Audio(sources=["microphone"], type="filepath", show_label=False)
|
101 |
|
102 |
with gr.Row():
|
103 |
+
process_button = gr.Button("Create Ringtones", elem_classes="light-btn")
|
104 |
|
105 |
with gr.Row():
|
106 |
with gr.Column(scale=1, min_width=250):
|