diff --git a/backend/src/handler/songs.js b/backend/src/handler/songs.js index 4bb05c9..4cd1301 100644 --- a/backend/src/handler/songs.js +++ b/backend/src/handler/songs.js @@ -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 || '', diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 77ec23a..7c07bc0 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -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); } diff --git a/frontend/src/components/SearchResultListForMobile.vue b/frontend/src/components/SearchResultListForMobile.vue index 125bc14..2317443 100644 --- a/frontend/src/components/SearchResultListForMobile.vue +++ b/frontend/src/components/SearchResultListForMobile.vue @@ -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, diff --git a/frontend/src/components/SearchResultTable.vue b/frontend/src/components/SearchResultTable.vue index 42ee60e..23fa98a 100644 --- a/frontend/src/components/SearchResultTable.vue +++ b/frontend/src/components/SearchResultTable.vue @@ -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,