refactor(playlists): 移除 Tunehub 相关代码并统一使用网易云 API
删除不再使用的 Tunehub 歌单处理逻辑,统一使用网易云音乐 API 获取歌单详情。修改 listSongsFromPlaylist 方法直接调用 getSongsFromPlaylist 接口,简化代码结构并确保版权信息正确。
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const logger = require('consola');
|
||||
const { getUserAllPlaylist } = require('../service/music_platform/wycloud');
|
||||
const { getPlaylistDetail } = require('../service/music_platform/tunehub');
|
||||
const { getUserAllPlaylist, getSongsFromPlaylist } = require('../service/music_platform/wycloud');
|
||||
const Source = require('../consts/source').consts;
|
||||
|
||||
function splitArtists(artist) {
|
||||
@@ -13,38 +12,6 @@ function splitArtists(artist) {
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function normalizeTunehubPlaylist(playlistId, detail) {
|
||||
const info = detail && detail.info ? detail.info : {};
|
||||
const list = detail && Array.isArray(detail.list) ? detail.list : [];
|
||||
|
||||
const songs = list.map(item => {
|
||||
const artists = splitArtists(item.artist);
|
||||
const primaryArtist = artists[0] || item.artist || '';
|
||||
const cover = item.pic || info.pic || '';
|
||||
const isBlocked = !item.types || item.types.length === 0;
|
||||
return {
|
||||
songId: item.id,
|
||||
songName: item.name || '',
|
||||
artists,
|
||||
artist: primaryArtist,
|
||||
duration: 0,
|
||||
album: item.album || '',
|
||||
cover,
|
||||
pageUrl: `https://music.163.com/song?id=${item.id}`,
|
||||
playUrl: item.url || '',
|
||||
isBlocked,
|
||||
isCloud: false,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: playlistId,
|
||||
name: info.name || '',
|
||||
cover: info.pic || '',
|
||||
songs,
|
||||
};
|
||||
}
|
||||
|
||||
async function listAllPlaylists(req, res) {
|
||||
const uid = req.account.uid;
|
||||
const playlists = await getUserAllPlaylist(uid);
|
||||
@@ -72,16 +39,22 @@ async function listSongsFromPlaylist(req, res) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const detail = await getPlaylistDetail(source, playlistId);
|
||||
if (detail === false) {
|
||||
logger.error(`get playlist detail failed, uid: ${uid}`);
|
||||
|
||||
// 使用网易云 API 获取歌单详情(包含正确的版权信息)
|
||||
const playlist = await getSongsFromPlaylist(uid, source, playlistId);
|
||||
if (playlist === false) {
|
||||
logger.error(`get playlist detail failed, uid: ${uid}, playlistId: ${playlistId}`);
|
||||
res.send({
|
||||
status: 1,
|
||||
message: "获取歌单详情失败",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const playlists = detail ? normalizeTunehubPlaylist(playlistId, detail) : false;
|
||||
|
||||
res.send({
|
||||
status: playlists ? 0 : 1,
|
||||
status: 0,
|
||||
data: {
|
||||
playlists: playlists ? playlists : [],
|
||||
playlists: playlist,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user