Skip to content

一分钟搭建影视站,支持Docker等部署方式

feat(recommend): 第三推荐源影视榜单(60s API,免 key)

bestZwei0747ada83947
diff --git a/README.md b/README.md
index cfa474c..2fa02be 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ LibreTV Next.js 迁移版:免费在线视频聚合搜索与观看平台。基
- **进度同步**:播放进度与观看历史存于本机 IndexedDB,精确到秒的续播
- **换源测速**:跨源搜索同名资源并测速排序,一键切换保留集数位置
- **源测试与订阅**:一键探活数据源;订阅远程源列表(LibreTV-SourceList JSON),可导出分享
-- **首页推荐**:豆瓣(电影/剧集分类浏览)或 Bangumi 新番放送表,设置中切换;均服务端直连 + 缓存,Bangumi 免 key 免配置
+- **首页推荐**:豆瓣(电影/剧集分类浏览)、Bangumi 新番放送表或影视榜单(豆瓣周榜 + 百度热播,经 60s API),设置中切换;均服务端直连 + 缓存,Bangumi/榜单免 key 免配置(`60S_API_BASE` 可指向自部署 60s 实例)
- **PWA**:可安装到桌面 / 主屏幕,亮暗双主题无首屏闪烁
## 部署
diff --git a/src/app/api/hot-list/route.ts b/src/app/api/hot-list/route.ts
new file mode 100644
index 0000000..6f795c1
--- /dev/null
+++ b/src/app/api/hot-list/route.ts
@@ -0,0 +1,26 @@
+import { NextResponse } from 'next/server';
+import { guardRequest } from '@/lib/api-guard';
+import { fetchHotList, isHotListId } from '@/lib/douban-weekly';
+
+export const runtime = 'nodejs';
+
+/** 影视热榜(经 60s API 免 key):豆瓣五个周榜 + 百度热播剧,服务端转发 + 缓存 */
+export async function GET(req: Request) {
+ const guarded = guardRequest(req);
+ if (guarded) return guarded;
+
+ const id = new URL(req.url).searchParams.get('id') || '';
+ if (!isHotListId(id)) {
+ return NextResponse.json({ error: `未知榜单: ${id.slice(0, 30)}` }, { status: 400 });
+ }
+
+ try {
+ const items = await fetchHotList(id);
+ return NextResponse.json({ items });
+ } catch (err) {
+ return NextResponse.json(
+ { error: err instanceof Error ? err.message : '榜单获取失败' },
+ { status: 502 }
+ );
+ }
+}
diff --git a/src/components/douban-section.tsx b/src/components/douban-section.tsx
index 68185f8..937e5c4 100644
--- a/src/components/douban-section.tsx
+++ b/src/components/douban-section.tsx
@@ -12,13 +12,15 @@ const MOVIE_TAGS = ['热门', '最新', '经典', '豆瓣高分', '冷门佳片'
const TV_TAGS = ['热门', '美剧', '英剧', '韩剧', '日剧', '国产剧', '港剧', '日本动画', '综艺', '纪录片'];
const WEEKDAYS = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
-/** 首页推荐区:数据源由设置决定(豆瓣热门 / Bangumi 新番放送),二选一展示 */
+/** 首页推荐区:数据源由设置决定(豆瓣热门 / Bangumi 新番放送 / 影视热榜),二选一展示 */
export function RecommendSection({ onPick }: { onPick: (title: string) => void }) {
const doubanEnabled = useAppStore((s) => s.doubanEnabled);
const recommendSource = useAppStore((s) => s.recommendSource);
if (!doubanEnabled) return null;
- return recommendSource === 'bangumi' ? <BangumiView onPick={onPick} /> : <DoubanView onPick={onPick} />;
+ if (recommendSource === 'bangumi') return <BangumiView onPick={onPick} />;
+ if (recommendSource === 'hot-list') return <HotListView onPick={onPick} />;
+ return <DoubanView onPick={onPick} />;
}
/** 豆瓣推荐:影视切换 + 标签筛选 + 分页加载 */
@@ -100,8 +102,7 @@ function DoubanView({ onPick }: { onPick: (title: string) => void }) {
);
}
-/** Bangumi 每日放送:星期筛选,一次拉全量无分页 */
-function BangumiView({ onPick }: { onPick: (title: string) => void }) {
+/** Bangumi 每日放送:星期筛选,一次拉全量无分页 */function BangumiView({ onPick }: { onPick: (title: string) => void }) {
const [weekday, setWeekday] = useState<number | 'all'>('all');
const query = useQuery({
@@ -144,6 +145,51 @@ function BangumiView({ onPick }: { onPick: (title: string) => void }) {
);
}
+const HOT_LISTS = [
+ { id: 'douban_movie_weekly', label: '电影周榜' },
+ { id: 'douban_tv_chinese', label: '国产剧周榜' },
+ { id: 'douban_tv_global', label: '海外剧周榜' },
+ { id: 'douban_show_chinese', label: '国内综艺' },
+ { id: 'douban_show_global', label: '海外综艺' },
+ { id: 'baidu_teleplay', label: '百度热播剧' },
+];
+
+/** 影视热榜(60s API):豆瓣五个周榜 + 百度热播剧,chips 切换 */
+function HotListView({ onPick }: { onPick: (title: string) => void }) {
+ const [listId, setListId] = useState(HOT_LISTS[0].id);
+
+ const query = useQuery({
+ queryKey: ['hot-list', listId],
+ queryFn: ({ signal }) => api.hotList(listId, signal),
+ });
+
+ const items = query.data?.items ?? [];
+
+ return (
+ <section aria-label="影视榜单推荐">
+ <div className="flex flex-wrap gap-1.5 mb-4">
+ {HOT_LISTS.map((l) => (
+ <ChipButton key={l.id} active={listId === l.id} onClick={() => setListId(l.id)}>
+ {l.label}
+ </ChipButton>
+ ))}
+ </div>
+
+ {query.isError ? (
+ <p className="text-center text-sm text-faint py-8">推荐内容加载失败,可稍后重试或在设置中关闭</p>
+ ) : query.isLoading ? (
+ <GridSkeleton />
+ ) : (
+ <div className="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 gap-2.5">
+ {items.map((item) => (
+ <DoubanCard key={item.id} item={item} onClick={() => onPick(item.title)} />
+ ))}
+ </div>
+ )}
+ </section>
+ );
+}
+
function GridSkeleton() {
return (
<div className="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 gap-2.5">
diff --git a/src/components/source-manager.tsx b/src/components/source-manager.tsx
index ce0d318..03eb6f8 100644
--- a/src/components/source-manager.tsx
+++ b/src/components/source-manager.tsx
@@ -256,10 +256,11 @@ export function SourceManagerDrawer({ open, onClose }: { open: boolean; onClose:
<SelectRow
label="推荐数据源"
value={store.recommendSource}
- onChange={(v) => store.updateSettings({ recommendSource: v as 'douban' | 'bangumi' })}
+ onChange={(v) => store.updateSettings({ recommendSource: v as 'douban' | 'bangumi' | 'hot-list' })}
options={[
{ value: 'douban', label: '豆瓣(电影/剧集)' },
{ value: 'bangumi', label: 'Bangumi 新番放送' },
+ { value: 'hot-list', label: '影视榜单(豆瓣周榜/百度热播)' },
]}
/>
</div>
diff --git a/src/lib/client-api.ts b/src/lib/client-api.ts
index e22f983..7ab34fa 100644
--- a/src/lib/client-api.ts
+++ b/src/lib/client-api.ts
@@ -83,6 +83,12 @@ export const api = {
/** Bangumi 每日放送(免 key),首页推荐的另一数据源 */
bangumiCalendar: (signal?: AbortSignal) => request<BangumiCalendarResponse>('/api/bangumi/calendar', { signal }),
+ /** 影视热榜(60s API 免 key):豆瓣周榜五个类目 + 百度热播剧 */
+ hotList: (id: string, signal?: AbortSignal) => {
+ const sp = new URLSearchParams({ id });
+ return request<DoubanResponse>(`/api/hot-list?${sp.toString()}`, { signal });
+ },
+
/** 换源:按标题跨源搜索并取详情,附带接口耗时(测速) */
detailSpeed: async (id: string, source: SourceConfig) => {
const start = performance.now();
diff --git a/src/lib/douban-weekly.test.ts b/src/lib/douban-weekly.test.ts
new file mode 100644
index 0000000..13fdee5
--- /dev/null
+++ b/src/lib/douban-weekly.test.ts
@@ -0,0 +1,60 @@
+import { describe, expect, it } from 'vitest';
+import { baiduTeleplayToItem, doubanWeeklyToItem, isHotListId } from './douban-weekly';
+
+describe('isHotListId', () => {
+ it('白名单校验', () => {
+ expect(isHotListId('douban_movie_weekly')).toBe(true);
+ expect(isHotListId('baidu_teleplay')).toBe(true);
+ expect(isHotListId('maoyan')).toBe(false);
+ expect(isHotListId('')).toBe(false);
+ });
+});
+
+describe('doubanWeeklyToItem', () => {
+ it('评分、封面代理、isTv 正确映射', () => {
+ const item = doubanWeeklyToItem(
+ {
+ id: 36808876,
+ title: '奥德赛',
+ rating: 8.6,
+ cover_proxy: 'https://doubanio.viki.moe/view/photo/p1.jpg',
+ cover: 'https://img9.doubanio.com/view/photo/p1.jpg',
+ },
+ false
+ );
+ expect(item).toEqual({
+ id: '36808876',
+ title: '奥德赛',
+ cover: 'https://doubanio.viki.moe/view/photo/p1.jpg',
+ rating: '8.6',
+ isTv: false,
+ });
+ });
+
+ it('cover_proxy 缺失时回退 cover,0 分不输出 rating', () => {
+ const item = doubanWeeklyToItem({ id: 1, title: 'x', cover: 'c', rating: 0 }, true);
+ expect(item).toMatchObject({ cover: 'c', isTv: true });
+ expect(item?.rating).toBeUndefined();
+ });
+
+ it('缺 id、标题或封面的脏数据丢弃', () => {
+ expect(doubanWeeklyToItem({ title: 'x', cover: 'c' }, false)).toBeUndefined();
+ expect(doubanWeeklyToItem({ id: 1, cover: 'c' }, false)).toBeUndefined();
+ expect(doubanWeeklyToItem({ id: 1, title: 'x' }, false)).toBeUndefined();
+ });
+});
+
+describe('baiduTeleplayToItem', () => {
+ it('用序号生成 id,不输出 rating', () => {
+ expect(baiduTeleplayToItem({ title: '某剧', cover: 'https://img.example/1.jpg' }, 3)).toEqual({
+ id: 'baidu_3',
+ title: '某剧',
+ cover: 'https://img.example/1.jpg',
+ isTv: true,
+ });
+ });
+
+ it('无海报条目丢弃', () => {
+ expect(baiduTeleplayToItem({ title: '某剧', cover: null }, 0)).toBeUndefined();
+ });
+});
diff --git a/src/lib/douban-weekly.ts b/src/lib/douban-weekly.ts
new file mode 100644
index 0000000..4779fea
--- /dev/null
+++ b/src/lib/douban-weekly.ts
@@ -0,0 +1,126 @@
+import type { DoubanItem } from './types';
+import { fetchUpstream, getCache, setCache } from './fetch-utils';
+
+/**
+ * 影视热榜聚合(经 60s API,免 key,https://github.com/vikiboss/60s)。
+ * 豆瓣周榜走其 rexxar 移动端接口(需伪装 iPhone UA),百度热播剧榜解析 top.baidu.com,
+ * 均由 60s 代为抓取;这里只做服务端转发 + 内存缓存 + 字段归一。
+ * 官方公共实例有限流,生产可通过 60S_API_BASE 指向自部署实例。
+ */
+
+const CACHE_TTL = 60 * 60 * 1000;
+const UA = 'LibreTV-Next (+https://github.com/bestZwei/LibreTV-Next)';
+
+function apiBase(): string {
+ return (process.env['60S_API_BASE'] || 'https://60s.viki.moe').replace(/\/+$/, '');
+}
+
+/** 榜单标识:豆瓣五个周榜 + 百度热播剧榜 */
+export const HOT_LIST_IDS = [
+ 'douban_movie_weekly',
+ 'douban_tv_chinese',
+ 'douban_tv_global',
+ 'douban_show_chinese',
+ 'douban_show_global',
+ 'baidu_teleplay',
+] as const;
+
+export type HotListId = (typeof HOT_LIST_IDS)[number];
+
+export function isHotListId(id: string): id is HotListId {
+ return (HOT_LIST_IDS as readonly string[]).includes(id);
+}
+
+const DOUBAN_WEEKLY_CATEGORY: Partial<Record<HotListId, string>> = {
+ douban_movie_weekly: 'movie',
+ douban_tv_chinese: 'tv_chinese',
+ douban_tv_global: 'tv_global',
+ douban_show_chinese: 'show_chinese',
+ douban_show_global: 'show_global',
+};
+
+// —— 60s API 原始结构(只取用到的字段) ——
+
+interface DoubanWeeklyRaw {
+ id?: number | string;
+ title?: string;
+ rating?: number;
+ cover_proxy?: string;
+ cover?: string;
+}
+
+interface BaiduTeleplayRaw {
+ title?: string;
+ cover?: string | null;
+}
+
+interface SixtyResponse<T> {
+ code?: number;
+ data?: T;
+}
+
+/** 豆瓣周榜条目 → DoubanItem;缺标题或封面的脏数据丢弃 */
+export function doubanWeeklyToItem(raw: DoubanWeeklyRaw, isTv: boolean): DoubanItem | undefined {
+ const cover = raw.cover_proxy || raw.cover;
+ if (!raw.id || !raw.title || !cover) return undefined;
+ return {
+ id: String(raw.id),
+ title: raw.title,
+ cover,
+ rating: raw.rating && raw.rating > 0 ? String(raw.rating) : undefined,
+ isTv,
+ };
+}
+
+/** 百度热播剧条目 → DoubanItem;无评分,海报为空的条目丢弃 */
+export function baiduTeleplayToItem(raw: BaiduTeleplayRaw, index: number): DoubanItem | undefined {
+ if (!raw.title || !raw.cover) return undefined;
+ return {
+ // 百度榜无稳定 id,用榜单内序号保证 React key 唯一
+ id: `baidu_${index}`,
+ title: raw.title,
+ cover: raw.cover,
+ isTv: true,
+ };
+}
+
+function assertArray<T>(value: unknown, what: string): T[] {
+ if (!Array.isArray(value)) throw new Error(`${what}数据异常`);
+ return value as T[];
+}
+
+async function fetchJson(path: string): Promise<unknown> {
+ const res = await fetchUpstream(`${apiBase()}${path}`, {
+ timeoutMs: 8000,
+ headers: { 'User-Agent': UA, Accept: 'application/json' },
+ });
+ if (!res.ok) throw new Error(`60s API 响应异常 (${res.status})`);
+ return res.json();
+}
+
+export async function fetchHotList(id: HotListId): Promise<DoubanItem[]> {
+ const cacheKey = `hot-list:${id}`;
+ const cached = getCache<DoubanItem[]>(cacheKey);
+ if (cached) return cached;
+
+ let items: DoubanItem[];
+
+ const category = DOUBAN_WEEKLY_CATEGORY[id];
+ if (category) {
+ const raw = (await fetchJson(`/v2/douban/weekly/${category}`)) as SixtyResponse<DoubanWeeklyRaw[]>;
+ const isTv = id !== 'douban_movie_weekly';
+ items = assertArray<DoubanWeeklyRaw>(raw.data, '豆瓣周榜')
+ .map((entry) => doubanWeeklyToItem(entry, isTv))
+ .filter((item): item is DoubanItem => item !== undefined);
+ } else {
+ const raw = (await fetchJson('/v2/baidu/teleplay')) as SixtyResponse<BaiduTeleplayRaw[]>;
+ items = assertArray<BaiduTeleplayRaw>(raw.data, '百度热播剧榜')
+ .map((entry, i) => baiduTeleplayToItem(entry, i))
+ .filter((item): item is DoubanItem => item !== undefined);
+ }
+
+ if (items.length === 0) throw new Error('榜单数据为空');
+
+ setCache(cacheKey, items, CACHE_TTL);
+ return items;
+}
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 12d75a7..b6a11d7 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -15,8 +15,8 @@ export interface AppSettings {
yellowFilter: boolean;
adFilter: boolean;
doubanEnabled: boolean;
- /** 首页推荐数据源:豆瓣热门 / Bangumi 每日放送(免 key) */
- recommendSource: 'douban' | 'bangumi';
+ /** 首页推荐数据源:豆瓣热门 / Bangumi 每日放送(免 key)/ 影视热榜(60s API) */
+ recommendSource: 'douban' | 'bangumi' | 'hot-list';
autoplayNext: boolean;
imageProxyMode: 'direct' | 'proxy' | 'custom';
customImageProxy: string;