优化视频权重获取方式
This commit is contained in:
@@ -83,6 +83,7 @@ export async function GET(request: NextRequest) {
|
||||
id: item.Id,
|
||||
source: sourceValue,
|
||||
source_name: sourceName,
|
||||
weight: weightMap.get(sourceValue) ?? 0,
|
||||
title: item.Name,
|
||||
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
||||
episodes: [],
|
||||
@@ -138,6 +139,7 @@ export async function GET(request: NextRequest) {
|
||||
id: folderName,
|
||||
source: 'openlist',
|
||||
source_name: '私人影库',
|
||||
weight: weightMap.get('openlist') ?? 0,
|
||||
title: info.title,
|
||||
poster: getTMDBImageUrl(info.poster_path),
|
||||
episodes: [],
|
||||
@@ -195,6 +197,11 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
let flattenedResults = [...openlistResults, ...embyResults, ...apiResultsFlat];
|
||||
|
||||
flattenedResults = flattenedResults.map((result) => ({
|
||||
...result,
|
||||
weight: result.weight ?? (weightMap.get(result.source) ?? 0),
|
||||
}));
|
||||
|
||||
if (!config.SiteConfig.DisableYellowFilter) {
|
||||
flattenedResults = flattenedResults.filter((result) => {
|
||||
const typeName = result.type_name || '';
|
||||
@@ -204,8 +211,8 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// 按权重降序排序
|
||||
flattenedResults.sort((a, b) => {
|
||||
const weightA = weightMap.get(a.source) ?? 0;
|
||||
const weightB = weightMap.get(b.source) ?? 0;
|
||||
const weightA = a.weight ?? 0;
|
||||
const weightB = b.weight ?? 0;
|
||||
return weightB - weightA;
|
||||
});
|
||||
|
||||
|
||||
@@ -147,6 +147,7 @@ export async function GET(request: NextRequest) {
|
||||
id: item.Id,
|
||||
source: sourceValue,
|
||||
source_name: sourceName,
|
||||
weight: weightMap.get(sourceValue) ?? 0,
|
||||
title: item.Name,
|
||||
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
||||
episodes: [],
|
||||
@@ -253,6 +254,7 @@ export async function GET(request: NextRequest) {
|
||||
id: key,
|
||||
source: 'openlist',
|
||||
source_name: '私人影库',
|
||||
weight: weightMap.get('openlist') ?? 0,
|
||||
title: info.title,
|
||||
poster: getTMDBImageUrl(info.poster_path),
|
||||
episodes: [],
|
||||
@@ -335,6 +337,11 @@ export async function GET(request: NextRequest) {
|
||||
});
|
||||
}
|
||||
|
||||
filteredResults = filteredResults.map((result) => ({
|
||||
...result,
|
||||
weight: result.weight ?? (weightMap.get(result.source) ?? 0),
|
||||
}));
|
||||
|
||||
// 发送该源的搜索结果
|
||||
completedSources++;
|
||||
|
||||
|
||||
@@ -1504,22 +1504,6 @@ function PlayPageClient() {
|
||||
): Promise<SearchResult> => {
|
||||
if (sources.length === 1) return sources[0];
|
||||
|
||||
// 获取配置以获取权重信息
|
||||
let weightMap = new Map<string, number>();
|
||||
try {
|
||||
const configResponse = await fetch('/api/admin/config');
|
||||
if (configResponse.ok) {
|
||||
const configData = await configResponse.json();
|
||||
if (configData.Config?.SourceConfig) {
|
||||
configData.Config.SourceConfig.forEach((source: any) => {
|
||||
weightMap.set(source.key, source.weight ?? 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('获取配置失败,权重将使用默认值0:', error);
|
||||
}
|
||||
|
||||
// 将播放源均分为两批,并发测速各批,避免一次性过多请求
|
||||
const batchSize = Math.ceil(sources.length / 2);
|
||||
const allResults: Array<{
|
||||
@@ -1602,8 +1586,8 @@ function PlayPageClient() {
|
||||
if (successfulResults.length === 0) {
|
||||
console.warn('所有播放源测速都失败,按权重排序');
|
||||
const sortedByWeight = [...sources].sort((a, b) => {
|
||||
const weightA = weightMap.get(a.source) ?? 0;
|
||||
const weightB = weightMap.get(b.source) ?? 0;
|
||||
const weightA = a.weight ?? 0;
|
||||
const weightB = b.weight ?? 0;
|
||||
return weightB - weightA;
|
||||
});
|
||||
return sortedByWeight[0];
|
||||
@@ -1642,7 +1626,7 @@ function PlayPageClient() {
|
||||
maxSpeed,
|
||||
minPing,
|
||||
maxPing,
|
||||
weightMap.get(result.source.source) ?? 0
|
||||
result.source.weight ?? 0
|
||||
),
|
||||
}));
|
||||
|
||||
|
||||
@@ -177,6 +177,7 @@ export interface SearchResult {
|
||||
episodes_titles: string[];
|
||||
source: string;
|
||||
source_name: string;
|
||||
weight?: number; // 播放源权重(来自后台配置,用于排序和优选评分)
|
||||
class?: string;
|
||||
year: string;
|
||||
desc?: string;
|
||||
|
||||
Reference in New Issue
Block a user