// A PODCAST FEED CHANNEL'S TITLES, BEFORE ANY PROBE (plans/pacing-guard.md). // // A download-missing on a feed channel with a title filter (megaphone.fm, // 2026-10-23) probed every listed episode with yt-dlp, ~1,150 of them back to // back, only to learn each one's title and decline it. The feed already says // every title. So, once per run and only where it can pay: ONE request for the // channel's feed, each item's title, description and date written into the // channel's metadata-scan store under the id its enclosure URL gives // (`extractVideoId`, as the playlist's URLs are read) — and the batch's // `settledByTitleFilterIds` then settles every filtered episode with no request // at all. // // WHEN. The channel has a download filter, its platform is not one this app // knows (a known platform's listing is not a feed), and the playlist's URLs // are mostly direct media files (an RSS feed's enclosures). An item already in // the store is left as it is: a probe's answer beats the feed's. // // Best effort: a feed that does not answer, or is not RSS, costs the run // nothing but its log line. import { detectPlatform } from "../lib/platform"; import { extractVideoId } from "../lib/videoId"; import { compileDownloadFilter } from "../lib/downloadFilters"; import { feedDateToUploadDate, parseRssFeed } from "../lib/rssFeed"; import type { ChannelConfig } from "../lib/channelConfig"; import type { Paths } from "../lib/paths"; import { loadMetadataScan, upsertMetadataScan, type MetadataScanEntry } from "./metadataScanStore"; import type { FetchFeed } from "./feedMetadataBackfill"; const MEDIA_FILE = /\.(mp3|m4a|m4b|aac|ogg|oga|opus|wav|flac|mp4|m4v)(?:$|[?#])/i; // Does this channel look like a podcast feed whose titles are worth one read? export function looksLikeFeedChannel( config: Pick, playlistUrls: readonly string[], ): boolean { if (!compileDownloadFilter(config.downloadFilter)) return false; if (!config.url || !/^https?:\/\//i.test(config.url)) return false; if (config.platform || detectPlatform(config.url)) return false; if (playlistUrls.length === 0) return false; const media = playlistUrls.filter((u) => MEDIA_FILE.test(u)).length; return media * 2 >= playlistUrls.length; } export async function seedFeedTitles(opts: { paths: Paths; slug: string; config: Pick; playlistUrls: readonly string[]; onLog: (line: string) => void; signal?: AbortSignal; fetchFeed?: FetchFeed; now?: string; }): Promise { if (!looksLikeFeedChannel(opts.config, opts.playlistUrls)) return 0; const wanted = new Set(opts.playlistUrls.map((u) => extractVideoId(u)).filter((id): id is string => Boolean(id))); const scan = await loadMetadataScan(opts.paths, opts.slug); const missing = [...wanted].filter((id) => !scan.entries[id]); if (missing.length === 0) return 0; let xml: string; try { opts.onLog(`Feed titles: reading the channel's feed once (${opts.config.url}) so filtered episodes cost no probe.\n`); const fetchFeed = opts.fetchFeed ?? (await import("./feedMetadataBackfill")).fetchFeedText; xml = await fetchFeed(opts.config.url!, opts.signal); } catch (err) { opts.onLog(`Feed titles: the feed could not be read (${(err as Error).message}); each episode is probed instead.\n`); return 0; } const feed = parseRssFeed(xml); const scannedAt = opts.now ?? new Date().toISOString(); const entries: Record = {}; const missingSet = new Set(missing); for (const item of feed.items) { if (!item.enclosureUrl || !item.title) continue; const id = extractVideoId(item.enclosureUrl); if (!id || !missingSet.has(id) || entries[id]) continue; entries[id] = { title: item.title, description: item.description ?? "", uploadDate: feedDateToUploadDate(item.pubDate) ?? "", ...(item.durationSeconds ? { duration: item.durationSeconds } : {}), scannedAt, }; } const n = Object.keys(entries).length; if (n > 0) await upsertMetadataScan(opts.paths, opts.slug, { entries }, scannedAt); opts.onLog(`Feed titles: ${n} of ${missing.length} unscanned episode(s) titled from the feed (${feed.items.length} item(s)).\n`); return n; }