diff --git a/src/cli/downloader.ts b/src/cli/downloader.ts index e17fed8..e6c565c 100644 --- a/src/cli/downloader.ts +++ b/src/cli/downloader.ts @@ -23,7 +23,6 @@ interface ProcessedSegment { start: number; end: number; intensity: number; - integralJump: number; } interface VideoInfo { @@ -143,7 +142,7 @@ function getIntensity(segment: RawHeatmapSegment): number { return segment.intensity ?? segment.heat ?? segment.value ?? 0; } -function getTopSegmentsByIntegral( +function getTopSegmentsByIntensity( segments: RawHeatmapSegment[], topN: number ): ProcessedSegment[] { @@ -166,19 +165,9 @@ function getTopSegmentsByIntegral( return []; } - // Calculate integral for each segment and sort by highest - const withIntegral = validSegments.map(seg => { - const segmentDuration = seg.end - seg.start; - const integralJump = seg.intensity * segmentDuration; - return { - ...seg, - integralJump, - }; - }); - - // Sort by integral jump (highest first) and return top N - withIntegral.sort((a, b) => b.integralJump - a.integralJump); - return withIntegral.slice(0, topN); + // Sort by raw intensity (highest first) - this matches visual "bumps" in heatmap + validSegments.sort((a, b) => b.intensity - a.intensity); + return validSegments.slice(0, topN); } export async function downloadMostWatchedSegment(options: DownloadOptions): Promise { @@ -208,10 +197,10 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom } console.log(`\nHeatmap data found: ${info.heatmap.length} segments`); - console.log(`\nTop ${topN} segments by integral jump:\n`); + console.log(`\nTop ${topN} segments by intensity (visual heatmap bumps):\n`); - // Get top segments - const topSegments = getTopSegmentsByIntegral(info.heatmap, topN); + // Get top segments by raw intensity + const topSegments = getTopSegmentsByIntensity(info.heatmap, topN); if (topSegments.length === 0) { console.log("No valid segments found. Downloading full video..."); @@ -224,7 +213,7 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom for (let i = 0; i < topSegments.length; i++) { const seg = topSegments[i]; const duration = seg.end - seg.start; - console.log(`${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)} | Duration: ${formatTime(duration)} | Integral: ${seg.integralJump.toFixed(4)}`); + console.log(`${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)} | Duration: ${formatTime(duration)} | Intensity: ${(seg.intensity * 100).toFixed(1)}%`); } console.log(""); @@ -239,14 +228,13 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom // Save segment info const segmentInfoPath = join(outputDir, `${safeTitle}_top_segments.txt`); let segmentInfo = `# ${info.title}\n\n`; - segmentInfo += `Top ${topN} segments by integral jump:\n\n`; + segmentInfo += `Top ${topN} segments by intensity (highest re-watch rate):\n\n`; for (let i = 0; i < topSegments.length; i++) { const seg = topSegments[i]; const duration = seg.end - seg.start; segmentInfo += `${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)}\n`; segmentInfo += ` Duration: ${formatTime(duration)}\n`; - segmentInfo += ` Integral: ${seg.integralJump.toFixed(4)}\n`; segmentInfo += ` Intensity: ${(seg.intensity * 100).toFixed(1)}%\n\n`; }