import type { DailyConfig } from '../config.js'; import { type RotationState } from '../rotation.js'; import type { Platform, RawItem } from '../types.js'; import type { MirrorPool } from './mirror.js'; export interface CollectEnv { config: DailyConfig; pool: MirrorPool; signal?: AbortSignal; /** * YouTube 频道的轮转/退避状态(输入)。由 service 从 meta 里取出来传进来 —— * 采集器本身不落盘,保持"给定输入 → 产出结果"的可测试性。 */ rotation?: RotationState; /** * **单源总预算**(毫秒)。缺省用 `SOURCE_BUDGET_MS`(20s)。 * 为什么需要它:`fetchText` 的 12s 是**每次尝试**的超时,默认还会重试 2 次 → * 最坏 ≈ 40s,一个慢源能独占整轮刷新(实测 YouTube 43–47s)。 */ sourceBudgetMs?: number; } export interface SourceResult { items: RawItem[]; /** 该源的补充说明(部分成功、降级路径等),会进日报的"源状态"里给人看。 */ note?: string; /** * 本轮的**尝试结果**(只用于需要轮转的源,目前是 YouTube)。 * 由 runCollection 汇总后交给 service 落进 meta —— 采集器不直接写盘。 */ rotationUpdates?: Array<{ key: string; ok: boolean; }>; } export type SourceRunner = (env: CollectEnv) => Promise; /** * 采集失败,但**带着本轮的轮转尝试记录**。 * * 为什么需要它:源全部失败时 runner 要抛错(好让源状态显示 ❌), * 但抛错会把 `rotationUpdates` 一起丢掉 —— 于是"失败计数"永远停在 0、 * 退避永不生效、一个挂掉的频道每轮都被重新选中。踩过一次,所以让它跟着异常走。 */ export declare class SourceFailure extends Error { readonly rotationUpdates?: Array<{ key: string; ok: boolean; }>; constructor(message: string, rotationUpdates?: Array<{ key: string; ok: boolean; }>); } /** * Hacker News。 * * 走 hnrss.org 而不是官方 Firebase API:官方 API 只给 id 列表,拿一条完整条目要再发一次请求 * (20 条 = 21 次请求);hnrss 一次就把标题、原文链接、分数、评论数都给全了。 * 代价是分数要从 description 的 HTML 里抠 —— 抠不到就当没有,不影响条目本身。 */ export declare function collectHackerNews(env: CollectEnv): Promise; export declare function collectArxiv(env: CollectEnv): Promise; /** * GitHub:**不用** Trending 页面(已实测超时),改用 Search API 做等价的事 —— * "最近 30 天创建、star 数最高"就是 Trending 的语义,而且是结构化 JSON。 */ export declare function collectGithub(env: CollectEnv): Promise; /** 秒 → `mm:ss` / `h:mm:ss`。B 站给的是秒数,前端约定要字符串。 */ export declare function formatDuration(seconds: number | undefined): string | undefined; /** * 把 feed 里五花八门的时长写法统一成 `mm:ss` / `h:mm:ss`。 * * 为什么要归一化:`itunes:duration` 在不同 feed 里可能是 * `754`(秒)、`12:34`、`1:02:03`,而 Atom 的 `media:content duration` 常用 ISO 8601 的 * `PT12M34S`。前端的角标只认 `mm:ss` 形式,混着显示会出现 "PT12M34S" 这种噪音。 * 认不出来就返回 undefined(宁可不显示,也不要显示错的)。 */ export declare function normalizeDuration(input: string | undefined): string | undefined; /** 哔哩哔哩·热门。这个接口无需签名,是本机实测最稳的视频源。 */ export declare function collectBilibiliPopular(env: CollectEnv): Promise; /** 哔哩哔哩·全站排行榜。带 rid=0 是全站;偶发 -352 风控,交给 http 层重试。 */ export declare function collectBilibiliRanking(env: CollectEnv): Promise; /** * YouTube:**必须**走 RSSHub 镜像池。 * 官方 feed(`youtube.com/feeds/videos.xml`)、Invidious、Piped 在本机全部直连超时(已实测)。 */ export declare function collectYoutube(env: CollectEnv): Promise; interface ChannelSpec { name: string; channelId: string; topic: string; } /** 解析 `名称|频道ID或@handle|主题`。容错:只给两段时主题留空,交给自动分类。 */ export declare function parseChannelSpec(spec: string): ChannelSpec | null; /** 从 `yt:video:XXXX` / `watch?v=XXXX` / feed 的 id 里取出视频 ID。 */ export declare function extractYoutubeId(input: string): string | null; /** 为某个内置 feed 生成 runner。 */ export declare function makeFeedRunner(id: string): SourceRunner; /** * 内置 feed 的 `名称|URL|主题` 清单。 * 导出 OPML 时把内置源也带上 —— 用户既然喜欢这几个源,就该能把它们带回自己的阅读器。 */ export declare function builtinFeedSpecs(): Array<{ name: string; url: string; topic: string; }>; /** 用户自配的额外 RSS 源,格式 `名称|URL|主题`。 */ export declare function parseFeedSpec(spec: string): { name: string; url: string; topic: string; } | null; export declare function collectExtraFeeds(env: CollectEnv): Promise; /** 平台 → 默认形态。采集器没声明 kind 时的兜底判定。 */ export declare function inferKind(platform: Platform, url: string): 'web' | 'video'; export {};