Docs/Skills and code/src/

src/youtube.js

Code28 lines1.2 KBsrc/

import { searchYouTube } from "ytsearch.js";
import { normalizeSearchVideo } from "./video-normalization.js";

export function normalizeVideo(video) {
  return normalizeSearchVideo(video);
}

export async function searchVideos(query, limit = 30) {
  const requestedLimit = Number(limit) || 30;
  const effectiveLimit = Math.max(10, Math.min(50, Math.round(requestedLimit)));
  if (effectiveLimit !== requestedLimit) {
    console.warn("[youtube-search] Adjusted ytsearch.js limit to supported range 10–50:", {
      requestedLimit, effectiveLimit, query
    });
  }
  console.log("[youtube-search] Searching:", { query, limit: effectiveLimit });
  const result = await searchYouTube(query, { type: "video", limit: effectiveLimit });
  const rawVideos = Array.isArray(result?.videos) ? result.videos : [];
  const videos = rawVideos.map(normalizeVideo).filter(video => video.video_id);
  console.log("[youtube-search] Normalized results:", {
    query, raw: rawVideos.length, accepted: videos.length,
    withViews: videos.filter(video => video.view_count !== null).length,
    withThumbnails: videos.filter(video => video.thumbnail_url).length,
    withDates: videos.filter(video => video.published_at_text).length
  });
  return videos;
}

Shown as it is in the repository at build time (2026-11-03); the home directory appears as <home>. If this page and the file differ, the file is right. Back to the catalogue.