私人影库增加扫描模式
This commit is contained in:
@@ -2766,6 +2766,7 @@ const OpenListConfigComponent = ({
|
||||
const [rootPath, setRootPath] = useState('/');
|
||||
const [offlineDownloadPath, setOfflineDownloadPath] = useState('/');
|
||||
const [scanInterval, setScanInterval] = useState(0);
|
||||
const [scanMode, setScanMode] = useState<'torrent' | 'name' | 'hybrid'>('hybrid');
|
||||
const [videos, setVideos] = useState<any[]>([]);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [scanProgress, setScanProgress] = useState<{
|
||||
@@ -2785,6 +2786,7 @@ const OpenListConfigComponent = ({
|
||||
setRootPath(config.OpenListConfig.RootPath || '/');
|
||||
setOfflineDownloadPath(config.OpenListConfig.OfflineDownloadPath || '/');
|
||||
setScanInterval(config.OpenListConfig.ScanInterval || 0);
|
||||
setScanMode(config.OpenListConfig.ScanMode || 'hybrid');
|
||||
}
|
||||
}, [config]);
|
||||
|
||||
@@ -2825,6 +2827,7 @@ const OpenListConfigComponent = ({
|
||||
RootPath: rootPath,
|
||||
OfflineDownloadPath: offlineDownloadPath,
|
||||
ScanInterval: scanInterval,
|
||||
ScanMode: scanMode,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -3151,6 +3154,25 @@ const OpenListConfigComponent = ({
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
扫描模式
|
||||
</label>
|
||||
<select
|
||||
value={scanMode}
|
||||
onChange={(e) => setScanMode(e.target.value as 'torrent' | 'name' | 'hybrid')}
|
||||
disabled={!enabled}
|
||||
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed'
|
||||
>
|
||||
<option value='hybrid'>混合模式(推荐)</option>
|
||||
<option value='torrent'>种子库匹配</option>
|
||||
<option value='name'>名字匹配</option>
|
||||
</select>
|
||||
<p className='mt-1 text-xs text-gray-500 dark:text-gray-400'>
|
||||
混合模式:先用种子库匹配,失败后降级为名字匹配
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className='flex gap-3'>
|
||||
<button
|
||||
onClick={handleCheckConnectivity}
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { action, Enabled, URL, Username, Password, RootPath, OfflineDownloadPath, ScanInterval } = body;
|
||||
const { action, Enabled, URL, Username, Password, RootPath, OfflineDownloadPath, ScanInterval, ScanMode } = body;
|
||||
|
||||
const authInfo = getAuthInfoFromCookie(request);
|
||||
if (!authInfo || !authInfo.username) {
|
||||
@@ -58,6 +58,7 @@ export async function POST(request: NextRequest) {
|
||||
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
||||
ResourceCount: adminConfig.OpenListConfig?.ResourceCount,
|
||||
ScanInterval: 0,
|
||||
ScanMode: ScanMode || 'hybrid',
|
||||
};
|
||||
|
||||
await db.saveAdminConfig(adminConfig);
|
||||
@@ -108,6 +109,7 @@ export async function POST(request: NextRequest) {
|
||||
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
||||
ResourceCount: adminConfig.OpenListConfig?.ResourceCount,
|
||||
ScanInterval: scanInterval,
|
||||
ScanMode: ScanMode || 'hybrid',
|
||||
};
|
||||
|
||||
await db.saveAdminConfig(adminConfig);
|
||||
|
||||
@@ -111,6 +111,7 @@ export interface AdminConfig {
|
||||
LastRefreshTime?: number; // 上次刷新时间戳
|
||||
ResourceCount?: number; // 资源数量
|
||||
ScanInterval?: number; // 定时扫描间隔(分钟),0表示关闭,最低60分钟
|
||||
ScanMode?: 'torrent' | 'name' | 'hybrid'; // 扫描模式:torrent=种子库匹配,name=名字匹配,hybrid=混合模式(默认)
|
||||
};
|
||||
AIConfig?: {
|
||||
Enabled: boolean; // 是否启用AI问片功能
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
} from '@/lib/scan-task';
|
||||
import { parseSeasonFromTitle } from '@/lib/season-parser';
|
||||
import { searchTMDB, getTVSeasonDetails } from '@/lib/tmdb.search';
|
||||
import parseTorrentName from 'parse-torrent-name';
|
||||
|
||||
/**
|
||||
* 启动 OpenList 刷新任务
|
||||
@@ -55,7 +56,8 @@ export async function startOpenListRefresh(clearMetaInfo: boolean = false): Prom
|
||||
tmdbProxy,
|
||||
openListConfig.Username,
|
||||
openListConfig.Password,
|
||||
clearMetaInfo
|
||||
clearMetaInfo,
|
||||
openListConfig.ScanMode || 'hybrid'
|
||||
).catch((error) => {
|
||||
console.error('[OpenList Refresh] 后台扫描失败:', error);
|
||||
failScanTask(taskId, (error as Error).message);
|
||||
@@ -75,7 +77,8 @@ async function performScan(
|
||||
tmdbProxy?: string,
|
||||
username?: string,
|
||||
password?: string,
|
||||
clearMetaInfo?: boolean
|
||||
clearMetaInfo?: boolean,
|
||||
scanMode: 'torrent' | 'name' | 'hybrid' = 'hybrid'
|
||||
): Promise<void> {
|
||||
const client = new OpenListClient(url, username!, password!);
|
||||
|
||||
@@ -161,18 +164,34 @@ async function performScan(
|
||||
existingKeys.add(folderKey);
|
||||
|
||||
try {
|
||||
const seasonInfo = parseSeasonFromTitle(folder.name);
|
||||
const searchQuery = seasonInfo.cleanTitle || folder.name;
|
||||
let searchQuery: string;
|
||||
let seasonNumber: number | null = null;
|
||||
let year: number | null = null;
|
||||
let searchResult: any;
|
||||
|
||||
console.log(`[OpenList Refresh] 处理文件夹: ${folder.name}`);
|
||||
console.log(`[OpenList Refresh] 清理后标题: ${searchQuery}, 季度: ${seasonInfo.seasonNumber}, 年份: ${seasonInfo.year}`);
|
||||
if (scanMode === 'torrent' || scanMode === 'hybrid') {
|
||||
const torrentInfo = parseTorrentName(folder.name);
|
||||
searchQuery = torrentInfo.title || folder.name;
|
||||
seasonNumber = torrentInfo.season || null;
|
||||
year = torrentInfo.year || null;
|
||||
|
||||
const searchResult = await searchTMDB(
|
||||
tmdbApiKey,
|
||||
searchQuery,
|
||||
tmdbProxy,
|
||||
seasonInfo.year || undefined
|
||||
);
|
||||
console.log(`[OpenList Refresh] 种子库模式 - 文件夹: ${folder.name}`);
|
||||
console.log(`[OpenList Refresh] 解析结果 - 标题: ${searchQuery}, 季度: ${seasonNumber}, 年份: ${year}`);
|
||||
|
||||
searchResult = await searchTMDB(tmdbApiKey, searchQuery, tmdbProxy, year || undefined);
|
||||
}
|
||||
|
||||
if (scanMode === 'name' || (scanMode === 'hybrid' && (!searchResult || searchResult.code !== 200 || !searchResult.result))) {
|
||||
const seasonInfo = parseSeasonFromTitle(folder.name);
|
||||
searchQuery = seasonInfo.cleanTitle || folder.name;
|
||||
seasonNumber = seasonInfo.seasonNumber;
|
||||
year = seasonInfo.year;
|
||||
|
||||
console.log(`[OpenList Refresh] 名字匹配模式 - 文件夹: ${folder.name}`);
|
||||
console.log(`[OpenList Refresh] 清理后标题: ${searchQuery}, 季度: ${seasonNumber}, 年份: ${year}`);
|
||||
|
||||
searchResult = await searchTMDB(tmdbApiKey, searchQuery, tmdbProxy, year || undefined);
|
||||
}
|
||||
|
||||
if (searchResult.code === 200 && searchResult.result) {
|
||||
const result = searchResult.result;
|
||||
@@ -190,12 +209,12 @@ async function performScan(
|
||||
failed: false,
|
||||
};
|
||||
|
||||
if (result.media_type === 'tv' && seasonInfo.seasonNumber) {
|
||||
if (result.media_type === 'tv' && seasonNumber) {
|
||||
try {
|
||||
const seasonDetails = await getTVSeasonDetails(
|
||||
tmdbApiKey,
|
||||
result.id,
|
||||
seasonInfo.seasonNumber,
|
||||
seasonNumber,
|
||||
tmdbProxy
|
||||
);
|
||||
|
||||
@@ -217,12 +236,12 @@ async function performScan(
|
||||
folderInfo.release_date = seasonDetails.season.air_date;
|
||||
}
|
||||
} else {
|
||||
console.warn(`[OpenList Refresh] 获取季度 ${seasonInfo.seasonNumber} 详情失败`);
|
||||
folderInfo.season_number = seasonInfo.seasonNumber;
|
||||
console.warn(`[OpenList Refresh] 获取季度 ${seasonNumber} 详情失败`);
|
||||
folderInfo.season_number = seasonNumber;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[OpenList Refresh] 获取季度详情异常:`, error);
|
||||
folderInfo.season_number = seasonInfo.seasonNumber;
|
||||
folderInfo.season_number = seasonNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user