MCPcopy Create free account
hub / github.com/SamuelZ12/longcut / buildFallbackTopics

Function buildFallbackTopics

lib/ai-processing.ts:451–516  ·  view source on GitHub ↗
(
  transcript: TranscriptSegment[],
  maxTopics: number,
  fullText: string,
  theme?: string
)

Source from the content-addressed store, hash-verified

449}
450
451function buildFallbackTopics(
452 transcript: TranscriptSegment[],
453 maxTopics: number,
454 fullText: string,
455 theme?: string
456): ParsedTopic[] {
457 // Don't generate generic fallbacks for theme-based generation
458 // If AI can't find theme-relevant content, return empty array
459 if (theme) {
460 console.log(`[buildFallbackTopics] Skipping fallback generation for theme: "${theme}"`);
461 return [];
462 }
463
464 if (transcript.length === 0) {
465 if (!fullText) return [];
466 return [
467 {
468 title: theme ? `${theme} overview` : 'Full Video',
469 quote: {
470 timestamp: '[00:00-00:30]',
471 text: fullText.substring(0, 200)
472 }
473 }
474 ];
475 }
476
477 const fallbackCount = Math.min(6, Math.max(1, maxTopics));
478 const chunkSize = Math.ceil(transcript.length / fallbackCount);
479 const fallbackTopics: ParsedTopic[] = [];
480
481 for (let i = 0; i < fallbackCount && i * chunkSize < transcript.length; i++) {
482 const startIdx = i * chunkSize;
483 const endIdx = Math.min((i + 1) * chunkSize, transcript.length);
484 const chunkSegments = transcript.slice(startIdx, endIdx);
485
486 if (chunkSegments.length === 0) continue;
487
488 const startTime = chunkSegments[0].start;
489 const endSegment = chunkSegments[chunkSegments.length - 1];
490 const endTime = endSegment.start + endSegment.duration;
491
492 fallbackTopics.push({
493 title: buildFallbackTopicTitle(startTime, endTime),
494 quote: {
495 timestamp: `[${formatTime(startTime)}-${formatTime(endTime)}]`,
496 text:
497 chunkSegments
498 .map((s) => s.text)
499 .join(' ')
500 .substring(0, 200) + '...'
501 }
502 });
503 }
504
505 if (fallbackTopics.length === 0 && fullText) {
506 fallbackTopics.push({
507 title: theme ? `${theme} spotlight` : 'Full Video',
508 quote: {

Callers 1

Calls 3

buildFallbackTopicTitleFunction · 0.85
logMethod · 0.80
formatTimeFunction · 0.70

Tested by

no test coverage detected