fix: 修复歌曲播放URL处理逻辑并添加元数据获取错误提示
修复播放URL处理逻辑,统一从getPlayableUrl方法获取可播放URL 添加歌曲元数据获取失败时的错误提示 确保songId字段在mapTunehubResult中始终有默认值
This commit is contained in:
@@ -20,6 +20,7 @@ function mapTunehubResult(item) {
|
|||||||
const playUrl = item.url || buildSongUrl(item.platform, item.id);
|
const playUrl = item.url || buildSongUrl(item.platform, item.id);
|
||||||
const pageUrl = buildPageUrl(item.platform, item.id);
|
const pageUrl = buildPageUrl(item.platform, item.id);
|
||||||
return {
|
return {
|
||||||
|
songId: item.id || '',
|
||||||
songName: item.name || '',
|
songName: item.name || '',
|
||||||
artist: item.artist || '',
|
artist: item.artist || '',
|
||||||
album: item.album || '',
|
album: item.album || '',
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ import { getPlayUrl, getSongsMeta, createSyncSongFromUrlJob } from "./api";
|
|||||||
import { startTaskListener } from "./components/TaskNotification";
|
import { startTaskListener } from "./components/TaskNotification";
|
||||||
import storage from "./utils/storage";
|
import storage from "./utils/storage";
|
||||||
import { getProperPlayUrl } from "./utils/audio";
|
import { getProperPlayUrl } from "./utils/audio";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: () => {
|
data: () => {
|
||||||
@@ -226,6 +227,15 @@ export default {
|
|||||||
let info = metaInfo;
|
let info = metaInfo;
|
||||||
if (!info) {
|
if (!info) {
|
||||||
const ret = await getSongsMeta({ url: pageUrl });
|
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;
|
info = ret.data.songMeta;
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,18 @@ export default {
|
|||||||
}
|
}
|
||||||
return item.pageUrl || item.url || "";
|
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) {
|
async uploadToCloud(pageUrl) {
|
||||||
const ret = await createSyncSongFromUrlJob(
|
const ret = await createSyncSongFromUrlJob(
|
||||||
pageUrl,
|
pageUrl,
|
||||||
@@ -200,9 +212,10 @@ export default {
|
|||||||
}
|
}
|
||||||
this.currentSongIndex = index;
|
this.currentSongIndex = index;
|
||||||
const pageUrl = this.getSourceUrl(item);
|
const pageUrl = this.getSourceUrl(item);
|
||||||
if (this.playTheSongWithPlayUrl && item && item.playUrl) {
|
const playUrl = this.getPlayableUrl(item);
|
||||||
|
if (this.playTheSongWithPlayUrl && playUrl) {
|
||||||
this.playTheSongWithPlayUrl({
|
this.playTheSongWithPlayUrl({
|
||||||
playUrl: item.playUrl,
|
playUrl,
|
||||||
coverUrl: item.coverUrl,
|
coverUrl: item.coverUrl,
|
||||||
songName: item.songName,
|
songName: item.songName,
|
||||||
artist: item.artist,
|
artist: item.artist,
|
||||||
|
|||||||
@@ -281,6 +281,18 @@ export default {
|
|||||||
}
|
}
|
||||||
return row.pageUrl || row.url || "";
|
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) {
|
async uploadToCloud(row) {
|
||||||
const pageUrl = this.getSourceUrl(row);
|
const pageUrl = this.getSourceUrl(row);
|
||||||
const ret = await createSyncSongFromUrlJob(
|
const ret = await createSyncSongFromUrlJob(
|
||||||
@@ -314,9 +326,10 @@ export default {
|
|||||||
play(row) {
|
play(row) {
|
||||||
const pageUrl = this.getSourceUrl(row);
|
const pageUrl = this.getSourceUrl(row);
|
||||||
this.currentSongUrl = row && row.url ? row.url : pageUrl;
|
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({
|
this.playTheSongWithPlayUrl({
|
||||||
playUrl: row.playUrl,
|
playUrl,
|
||||||
coverUrl: row.coverUrl,
|
coverUrl: row.coverUrl,
|
||||||
songName: row.songName,
|
songName: row.songName,
|
||||||
artist: row.artist,
|
artist: row.artist,
|
||||||
|
|||||||
Reference in New Issue
Block a user