Escapingmatrixtoday commited on
Commit
3c02e14
·
verified ·
1 Parent(s): b59d558

Fix the generate button and it's functions, and terminate bugs if any

Browse files
Files changed (1) hide show
  1. index.html +88 -46
index.html CHANGED
@@ -258,60 +258,102 @@
258
  youtubeTab.classList.remove('active-tab', 'text-primary', 'dark:text-primary', 'border-primary');
259
  document.getElementById('video-url').placeholder = 'https://www.tiktok.com/@username/video/...';
260
  });
261
-
262
- // Simulate transcript generation
263
- document.getElementById('generate-btn').addEventListener('click', () => {
264
- const url = document.getElementById('video-url').value;
 
 
 
265
 
266
  if (!url) {
267
  alert('Please enter a valid YouTube or TikTok URL');
268
  return;
269
  }
270
 
271
- // Show loading state
272
- document.getElementById('empty-state').classList.add('hidden');
273
- document.getElementById('status-container').classList.remove('hidden');
274
- document.getElementById('results-container').classList.add('hidden');
275
- // Fetch transcript and video info
276
- fetch(`https://api.example.com/video-info?url=${encodeURIComponent(url)}`)
277
- .then(response => response.json())
278
- .then(data => {
279
- document.getElementById('status-container').classList.add('hidden');
280
- document.getElementById('results-container').classList.remove('hidden');
281
-
282
- // Update video info
283
- document.getElementById('video-title').textContent = data.title || 'Unknown';
284
- document.getElementById('video-duration').textContent = data.duration || 'Unknown';
285
- document.getElementById('processing-time').textContent = `${(Math.random() * 2 + 1).toFixed(2)} seconds`;
286
- // Sample transcript (in a real app this would come from an API)
287
- // Fetch actual transcript from API (mock implementation)
288
- fetch(`https://api.example.com/transcript?url=${encodeURIComponent(url)}`)
289
- .then(response => response.json())
290
- .then(data => {
291
- let fullTranscript = '';
292
- data.transcript.forEach(entry => {
293
- fullTranscript += `<p><strong>[${entry.timestamp}]</strong> ${entry.text}</p>`;
294
- });
295
- document.getElementById('transcript-content').innerHTML = fullTranscript;
296
- })
297
- .catch(error => {
298
- console.error('Error fetching transcript:', error);
299
- document.getElementById('transcript-content').innerHTML = `
300
- <p class="text-red-500">Error: Could not fetch transcript. Please try again.</p>
301
- `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  });
303
- document.getElementById('transcript-content').innerHTML = fullTranscript;
304
- document.getElementById('word-count').textContent = fullTranscript.split(/\s+/).length;
305
- })
306
- .catch(error => {
307
- console.error('Error fetching video info:', error);
308
- document.getElementById('status-container').classList.add('hidden');
309
- document.getElementById('empty-state').classList.remove('hidden');
310
- alert('Error processing video. Please try again.');
311
- });
312
- });
313
 
314
- // Copy functionality
 
 
 
 
 
 
 
 
 
315
  document.getElementById('copy-btn').addEventListener('click', () => {
316
  const transcriptText = document.getElementById('transcript-content').textContent;
317
  navigator.clipboard.writeText(transcriptText).then(() => {
 
258
  youtubeTab.classList.remove('active-tab', 'text-primary', 'dark:text-primary', 'border-primary');
259
  document.getElementById('video-url').placeholder = 'https://www.tiktok.com/@username/video/...';
260
  });
261
+ // Transcript generation
262
+ document.getElementById('generate-btn').addEventListener('click', async () => {
263
+ const url = document.getElementById('video-url').value.trim();
264
+ const urlPatterns = {
265
+ youtube: /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+/,
266
+ tiktok: /^(https?:\/\/)?(www\.)?tiktok\.com\/.+\/video\/.+/
267
+ };
268
 
269
  if (!url) {
270
  alert('Please enter a valid YouTube or TikTok URL');
271
  return;
272
  }
273
 
274
+ if (!urlPatterns.youtube.test(url) && !urlPatterns.tiktok.test(url)) {
275
+ alert('Please enter a valid YouTube or TikTok URL');
276
+ return;
277
+ }
278
+
279
+ try {
280
+ // Show loading state
281
+ document.getElementById('empty-state').classList.add('hidden');
282
+ document.getElementById('status-container').classList.remove('hidden');
283
+ document.getElementById('results-container').classList.add('hidden');
284
+ document.getElementById('generate-btn').disabled = true;
285
+
286
+ // Mock API call - replace with actual API endpoint
287
+ const [videoInfo, transcriptData] = await Promise.all([
288
+ fetchVideoInfo(url),
289
+ fetchTranscript(url)
290
+ ]);
291
+
292
+ // Update UI
293
+ document.getElementById('status-container').classList.add('hidden');
294
+ document.getElementById('results-container').classList.remove('hidden');
295
+
296
+ // Update video info
297
+ document.getElementById('video-title').textContent = videoInfo.title || 'Unknown';
298
+ document.getElementById('video-duration').textContent = videoInfo.duration || 'Unknown';
299
+ document.getElementById('processing-time').textContent = videoInfo.processingTime || 'Unknown';
300
+
301
+ // Update transcript
302
+ const fullTranscript = formatTranscript(transcriptData);
303
+ document.getElementById('transcript-content').innerHTML = fullTranscript;
304
+ document.getElementById('word-count').textContent = countWords(fullTranscript);
305
+
306
+ } catch (error) {
307
+ console.error('Error:', error);
308
+ document.getElementById('status-container').classList.add('hidden');
309
+ document.getElementById('results-container').classList.add('hidden');
310
+ document.getElementById('empty-state').classList.remove('hidden');
311
+ alert('Error processing video. Please try again.');
312
+ } finally {
313
+ document.getElementById('generate-btn').disabled = false;
314
+ }
315
+ });
316
+
317
+ // Helper functions
318
+ async function fetchVideoInfo(url) {
319
+ // Mock implementation - replace with actual API call
320
+ return new Promise(resolve => {
321
+ setTimeout(() => {
322
+ resolve({
323
+ title: 'Sample Video Title',
324
+ duration: '5:30',
325
+ processingTime: `${(Math.random() * 2 + 1).toFixed(2)} seconds`
326
+ });
327
+ }, 500);
328
+ });
329
+ }
330
+
331
+ async function fetchTranscript(url) {
332
+ // Mock implementation - replace with actual API call
333
+ return new Promise(resolve => {
334
+ setTimeout(() => {
335
+ const mockTranscript = [];
336
+ for (let i = 0; i < 10; i++) {
337
+ mockTranscript.push({
338
+ timestamp: `00:${i.toString().padStart(2, '0')}`,
339
+ text: `This is sample transcript line ${i + 1} for demonstration purposes.`
340
  });
341
+ }
342
+ resolve(mockTranscript);
343
+ }, 1000);
344
+ });
345
+ }
 
 
 
 
 
346
 
347
+ function formatTranscript(data) {
348
+ return data.map(entry =>
349
+ `<p><strong>[${entry.timestamp}]</strong> ${entry.text}</p>`
350
+ ).join('');
351
+ }
352
+
353
+ function countWords(text) {
354
+ return text.split(/\s+/).filter(word => word.length > 0).length;
355
+ }
356
+ // Copy functionality
357
  document.getElementById('copy-btn').addEventListener('click', () => {
358
  const transcriptText = document.getElementById('transcript-content').textContent;
359
  navigator.clipboard.writeText(transcriptText).then(() => {