sudo-soldier commited on
Commit
9588f0c
Β·
verified Β·
1 Parent(s): 7f30883

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
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
- if not video_filename:
64
- return "Error: Video file not found for Android ringtone.", None
65
-
66
- android_path = os.path.join(DOWNLOAD_FOLDER, 'AndroidRingtone.mp3')
67
- command = ['ffmpeg', '-y', '-i', video_filename, '-t', '20', '-q:a', '0', '-map', 'a', android_path]
68
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
69
- _, stderr = process.communicate()
70
-
71
- if process.returncode == 0 and os.path.exists(android_path):
72
- return "Android ringtone created successfully.", android_path
73
  else:
74
- return f"Error creating Android ringtone: {stderr.decode()}", None
75
  except Exception as e:
76
- return f"Exception during Android ringtone creation: {str(e)}", None
 
77
 
78
  def iphone_download():
79
  try:
80
- android_path = os.path.join(DOWNLOAD_FOLDER, 'AndroidRingtone.mp3')
81
- iphone_path = os.path.join(DOWNLOAD_FOLDER, 'iPhoneRingtone.m4r')
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
- _, stderr = process.communicate()
92
 
93
- if process.returncode == 0 and os.path.exists(iphone_path):
94
- return "iPhone ringtone created successfully.", iphone_path
95
  else:
96
  return f"Error creating iPhone ringtone: {stderr.decode()}", None
97
  except Exception as e:
98
- return f"Exception during iPhone ringtone creation: {str(e)}", None
 
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(fn=android_download, outputs=[status_output, android_download_link])
126
- iphone_button.click(fn=iphone_download, outputs=[status_output, iphone_download_link])
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