fix: 修复歌曲播放URL处理逻辑并添加元数据获取错误提示

修复播放URL处理逻辑,统一从getPlayableUrl方法获取可播放URL
添加歌曲元数据获取失败时的错误提示
确保songId字段在mapTunehubResult中始终有默认值
This commit is contained in:
史悦
2026-01-07 17:31:27 +08:00
parent 6baa2c4868
commit 3656432653
4 changed files with 41 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ function mapTunehubResult(item) {
const playUrl = item.url || buildSongUrl(item.platform, item.id);
const pageUrl = buildPageUrl(item.platform, item.id);
return {
songId: item.id || '',
songName: item.name || '',
artist: item.artist || '',
album: item.album || '',

View File

@@ -167,6 +167,7 @@ import { getPlayUrl, getSongsMeta, createSyncSongFromUrlJob } from "./api";
import { startTaskListener } from "./components/TaskNotification";
import storage from "./utils/storage";
import { getProperPlayUrl } from "./utils/audio";
import { ElMessage } from "element-plus";
export default {
data: () => {
@@ -226,6 +227,15 @@ export default {
let info = metaInfo;
if (!info) {
const ret = await getSongsMeta({ url: pageUrl });
if (!ret || !ret.data || !ret.data.songMeta) {
console.warn("获取歌曲元数据失败", ret);
ElMessage({
message: "获取歌曲元数据失败,无法播放",
type: "warning",
duration: 1500,
});
return false;
}
info = ret.data.songMeta;
console.log(ret);
}

View File

@@ -172,6 +172,18 @@ export default {
}
return item.pageUrl || item.url || "";
},
getPlayableUrl(item) {
if (!item) {
return "";
}
if (item.playUrl) {
return item.playUrl;
}
if (item.url && item.url.indexOf("music-dl.sayqz.com/api/") >= 0) {
return item.url;
}
return "";
},
async uploadToCloud(pageUrl) {
const ret = await createSyncSongFromUrlJob(
pageUrl,
@@ -200,9 +212,10 @@ export default {
}
this.currentSongIndex = index;
const pageUrl = this.getSourceUrl(item);
if (this.playTheSongWithPlayUrl && item && item.playUrl) {
const playUrl = this.getPlayableUrl(item);
if (this.playTheSongWithPlayUrl && playUrl) {
this.playTheSongWithPlayUrl({
playUrl: item.playUrl,
playUrl,
coverUrl: item.coverUrl,
songName: item.songName,
artist: item.artist,

View File

@@ -281,6 +281,18 @@ export default {
}
return row.pageUrl || row.url || "";
},
getPlayableUrl(row) {
if (!row) {
return "";
}
if (row.playUrl) {
return row.playUrl;
}
if (row.url && row.url.indexOf("music-dl.sayqz.com/api/") >= 0) {
return row.url;
}
return "";
},
async uploadToCloud(row) {
const pageUrl = this.getSourceUrl(row);
const ret = await createSyncSongFromUrlJob(
@@ -314,9 +326,10 @@ export default {
play(row) {
const pageUrl = this.getSourceUrl(row);
this.currentSongUrl = row && row.url ? row.url : pageUrl;
if (this.playTheSongWithPlayUrl && row && row.playUrl) {
const playUrl = this.getPlayableUrl(row);
if (this.playTheSongWithPlayUrl && playUrl) {
this.playTheSongWithPlayUrl({
playUrl: row.playUrl,
playUrl,
coverUrl: row.coverUrl,
songName: row.songName,
artist: row.artist,