From f1a295cd75829120741513a88c34c3b1204f5736 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 5 Jan 2026 20:42:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=81=9A=E5=90=88=E8=A7=84?= =?UTF-8?q?=E5=88=99=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/play/page.tsx | 17 +++++++++++++---- src/app/search/page.tsx | 13 +++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index 2f914dc..b072243 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -2228,6 +2228,15 @@ function PlayPageClient() { setSourceSearchLoading(false); } }; + + // 规范化标题用于聚合(去除特殊符号、括号、空格和全角空格) + const normalizeTitle = (title: string) => { + return title + .replace(/[\s\u3000]/g, '') // 去除空格和全角空格 + .replace(/[()()[\]【】{}「」『』<>《》]/g, '') // 去除各种括号 + .replace(/[^\w\u4e00-\u9fa5]/g, ''); // 去除特殊符号,保留字母、数字、下划线和中文 + }; + const fetchSourcesData = async (query: string): Promise => { // 根据搜索词获取全部源信息 try { @@ -2245,8 +2254,8 @@ function PlayPageClient() { // 处理缓存的搜索结果,根据规则过滤 results = cachedData.filter( (result: SearchResult) => - result.title.replaceAll(' ', '').toLowerCase() === - videoTitleRef.current.replaceAll(' ', '').toLowerCase() && + normalizeTitle(result.title).toLowerCase() === + normalizeTitle(videoTitleRef.current).toLowerCase() && (videoYearRef.current ? result.year.toLowerCase() === videoYearRef.current.toLowerCase() : true) && @@ -2280,8 +2289,8 @@ function PlayPageClient() { // 处理搜索结果,根据规则过滤 results = data.results.filter( (result: SearchResult) => - result.title.replaceAll(' ', '').toLowerCase() === - videoTitleRef.current.replaceAll(' ', '').toLowerCase() && + normalizeTitle(result.title).toLowerCase() === + normalizeTitle(videoTitleRef.current).toLowerCase() && (videoYearRef.current ? result.year.toLowerCase() === videoYearRef.current.toLowerCase() : true) && diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx index baf0cc4..3a0a091 100644 --- a/src/app/search/page.tsx +++ b/src/app/search/page.tsx @@ -212,14 +212,23 @@ function SearchPageClient() { return order === 'asc' ? aNum - bNum : bNum - aNum; }; + // 规范化标题用于聚合(去除特殊符号、括号、空格和全角空格) + const normalizeTitle = (title: string) => { + return title + .replace(/[\s\u3000]/g, '') // 去除空格和全角空格 + .replace(/[()()[\]【】{}「」『』<>《》]/g, '') // 去除各种括号 + .replace(/[^\w\u4e00-\u9fa5]/g, ''); // 去除特殊符号,保留字母、数字、下划线和中文 + }; + // 聚合后的结果(按标题和年份分组) const aggregatedResults = useMemo(() => { const map = new Map(); const keyOrder: string[] = []; // 记录键出现的顺序 searchResults.forEach((item) => { - // 使用 title + year + type 作为键,year 必然存在,但依然兜底 'unknown' - const key = `${item.title.replaceAll(' ', '')}-${item.year || 'unknown' + // 使用规范化后的 title + year + type 作为键,year 必然存在,但依然兜底 'unknown' + const normalizedTitle = normalizeTitle(item.title); + const key = `${normalizedTitle}-${item.year || 'unknown' }-${item.episodes.length === 1 ? 'movie' : 'tv'}`; const arr = map.get(key) || [];