fix: 修复无法优选 qq 平台匹配 (#409)
PLATFORM_ORDER 优选平台匹配自 PR #167 起改为依据番剧身份(标题 from 段或 source)与目标平台评分。当源身份名与配置平台名不一致、但集上挂有目标平台标签时(如 tencent 源、集标题挂 qq),getPlatformMatchScore(identity, "qq") 得 0,与无交集的 dandan 同为 0 分,平局由 SOURCE_ORDER 决定,导致配置 qq 却选中 dandan 而非 tencent。 现于 matchAniAndEp 评分时,将命中集所挂平台标签并入候选平台(与身份标签去重合并),使 tencent 这类源在集上挂有 qq 时能正确加分。同时 getPlatformMatchScore 预处理支持全角&并去重,修正合并标题重复标签(如 dandan&qiyi&qiyi)抬高杂质长度导致评分失真的问题。该加性改动不影响既有的合并源优选评分(已以 40 例用例验证,含合并源、正常单源、全角&、去重及手动优选绝对优先等场景)。
This commit is contained in:
1 parent
e8f22b621f
commit
ef003d7882
1 file changed
+11
-7
@@ -972,9 +972,9 @@ export function filterSameEpisodeTitle(filteredTmpEpisodes) {
|
||||
function getPlatformMatchScore(candidatePlatform, targetPlatform) {
|
||||
if (!candidatePlatform || !targetPlatform) return 0;
|
||||
|
||||
// 预处理:按 & 分割,转小写,去空格
|
||||
const cParts = candidatePlatform.split('&').map(s => s.trim().toLowerCase()).filter(s => s);
|
||||
const tParts = targetPlatform.split('&').map(s => s.trim().toLowerCase()).filter(s => s);
|
||||
// 预处理:按半角/全角 & 分割,转小写去空格并去重,避免合并标题重复标签抬高杂质长度导致评分失真
|
||||
const cParts = [...new Set(candidatePlatform.split(/[&&]/).map(s => s.trim().toLowerCase()).filter(s => s))];
|
||||
const tParts = [...new Set(targetPlatform.split(/[&&]/).map(s => s.trim().toLowerCase()).filter(s => s))];
|
||||
|
||||
let matchCount = 0;
|
||||
|
||||
@@ -1002,7 +1002,7 @@ function getPlatformMatchScore(candidatePlatform, targetPlatform) {
|
||||
|
||||
// 辅助函数:从标题中提取来源平台列表 (新增函数 - 适配合并源标题格式)
|
||||
function extractPlatformFromTitle(title) {
|
||||
const match = title.match(/from\s+([a-zA-Z0-9&]+)/i);
|
||||
const match = title.match(/from\s+([a-zA-Z0-9&&]+)/i);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
|
||||
@@ -1439,12 +1439,16 @@ async function matchAniAndEp(season, episode, year, searchData, title, req, plat
|
||||
// 3. 匹配结果处理与评分比较
|
||||
if (matchedEpisode) {
|
||||
// 计算当前匹配的得分
|
||||
const actualPlatform = extractPlatformFromTitle(anime.animeTitle) || anime.source;
|
||||
// 候选平台由番剧身份标签(标题 from 段或 source)与命中集所挂平台标签共同决定,使身份名(如 tencent)与优选平台名(如 qq)不一致但集上挂有该标签的源也能正确加分
|
||||
const identityPlatform = extractPlatformFromTitle(anime.animeTitle) || anime.source;
|
||||
const epPlatform = matchedEpisode ? extractEpisodeTitle(matchedEpisode.episodeTitle) : null;
|
||||
const candidatePlatform = [...new Set([identityPlatform, epPlatform].filter(Boolean)
|
||||
.flatMap(p => p.split(/[&&]/).map(s => s.trim().toLowerCase())).filter(s => s))].join('&');
|
||||
let currentScore = 0;
|
||||
|
||||
|
||||
if (platform) {
|
||||
// 如果指定了平台偏好,计算匹配得分
|
||||
currentScore = getPlatformMatchScore(actualPlatform, platform);
|
||||
currentScore = getPlatformMatchScore(candidatePlatform, platform);
|
||||
} else {
|
||||
// 如果没有指定平台偏好,默认为 1
|
||||
currentScore = 1;
|
||||
|
||||
Reference in new issue
Block a user