refactor(音乐同步): 优化歌曲匹配逻辑,优先使用提供的songId
当songId存在时,跳过冗余的网易云匹配流程,直接使用songId进行精确匹配 如果精确匹配失败,再回退到基于名称的匹配方式
This commit is contained in:
@@ -93,21 +93,15 @@ async function createJob(req, res) {
|
||||
}
|
||||
|
||||
if (songId) {
|
||||
const songFromWyCloud = await findTheBestMatchFromWyCloud(req.account.uid, {
|
||||
songName: meta.songName,
|
||||
artist: meta.artist,
|
||||
album: meta.album,
|
||||
musicPlatformSongId: songId,
|
||||
});
|
||||
if (!songFromWyCloud) {
|
||||
logger.error(`song not found in wycloud`);
|
||||
res.status(412).send({
|
||||
status: 1,
|
||||
message: "can not find song in wycloud with your songId",
|
||||
});
|
||||
return;
|
||||
}
|
||||
meta.songFromWyCloud = songFromWyCloud;
|
||||
// 直接传递songId给后续处理,避免冗余的网易云匹配
|
||||
// 如果后续需要,可以根据songId进行精确匹配
|
||||
meta.songFromWyCloud = {
|
||||
songId: songId,
|
||||
songName: meta.songName || "",
|
||||
artist: meta.artist || "",
|
||||
album: meta.album || "",
|
||||
};
|
||||
logger.info(`[sync_jobs] Using provided songId: ${songId}, will handle matching later if needed`);
|
||||
}
|
||||
|
||||
// create job
|
||||
|
||||
@@ -154,10 +154,29 @@ module.exports = async function syncSingleSongWithUrl(uid, url, {
|
||||
await updateJobIfNeed(uid, jobId, songInfo, jobType);
|
||||
|
||||
// step 2. find the best match from wycloud
|
||||
if (songFromWyCloud === null) {
|
||||
if (songFromWyCloud && songFromWyCloud.songId) {
|
||||
// 如果已经提供了songId,优先使用它进行精确匹配
|
||||
logger.info(`[syncSingleSongWithUrl] Using provided songId: ${songFromWyCloud.songId}`);
|
||||
try {
|
||||
const wySongInfo = await getWySongInfo(uid, songFromWyCloud.songId);
|
||||
if (wySongInfo) {
|
||||
songFromWyCloud = buildSongInfoFromWyCloud(wySongInfo);
|
||||
logger.info(`[syncSingleSongWithUrl] Found exact match via songId: ${wySongInfo.songName} - ${wySongInfo.artists?.[0] || 'Unknown'}`);
|
||||
} else {
|
||||
logger.warn(`[syncSingleSongWithUrl] songId ${songFromWyCloud.songId} not found in WyCloud, will try name-based matching`);
|
||||
songFromWyCloud = null; // 回退到基于名称的匹配
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[syncSingleSongWithUrl] Error matching songId: ${error.message}`);
|
||||
songFromWyCloud = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有songId或精确匹配失败,进行基于名称的匹配
|
||||
if (!songFromWyCloud) {
|
||||
let findSongName, findArtist, findAlbum;
|
||||
if (songName !== "" && artist !== "") {
|
||||
logger.info(`use the user input song name and artist, ${songName}, ${artist}, ${album}`);
|
||||
logger.info(`[syncSingleSongWithUrl] use the user input song name and artist, ${songName}, ${artist}, ${album}`);
|
||||
findSongName = songName;
|
||||
findArtist = artist;
|
||||
findAlbum = album;
|
||||
@@ -165,17 +184,24 @@ module.exports = async function syncSingleSongWithUrl(uid, url, {
|
||||
findSongName = songInfo.songName;
|
||||
findArtist = songInfo.artist;
|
||||
findAlbum = songInfo.album;
|
||||
}
|
||||
songFromWyCloud = await findTheBestMatchFromWyCloud(uid, {
|
||||
songName: findSongName,
|
||||
artist: findArtist,
|
||||
album: findAlbum,
|
||||
});
|
||||
} else {
|
||||
logger.info(`use the songFromWyCloud by params`);
|
||||
}
|
||||
if (findSongName && findArtist) {
|
||||
songFromWyCloud = await findTheBestMatchFromWyCloud(uid, {
|
||||
songName: findSongName,
|
||||
artist: findArtist,
|
||||
album: findAlbum,
|
||||
});
|
||||
if (songFromWyCloud) {
|
||||
logger.info(`[syncSingleSongWithUrl] Found match via name-based search: ${songFromWyCloud.songName}`);
|
||||
} else {
|
||||
logger.info(`[syncSingleSongWithUrl] No match found in WyCloud, will upload as new song`);
|
||||
}
|
||||
} else {
|
||||
logger.info(`[syncSingleSongWithUrl] No song info available for matching`);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('songFromWyCloud:', songFromWyCloud);
|
||||
logger.info('[syncSingleSongWithUrl] songFromWyCloud:', songFromWyCloud);
|
||||
|
||||
// step 3. download
|
||||
// should add meta tag if not matched song on wycloud
|
||||
|
||||
Reference in New Issue
Block a user