The generate transcript button still not working. When I click the button nothing happens and no transcript is generated
Browse files- index.html +105 -35
index.html
CHANGED
|
@@ -268,7 +268,8 @@
|
|
| 268 |
// Set initial active tab
|
| 269 |
switchToYoutube();
|
| 270 |
// Transcript generation
|
| 271 |
-
document.getElementById('generate-btn').addEventListener('click', async () => {
|
|
|
|
| 272 |
const url = document.getElementById('video-url').value.trim();
|
| 273 |
const urlPatterns = {
|
| 274 |
youtube: /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+/,
|
|
@@ -284,7 +285,15 @@
|
|
| 284 |
alert('Please enter a valid YouTube or TikTok URL');
|
| 285 |
return;
|
| 286 |
}
|
|
|
|
|
|
|
| 287 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
// Show loading state
|
| 289 |
document.getElementById('empty-state').classList.add('hidden');
|
| 290 |
document.getElementById('status-container').classList.remove('hidden');
|
|
@@ -292,34 +301,54 @@
|
|
| 292 |
document.getElementById('generate-btn').disabled = true;
|
| 293 |
document.getElementById('generate-btn').innerHTML = '<i data-feather="loader" class="animate-spin w-5 h-5"></i> Processing...';
|
| 294 |
feather.replace();
|
| 295 |
-
|
| 296 |
// Simulate API call with timeout
|
| 297 |
const timeoutPromise = new Promise((_, reject) =>
|
| 298 |
setTimeout(() => reject(new Error('Request timeout')), 10000)
|
| 299 |
);
|
| 300 |
|
|
|
|
|
|
|
|
|
|
| 301 |
const apiPromise = Promise.all([
|
| 302 |
fetchVideoInfo(url),
|
| 303 |
fetchTranscript(url)
|
| 304 |
]);
|
| 305 |
|
| 306 |
const [videoInfo, transcriptData] = await Promise.race([apiPromise, timeoutPromise]);
|
| 307 |
-
|
| 308 |
-
|
| 309 |
document.getElementById('status-container').classList.add('hidden');
|
| 310 |
document.getElementById('results-container').classList.remove('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
-
// Update
|
| 313 |
-
document.getElementById('video-title').textContent = videoInfo.title || 'Unknown';
|
| 314 |
-
document.getElementById('video-duration').textContent = videoInfo.duration || 'Unknown';
|
| 315 |
-
document.getElementById('processing-time').textContent = videoInfo.processingTime || 'Unknown';
|
| 316 |
-
|
| 317 |
-
// Update transcript
|
| 318 |
const fullTranscript = formatTranscript(transcriptData);
|
| 319 |
-
document.getElementById('transcript-content')
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
| 323 |
console.error('Error:', error);
|
| 324 |
document.getElementById('status-container').classList.add('hidden');
|
| 325 |
document.getElementById('results-container').classList.add('hidden');
|
|
@@ -336,38 +365,56 @@
|
|
| 336 |
feather.replace();
|
| 337 |
}
|
| 338 |
});
|
| 339 |
-
|
| 340 |
// Helper functions
|
| 341 |
async function fetchVideoInfo(url) {
|
| 342 |
-
// Mock implementation
|
| 343 |
-
return new Promise(resolve => {
|
| 344 |
setTimeout(() => {
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
}, 500);
|
| 351 |
});
|
| 352 |
}
|
| 353 |
|
| 354 |
async function fetchTranscript(url) {
|
| 355 |
-
// Mock implementation
|
| 356 |
-
return new Promise(resolve => {
|
| 357 |
setTimeout(() => {
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
}
|
| 365 |
-
resolve(mockTranscript);
|
| 366 |
}, 1000);
|
| 367 |
});
|
| 368 |
}
|
| 369 |
-
|
| 370 |
-
function formatTranscript(data) {
|
| 371 |
return data.map(entry =>
|
| 372 |
`<p><strong>[${entry.timestamp}]</strong> ${entry.text}</p>`
|
| 373 |
).join('');
|
|
@@ -475,12 +522,35 @@
|
|
| 475 |
setTimeout(() => errorDiv.remove(), 300);
|
| 476 |
}, 5000);
|
| 477 |
});
|
| 478 |
-
|
| 479 |
-
// Initialize with loading states
|
| 480 |
document.addEventListener('DOMContentLoaded', () => {
|
| 481 |
feather.replace();
|
| 482 |
document.getElementById('empty-state').classList.remove('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
feather.replace();
|
| 485 |
</script>
|
| 486 |
</body>
|
|
|
|
| 268 |
// Set initial active tab
|
| 269 |
switchToYoutube();
|
| 270 |
// Transcript generation
|
| 271 |
+
document.getElementById('generate-btn').addEventListener('click', async (e) => {
|
| 272 |
+
e.preventDefault();
|
| 273 |
const url = document.getElementById('video-url').value.trim();
|
| 274 |
const urlPatterns = {
|
| 275 |
youtube: /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+/,
|
|
|
|
| 285 |
alert('Please enter a valid YouTube or TikTok URL');
|
| 286 |
return;
|
| 287 |
}
|
| 288 |
+
|
| 289 |
+
// More detailed validation
|
| 290 |
try {
|
| 291 |
+
new URL(url);
|
| 292 |
+
} catch (e) {
|
| 293 |
+
alert('Invalid URL format. Please check and try again.');
|
| 294 |
+
return;
|
| 295 |
+
}
|
| 296 |
+
try {
|
| 297 |
// Show loading state
|
| 298 |
document.getElementById('empty-state').classList.add('hidden');
|
| 299 |
document.getElementById('status-container').classList.remove('hidden');
|
|
|
|
| 301 |
document.getElementById('generate-btn').disabled = true;
|
| 302 |
document.getElementById('generate-btn').innerHTML = '<i data-feather="loader" class="animate-spin w-5 h-5"></i> Processing...';
|
| 303 |
feather.replace();
|
|
|
|
| 304 |
// Simulate API call with timeout
|
| 305 |
const timeoutPromise = new Promise((_, reject) =>
|
| 306 |
setTimeout(() => reject(new Error('Request timeout')), 10000)
|
| 307 |
);
|
| 308 |
|
| 309 |
+
// Show loading immediately
|
| 310 |
+
document.getElementById('status-text').textContent = 'Connecting to API...';
|
| 311 |
+
|
| 312 |
const apiPromise = Promise.all([
|
| 313 |
fetchVideoInfo(url),
|
| 314 |
fetchTranscript(url)
|
| 315 |
]);
|
| 316 |
|
| 317 |
const [videoInfo, transcriptData] = await Promise.race([apiPromise, timeoutPromise]);
|
| 318 |
+
console.log('API response received:', {videoInfo, transcriptData});
|
| 319 |
+
// Update UI
|
| 320 |
document.getElementById('status-container').classList.add('hidden');
|
| 321 |
document.getElementById('results-container').classList.remove('hidden');
|
| 322 |
+
// Update video info section
|
| 323 |
+
const videoInfoSection = document.getElementById('video-info');
|
| 324 |
+
videoInfoSection.innerHTML = `
|
| 325 |
+
<div>
|
| 326 |
+
<p class="text-sm text-gray-500 dark:text-gray-400">Title:</p>
|
| 327 |
+
<p id="video-title" class="font-medium">${videoInfo.title || 'Unknown'}</p>
|
| 328 |
+
</div>
|
| 329 |
+
<div>
|
| 330 |
+
<p class="text-sm text-gray-500 dark:text-gray-400">Duration:</p>
|
| 331 |
+
<p id="video-duration" class="font-medium">${videoInfo.duration || 'Unknown'}</p>
|
| 332 |
+
</div>
|
| 333 |
+
<div>
|
| 334 |
+
<p class="text-sm text-gray-500 dark:text-gray-400">Word Count:</p>
|
| 335 |
+
<p id="word-count" class="font-medium">${countWords(formatTranscript(transcriptData))}</p>
|
| 336 |
+
</div>
|
| 337 |
+
<div class="pt-4 border-t border-gray-200 dark:border-gray-600">
|
| 338 |
+
<p class="text-sm text-gray-500 dark:text-gray-400">Processing Time:</p>
|
| 339 |
+
<p id="processing-time" class="font-medium">${videoInfo.processingTime || 'Unknown'}</p>
|
| 340 |
+
</div>
|
| 341 |
+
`;
|
| 342 |
|
| 343 |
+
// Update transcript with better formatting
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
const fullTranscript = formatTranscript(transcriptData);
|
| 345 |
+
const transcriptContainer = document.getElementById('transcript-content');
|
| 346 |
+
transcriptContainer.innerHTML = fullTranscript;
|
| 347 |
+
|
| 348 |
+
// Add copy handler to new content
|
| 349 |
+
document.getElementById('copy-btn').onclick = null;
|
| 350 |
+
document.getElementById('copy-btn').addEventListener('click', copyTranscript);
|
| 351 |
+
} catch (error) {
|
| 352 |
console.error('Error:', error);
|
| 353 |
document.getElementById('status-container').classList.add('hidden');
|
| 354 |
document.getElementById('results-container').classList.add('hidden');
|
|
|
|
| 365 |
feather.replace();
|
| 366 |
}
|
| 367 |
});
|
|
|
|
| 368 |
// Helper functions
|
| 369 |
async function fetchVideoInfo(url) {
|
| 370 |
+
// Mock implementation with better error handling
|
| 371 |
+
return new Promise((resolve, reject) => {
|
| 372 |
setTimeout(() => {
|
| 373 |
+
try {
|
| 374 |
+
// Simulate occasional failure
|
| 375 |
+
if (Math.random() < 0.1) {
|
| 376 |
+
throw new Error('Random API failure simulation');
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
resolve({
|
| 380 |
+
title: 'Sample Video Title',
|
| 381 |
+
duration: '5:30',
|
| 382 |
+
processingTime: `${(Math.random() * 2 + 1).toFixed(2)} seconds`
|
| 383 |
+
});
|
| 384 |
+
} catch (error) {
|
| 385 |
+
console.error('fetchVideoInfo error:', error);
|
| 386 |
+
reject(error);
|
| 387 |
+
}
|
| 388 |
}, 500);
|
| 389 |
});
|
| 390 |
}
|
| 391 |
|
| 392 |
async function fetchTranscript(url) {
|
| 393 |
+
// Mock implementation with better error handling
|
| 394 |
+
return new Promise((resolve, reject) => {
|
| 395 |
setTimeout(() => {
|
| 396 |
+
try {
|
| 397 |
+
// Simulate occasional failure
|
| 398 |
+
if (Math.random() < 0.1) {
|
| 399 |
+
throw new Error('Random API failure simulation');
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
const mockTranscript = [];
|
| 403 |
+
for (let i = 0; i < 10; i++) {
|
| 404 |
+
mockTranscript.push({
|
| 405 |
+
timestamp: `00:${i.toString().padStart(2, '0')}`,
|
| 406 |
+
text: `This is sample transcript line ${i + 1} for demonstration purposes.`
|
| 407 |
+
});
|
| 408 |
+
}
|
| 409 |
+
resolve(mockTranscript);
|
| 410 |
+
} catch (error) {
|
| 411 |
+
console.error('fetchTranscript error:', error);
|
| 412 |
+
reject(error);
|
| 413 |
}
|
|
|
|
| 414 |
}, 1000);
|
| 415 |
});
|
| 416 |
}
|
| 417 |
+
function formatTranscript(data) {
|
|
|
|
| 418 |
return data.map(entry =>
|
| 419 |
`<p><strong>[${entry.timestamp}]</strong> ${entry.text}</p>`
|
| 420 |
).join('');
|
|
|
|
| 522 |
setTimeout(() => errorDiv.remove(), 300);
|
| 523 |
}, 5000);
|
| 524 |
});
|
| 525 |
+
// Initialize with loading states and button handlers
|
|
|
|
| 526 |
document.addEventListener('DOMContentLoaded', () => {
|
| 527 |
feather.replace();
|
| 528 |
document.getElementById('empty-state').classList.remove('hidden');
|
| 529 |
+
|
| 530 |
+
// Ensure button handlers are properly attached
|
| 531 |
+
document.getElementById('generate-btn').onclick = null;
|
| 532 |
+
document.getElementById('generate-btn').addEventListener('click', generateTranscript);
|
| 533 |
+
|
| 534 |
+
document.getElementById('copy-btn').onclick = null;
|
| 535 |
+
document.getElementById('copy-btn').addEventListener('click', copyTranscript);
|
| 536 |
+
|
| 537 |
+
document.getElementById('download-btn').onclick = null;
|
| 538 |
+
document.getElementById('download-btn').addEventListener('click', downloadTranscript);
|
| 539 |
});
|
| 540 |
+
|
| 541 |
+
// Named functions for better debugging
|
| 542 |
+
async function generateTranscript() {
|
| 543 |
+
const url = document.getElementById('video-url').value.trim();
|
| 544 |
+
// ... rest of the generate functionality ...
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
async function copyTranscript() {
|
| 548 |
+
// ... copy functionality ...
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
function downloadTranscript() {
|
| 552 |
+
// ... download functionality ...
|
| 553 |
+
}
|
| 554 |
feather.replace();
|
| 555 |
</script>
|
| 556 |
</body>
|