获取视频源详情不再依赖title

This commit is contained in:
mtvpls
2026-03-18 09:51:23 +08:00
parent 826acf40bf
commit 02b5c87c01
3 changed files with 98 additions and 44 deletions
+10 -22
View File
@@ -4,13 +4,13 @@ import { NextRequest, NextResponse } from 'next/server';
import { getAuthInfoFromCookie } from '@/lib/auth';
import { getAvailableApiSites, getCacheTime, getConfig } from '@/lib/config';
import { searchFromApi } from '@/lib/downstream';
import { getDetailFromApiV2 } from '@/lib/downstream';
import { getProxyToken } from '@/lib/emby-token';
export const runtime = 'nodejs';
/**
* 根据 source 和 id 从搜索结果中精确匹配获取视频详情
* 根据 source 和 id 直接获取视频详情
* 这个API专门用于play页面快速获取当前源的详情
*/
export async function GET(request: NextRequest) {
@@ -22,10 +22,9 @@ export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const id = searchParams.get('id');
const sourceCode = searchParams.get('source');
const title = searchParams.get('title'); // 用于搜索的标题
const fileName = searchParams.get('fileName'); // 小雅源:用户点击的文件名
if (!id || !sourceCode || !title) {
if (!id || !sourceCode) {
return NextResponse.json({ error: '缺少必要参数' }, { status: 400 });
}
@@ -385,7 +384,11 @@ export async function GET(request: NextRequest) {
}
}
// 对于其他源,通过搜索API获取,然后精确匹配
if (!/^[\w-]+$/.test(id)) {
return NextResponse.json({ error: '无效的视频ID格式' }, { status: 400 });
}
// 对于其他采集源,直接按 id 获取详情。
try {
const apiSites = await getAvailableApiSites(authInfo.username);
const apiSite = apiSites.find((site) => site.key === sourceCode);
@@ -394,26 +397,11 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: '无效的API来源' }, { status: 400 });
}
// 调用搜索API
const searchResults = await searchFromApi(apiSite, title.trim());
// 从搜索结果中精确匹配 source 和 id
const exactMatch = searchResults.find(
(item: any) =>
item.source?.toString() === sourceCode.toString() &&
item.id?.toString() === id.toString()
);
if (!exactMatch) {
return NextResponse.json(
{ error: '未找到匹配的视频源' },
{ status: 404 }
);
}
const result = await getDetailFromApiV2(apiSite, id);
// 添加 proxyMode 到返回结果
const resultWithProxy = {
...exactMatch,
...result,
proxyMode: apiSite.proxyMode || false,
};