Ivan000 commited on
Commit
9ce10a6
·
verified ·
1 Parent(s): 8fa34d8

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +19 -17
templates/index.html CHANGED
@@ -65,11 +65,11 @@
65
  </div>
66
  </div>
67
 
68
- <!-- Download Button -->
69
- <button onclick="downloadAudio()"
70
  class="w-full bg-green-500 hover:bg-green-600 active:bg-green-700 text-white py-4 px-6 rounded-xl transition-all duration-300 flex items-center justify-center space-x-2 font-medium focus:outline-none focus:ring-2 focus:ring-green-500/50 focus:ring-offset-2 dark:ring-offset-gray-800 mt-4">
71
- <i class="fas fa-download text-sm"></i>
72
- <span>Download MP3</span>
73
  </button>
74
  </div>
75
  </div>
@@ -164,14 +164,14 @@
164
  });
165
  }
166
 
167
- function downloadAudio() {
168
  const url = $('#youtubeUrl').val().trim();
169
  if (!url) {
170
  showError('Please enter a YouTube URL');
171
  return;
172
  }
173
 
174
- showLoading('Preparing your download...');
175
 
176
  $.ajax({
177
  url: '/download',
@@ -183,20 +183,23 @@
183
  },
184
  success: function(response) {
185
  const blob = new Blob([response], { type: 'audio/mp3' });
186
- const downloadUrl = window.URL.createObjectURL(blob);
187
- const a = document.createElement('a');
188
- a.style.display = 'none';
189
- a.href = downloadUrl;
190
- a.download = $('#videoTitle').text() + '.mp3';
191
- document.body.appendChild(a);
192
- a.click();
193
- window.URL.revokeObjectURL(downloadUrl);
 
 
 
194
  Swal.close();
195
- showSuccess('Download started');
196
  },
197
  error: function(xhr) {
198
  Swal.close();
199
- showError('Download failed');
200
  }
201
  });
202
  }
@@ -217,6 +220,5 @@
217
  document.documentElement.classList.add('dark');
218
  }
219
  </script>
220
- </head>
221
  </body>
222
  </html>
 
65
  </div>
66
  </div>
67
 
68
+ <!-- Play Audio Button -->
69
+ <button onclick="playAudio()"
70
  class="w-full bg-green-500 hover:bg-green-600 active:bg-green-700 text-white py-4 px-6 rounded-xl transition-all duration-300 flex items-center justify-center space-x-2 font-medium focus:outline-none focus:ring-2 focus:ring-green-500/50 focus:ring-offset-2 dark:ring-offset-gray-800 mt-4">
71
+ <i class="fas fa-play text-sm"></i>
72
+ <span>Start Listening</span>
73
  </button>
74
  </div>
75
  </div>
 
164
  });
165
  }
166
 
167
+ function playAudio() {
168
  const url = $('#youtubeUrl').val().trim();
169
  if (!url) {
170
  showError('Please enter a YouTube URL');
171
  return;
172
  }
173
 
174
+ showLoading('Preparing audio...');
175
 
176
  $.ajax({
177
  url: '/download',
 
183
  },
184
  success: function(response) {
185
  const blob = new Blob([response], { type: 'audio/mp3' });
186
+ const audioUrl = URL.createObjectURL(blob);
187
+
188
+ const audioPlayer = document.createElement('audio');
189
+ audioPlayer.src = audioUrl;
190
+ audioPlayer.controls = true;
191
+ audioPlayer.style.width = '100%';
192
+ audioPlayer.style.marginTop = '1rem';
193
+
194
+ const videoInfoContainer = document.querySelector('#videoInfo .p-6');
195
+ videoInfoContainer.appendChild(audioPlayer);
196
+
197
  Swal.close();
198
+ showSuccess('Audio is ready to play');
199
  },
200
  error: function(xhr) {
201
  Swal.close();
202
+ showError('Failed to prepare audio');
203
  }
204
  });
205
  }
 
220
  document.documentElement.classList.add('dark');
221
  }
222
  </script>
 
223
  </body>
224
  </html>