优化小雅匹配数据

This commit is contained in:
mtvpls
2026-01-12 12:17:00 +08:00
parent 7655eee23d
commit ffd29e009a
4 changed files with 39 additions and 10 deletions

View File

@@ -207,6 +207,8 @@ export async function GET(request: NextRequest) {
proxyMode: false,
// 返回用户点击的文件索引(如果找到的话)
initialEpisodeIndex: clickedFileIndex >= 0 ? clickedFileIndex : undefined,
// 返回元数据来源
metadataSource: metadata.source,
};
return NextResponse.json(result);

View File

@@ -2677,8 +2677,10 @@ function PlayPageClient() {
newUrl.searchParams.set('year', detailData.year);
// 保持原有的 title不更新
newUrl.searchParams.delete('prefer');
// 删除fileName参数,避免换集后刷新跳回到最初点击的那一集
newUrl.searchParams.delete('fileName');
// 只有当元数据不是从文件获取时,才删除fileName参数
if (detailData.metadataSource !== 'file') {
newUrl.searchParams.delete('fileName');
}
window.history.replaceState({}, '', newUrl.toString());
setLoadingStage('ready');

View File

@@ -140,6 +140,7 @@ export interface SearchResult {
tmdb_id?: number; // TMDB ID
rating?: number; // 评分
initialEpisodeIndex?: number; // 初始集数索引(用于小雅源从文件点击进入时指定集数)
metadataSource?: 'folder' | 'nfo' | 'tmdb' | 'file'; // 元数据来源用于小雅源判断是否保留fileName
}
// 豆瓣数据结构

View File

@@ -14,7 +14,7 @@ export interface XiaoyaMetadata {
poster?: string;
background?: string;
mediaType: 'movie' | 'tv';
source: 'folder' | 'nfo' | 'tmdb';
source: 'folder' | 'nfo' | 'tmdb' | 'file';
}
/**
@@ -48,18 +48,32 @@ async function findNFO(
videoPath: string
): Promise<NFOMetadata | null> {
const pathParts = videoPath.split('/').filter(Boolean);
const parentDir = pathParts.slice(0, -1).join('/');
const isInSeasonDir = /(season\s*\d+|s\d+)/i.test(parentDir);
// 判断是否为文件路径
const videoExtensions = ['.mp4', '.mkv', '.avi', '.m3u8', '.flv', '.ts', '.mov', '.wmv', '.webm'];
const isFilePath = videoExtensions.some(ext => videoPath.toLowerCase().endsWith(ext));
let isInSeasonDir = false;
if (isFilePath) {
// 文件路径:判断父目录是否为季度目录
const parentDir = pathParts[pathParts.length - 2];
isInSeasonDir = /(season\s*\d+|s\d+)/i.test(parentDir);
} else {
// 目录路径:判断当前目录是否为季度目录
const currentDir = pathParts[pathParts.length - 1];
isInSeasonDir = /(season\s*\d+|s\d+)/i.test(currentDir);
}
const nfoSearchPaths: string[] = [];
if (isInSeasonDir) {
// 电视剧:查父级的 tvshow.nfo
const grandParentDir = pathParts.slice(0, -2).join('/');
const grandParentDir = pathParts.slice(0, isFilePath ? -2 : -1).join('/');
nfoSearchPaths.push(`/${grandParentDir}/tvshow.nfo`);
} else {
// 电影:查同级的 movie.nfo
const parentDir = pathParts.slice(0, isFilePath ? -1 : pathParts.length).join('/');
nfoSearchPaths.push(`/${parentDir}/movie.nfo`);
}
@@ -123,8 +137,18 @@ export async function getXiaoyaMetadata(
metadataDir = '';
folderName = pathParts[0];
} else {
metadataDir = pathParts.slice(0, -1).join('/');
folderName = pathParts[pathParts.length - 1];
// 判断当前目录是否为季度目录
const currentDirName = pathParts[pathParts.length - 1];
const isSeasonDir = /(season\s*\d+|s\d+)/i.test(currentDirName);
if (isSeasonDir && pathParts.length >= 2) {
// 季度目录:使用父级目录名
metadataDir = pathParts.slice(0, -2).join('/');
folderName = pathParts[pathParts.length - 2];
} else {
metadataDir = pathParts.slice(0, -1).join('/');
folderName = pathParts[pathParts.length - 1];
}
}
}
@@ -153,7 +177,7 @@ export async function getXiaoyaMetadata(
poster: posterUrl,
background: backgroundUrl,
mediaType: isInSeasonDir ? 'tv' : 'movie',
source: nfoData ? 'nfo' : 'folder',
source: nfoData ? 'nfo' : (isFilePath ? 'file' : 'folder'),
};
}
@@ -206,7 +230,7 @@ export async function getXiaoyaMetadata(
? getTMDBImageUrl(tmdbResult.result.poster_path)
: undefined,
mediaType: tmdbResult.result.media_type,
source: 'tmdb',
source: isFilePath ? 'file' : 'tmdb',
};
}
}