优化视频权重获取方式
This commit is contained in:
@@ -83,6 +83,7 @@ export async function GET(request: NextRequest) {
|
|||||||
id: item.Id,
|
id: item.Id,
|
||||||
source: sourceValue,
|
source: sourceValue,
|
||||||
source_name: sourceName,
|
source_name: sourceName,
|
||||||
|
weight: weightMap.get(sourceValue) ?? 0,
|
||||||
title: item.Name,
|
title: item.Name,
|
||||||
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
||||||
episodes: [],
|
episodes: [],
|
||||||
@@ -138,6 +139,7 @@ export async function GET(request: NextRequest) {
|
|||||||
id: folderName,
|
id: folderName,
|
||||||
source: 'openlist',
|
source: 'openlist',
|
||||||
source_name: '私人影库',
|
source_name: '私人影库',
|
||||||
|
weight: weightMap.get('openlist') ?? 0,
|
||||||
title: info.title,
|
title: info.title,
|
||||||
poster: getTMDBImageUrl(info.poster_path),
|
poster: getTMDBImageUrl(info.poster_path),
|
||||||
episodes: [],
|
episodes: [],
|
||||||
@@ -195,6 +197,11 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
let flattenedResults = [...openlistResults, ...embyResults, ...apiResultsFlat];
|
let flattenedResults = [...openlistResults, ...embyResults, ...apiResultsFlat];
|
||||||
|
|
||||||
|
flattenedResults = flattenedResults.map((result) => ({
|
||||||
|
...result,
|
||||||
|
weight: result.weight ?? (weightMap.get(result.source) ?? 0),
|
||||||
|
}));
|
||||||
|
|
||||||
if (!config.SiteConfig.DisableYellowFilter) {
|
if (!config.SiteConfig.DisableYellowFilter) {
|
||||||
flattenedResults = flattenedResults.filter((result) => {
|
flattenedResults = flattenedResults.filter((result) => {
|
||||||
const typeName = result.type_name || '';
|
const typeName = result.type_name || '';
|
||||||
@@ -204,8 +211,8 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
// 按权重降序排序
|
// 按权重降序排序
|
||||||
flattenedResults.sort((a, b) => {
|
flattenedResults.sort((a, b) => {
|
||||||
const weightA = weightMap.get(a.source) ?? 0;
|
const weightA = a.weight ?? 0;
|
||||||
const weightB = weightMap.get(b.source) ?? 0;
|
const weightB = b.weight ?? 0;
|
||||||
return weightB - weightA;
|
return weightB - weightA;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ export async function GET(request: NextRequest) {
|
|||||||
id: item.Id,
|
id: item.Id,
|
||||||
source: sourceValue,
|
source: sourceValue,
|
||||||
source_name: sourceName,
|
source_name: sourceName,
|
||||||
|
weight: weightMap.get(sourceValue) ?? 0,
|
||||||
title: item.Name,
|
title: item.Name,
|
||||||
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
poster: client.getImageUrl(item.Id, 'Primary', undefined, client.isProxyEnabled() ? proxyToken || undefined : undefined),
|
||||||
episodes: [],
|
episodes: [],
|
||||||
@@ -253,6 +254,7 @@ export async function GET(request: NextRequest) {
|
|||||||
id: key,
|
id: key,
|
||||||
source: 'openlist',
|
source: 'openlist',
|
||||||
source_name: '私人影库',
|
source_name: '私人影库',
|
||||||
|
weight: weightMap.get('openlist') ?? 0,
|
||||||
title: info.title,
|
title: info.title,
|
||||||
poster: getTMDBImageUrl(info.poster_path),
|
poster: getTMDBImageUrl(info.poster_path),
|
||||||
episodes: [],
|
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++;
|
completedSources++;
|
||||||
|
|
||||||
|
|||||||
+3
-19
@@ -1504,22 +1504,6 @@ function PlayPageClient() {
|
|||||||
): Promise<SearchResult> => {
|
): Promise<SearchResult> => {
|
||||||
if (sources.length === 1) return sources[0];
|
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 batchSize = Math.ceil(sources.length / 2);
|
||||||
const allResults: Array<{
|
const allResults: Array<{
|
||||||
@@ -1602,8 +1586,8 @@ function PlayPageClient() {
|
|||||||
if (successfulResults.length === 0) {
|
if (successfulResults.length === 0) {
|
||||||
console.warn('所有播放源测速都失败,按权重排序');
|
console.warn('所有播放源测速都失败,按权重排序');
|
||||||
const sortedByWeight = [...sources].sort((a, b) => {
|
const sortedByWeight = [...sources].sort((a, b) => {
|
||||||
const weightA = weightMap.get(a.source) ?? 0;
|
const weightA = a.weight ?? 0;
|
||||||
const weightB = weightMap.get(b.source) ?? 0;
|
const weightB = b.weight ?? 0;
|
||||||
return weightB - weightA;
|
return weightB - weightA;
|
||||||
});
|
});
|
||||||
return sortedByWeight[0];
|
return sortedByWeight[0];
|
||||||
@@ -1642,7 +1626,7 @@ function PlayPageClient() {
|
|||||||
maxSpeed,
|
maxSpeed,
|
||||||
minPing,
|
minPing,
|
||||||
maxPing,
|
maxPing,
|
||||||
weightMap.get(result.source.source) ?? 0
|
result.source.weight ?? 0
|
||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ export interface SearchResult {
|
|||||||
episodes_titles: string[];
|
episodes_titles: string[];
|
||||||
source: string;
|
source: string;
|
||||||
source_name: string;
|
source_name: string;
|
||||||
|
weight?: number; // 播放源权重(来自后台配置,用于排序和优选评分)
|
||||||
class?: string;
|
class?: string;
|
||||||
year: string;
|
year: string;
|
||||||
desc?: string;
|
desc?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user