Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -56,46 +56,41 @@ def download_video(url):
|
|
56 |
|
57 |
except Exception as e:
|
58 |
return f"Exception during video download: {str(e)}"
|
59 |
-
|
60 |
def android_download():
|
61 |
try:
|
62 |
-
video_filename = get_video_filename()
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
else:
|
74 |
-
return
|
75 |
except Exception as e:
|
76 |
-
return f"
|
|
|
77 |
|
78 |
def iphone_download():
|
79 |
try:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
if not os.path.exists(android_path):
|
84 |
-
return "Error: Android ringtone not found. Create it first.", None
|
85 |
-
|
86 |
-
command = [
|
87 |
-
'ffmpeg', '-y', '-i', android_path, '-t', '20',
|
88 |
-
'-acodec', 'aac', '-b:a', '128k', '-f', 'ipod', iphone_path
|
89 |
-
]
|
90 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
91 |
-
|
92 |
|
93 |
-
if process.returncode == 0
|
94 |
-
return "iPhone ringtone created successfully
|
95 |
else:
|
96 |
return f"Error creating iPhone ringtone: {stderr.decode()}", None
|
97 |
except Exception as e:
|
98 |
-
return f"
|
|
|
99 |
|
100 |
def paste_from_clipboard():
|
101 |
try:
|
@@ -107,6 +102,7 @@ def clear_input():
|
|
107 |
return "", ""
|
108 |
|
109 |
# Gradio UI
|
|
|
110 |
with gr.Blocks() as iface:
|
111 |
gr.Markdown("## π΅ YouTube Ringtone Creator")
|
112 |
url_input = gr.Textbox(label="Enter YouTube URL", placeholder="Paste URL here")
|
@@ -115,6 +111,11 @@ with gr.Blocks() as iface:
|
|
115 |
android_download_link = gr.File(label="Android Ringtone", interactive=False)
|
116 |
iphone_download_link = gr.File(label="iPhone Ringtone", interactive=False)
|
117 |
|
|
|
|
|
|
|
|
|
|
|
118 |
download_button = gr.Button("π₯ Download Video")
|
119 |
android_button = gr.Button("πΆ Create Android Ringtone")
|
120 |
iphone_button = gr.Button("π± Create iPhone Ringtone")
|
@@ -122,8 +123,8 @@ with gr.Blocks() as iface:
|
|
122 |
clear_button = gr.Button("π§Ή Clear")
|
123 |
|
124 |
download_button.click(fn=download_video, inputs=url_input, outputs=status_output)
|
125 |
-
android_button.click(
|
126 |
-
iphone_button.click(
|
127 |
paste_button.click(fn=paste_from_clipboard, outputs=url_input)
|
128 |
clear_button.click(fn=clear_input, outputs=[url_input, status_output])
|
129 |
|
|
|
56 |
|
57 |
except Exception as e:
|
58 |
return f"Exception during video download: {str(e)}"
|
59 |
+
|
60 |
def android_download():
|
61 |
try:
|
62 |
+
video_filename = get_video_filename(f'{DOWNLOAD_FOLDER}/%(title)s.mp4')
|
63 |
+
output_file = f'{DOWNLOAD_FOLDER}/AndroidRingtone.mp3'
|
64 |
+
if video_filename:
|
65 |
+
command = ['ffmpeg', '-i', video_filename, '-t', '20', '-q:a', '0', '-map', 'a', output_file]
|
66 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
67 |
+
stdout, stderr = process.communicate()
|
68 |
+
|
69 |
+
if process.returncode == 0:
|
70 |
+
return "Android ringtone created successfully", output_file
|
71 |
+
else:
|
72 |
+
return f"Error creating Android ringtone: {stderr.decode()}", None
|
73 |
else:
|
74 |
+
return "Error: Video file not found for Android ringtone.", None
|
75 |
except Exception as e:
|
76 |
+
return f"Failed to create Android ringtone: {str(e)}", None
|
77 |
+
|
78 |
|
79 |
def iphone_download():
|
80 |
try:
|
81 |
+
input_file = f'{DOWNLOAD_FOLDER}/AndroidRingtone.mp3'
|
82 |
+
output_file = f'{DOWNLOAD_FOLDER}/iPhoneRingtone.m4r'
|
83 |
+
command = ['ffmpeg', '-i', input_file, '-t', '20', '-acodec', 'aac', '-b:a', '128k', '-f', 'mp4', output_file]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
85 |
+
stdout, stderr = process.communicate()
|
86 |
|
87 |
+
if process.returncode == 0:
|
88 |
+
return "iPhone ringtone created successfully", output_file
|
89 |
else:
|
90 |
return f"Error creating iPhone ringtone: {stderr.decode()}", None
|
91 |
except Exception as e:
|
92 |
+
return f"Failed to create iPhone ringtone: {str(e)}", None
|
93 |
+
|
94 |
|
95 |
def paste_from_clipboard():
|
96 |
try:
|
|
|
102 |
return "", ""
|
103 |
|
104 |
# Gradio UI
|
105 |
+
|
106 |
with gr.Blocks() as iface:
|
107 |
gr.Markdown("## π΅ YouTube Ringtone Creator")
|
108 |
url_input = gr.Textbox(label="Enter YouTube URL", placeholder="Paste URL here")
|
|
|
111 |
android_download_link = gr.File(label="Android Ringtone", interactive=False)
|
112 |
iphone_download_link = gr.File(label="iPhone Ringtone", interactive=False)
|
113 |
|
114 |
+
|
115 |
+
android_file = gr.File(label="Download Android Ringtone (.mp3)")
|
116 |
+
iphone_file = gr.File(label="Download iPhone Ringtone (.m4r)")
|
117 |
+
|
118 |
+
|
119 |
download_button = gr.Button("π₯ Download Video")
|
120 |
android_button = gr.Button("πΆ Create Android Ringtone")
|
121 |
iphone_button = gr.Button("π± Create iPhone Ringtone")
|
|
|
123 |
clear_button = gr.Button("π§Ή Clear")
|
124 |
|
125 |
download_button.click(fn=download_video, inputs=url_input, outputs=status_output)
|
126 |
+
android_button.click(android_download, outputs=[status_output, android_file])
|
127 |
+
iphone_button.click(iphone_download, outputs=[status_output, iphone_file])
|
128 |
paste_button.click(fn=paste_from_clipboard, outputs=url_input)
|
129 |
clear_button.click(fn=clear_input, outputs=[url_input, status_output])
|
130 |
|