Skip to content

Commit

Permalink
updated playlistFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
gnehs committed Oct 9, 2021
1 parent d3e397c commit c97122d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
6 changes: 4 additions & 2 deletions dataModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ router.get("/album/", async (req, res) => {
router.get("/playlists/", async (req, res) => {
//http://localhost:3000/pokaapi/playlists
let r = {
playlists: []
playlists: [],
playlistFolders: []
};
for (var i in Object.keys(moduleList)) {
let x = moduleList[Object.keys(moduleList)[i]];
Expand All @@ -295,7 +296,8 @@ router.get("/playlists/", async (req, res) => {
try {
let list = (await y.getPlaylists(req.session.user)) || null;
if (list) {
for (i = 0; i < list.playlists.length; i++) r.playlists.push(list.playlists[i]);
if (list.playlists) r.playlists = r.playlists.concat(list.playlists);
if (list.playlistFolders) r.playlistFolders = r.playlistFolders.concat(list.playlistFolders);
}
} catch (e) {
showError(x.name, e)
Expand Down
46 changes: 24 additions & 22 deletions dataModule/netease2.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async function parseSongs(songs, br = 999000) {
codec: "mp3",
// lrc: song.id,
source: "Netease2",
id: song.id
id: `${song.id}`
};
})
);
Expand Down Expand Up @@ -246,7 +246,7 @@ async function parseAlbums(albums) {
year: new Date(x.publishTime).getFullYear(),
cover: imageUrl(x.picUrl),
source: "Netease2",
id: x.id
id: `${x.id}`
}));
}

Expand All @@ -255,7 +255,7 @@ async function parseArtists(artists) {
name: x.name,
cover: imageUrl(x.picUrl || x.img1v1Url),
source: "Netease2",
id: x.id
id: `${x.id}`
}));
}

Expand All @@ -264,7 +264,7 @@ async function parsePlaylists(playlists) {
name: x.name,
image: imageUrl(x.coverImgUrl || x.picUrl),
source: "Netease2",
id: x.id
id: `${x.id}`
}));
}

Expand Down Expand Up @@ -358,7 +358,7 @@ async function resolveTopPlaylistStack(topPlaylistStack) {
x ? {
name: x.name,
source: "Netease2",
id: x.id,
id: `${x.id}`,
image: imageUrl(x.coverImgUrl || x.picUrl),
from: "topPlaylistStack"
} : false
Expand All @@ -372,13 +372,13 @@ async function resolvePlaylistStack(playlistStack) {
Array.isArray(x) ? {
name: x[1].name || x[0].playlist.name,
source: "Netease2",
id: x[0].playlist.id,
id: `${x[0].playlist.id}`,
image: x[1].image || imageUrl(x[0].playlist.coverImgUrl || x[0].playlist.picUrl),
from: "playlistStack"
} : {
name: x.playlist.name,
source: "Netease2",
id: x.playlist.id,
id: `${x.playlist.id}`,
image: imageUrl(x.playlist.coverImgUrl || x.playlist.picUrl),
from: "playlistStack"
}
Expand All @@ -394,13 +394,13 @@ async function resolvedailyRecommendStack(dailyRecommendStack) {
).map(x =>
Array.isArray(x) ? {
name: x[1].name,
id: x[1].id,
id: `${x[1].id}`,
image: x[0] || imageUrl(x.coverImgUrl || x.picUrl),
source: "Netease2",
from: "dailyRecommendStack"
} : {
name: x.name,
id: x.id,
id: `${x.id}`,
image: imageUrl(x.coverImgUrl || x.picUrl),
source: "Netease2",
from: "dailyRecommendStack"
Expand All @@ -421,7 +421,7 @@ async function getPlaylists(uid) {
return result.playlist.map(x => ({
name: x.name,
source: "Netease2",
id: x.id,
id: `${x.id}`,
image: imageUrl(x.coverImgUrl || x.picUrl),
from: "getCustomPlaylists"
}));
Expand All @@ -431,6 +431,7 @@ async function getPlaylists(uid) {
let r = [];
let playlistStack = [];
let userList = [];
let playlistFolders = [];
for (let x of playlists) {
if (x.source != "Netease2") continue;
else {
Expand Down Expand Up @@ -471,12 +472,12 @@ async function getPlaylists(uid) {
break;
case "folder":
let data = await processPlaylist(x.playlists);
r.push({
playlistFolders.push({
name: x.name,
type: "folder",
image: x.image,
source: "Netease2",
id: x.id,
id: `${x.id}`,
playlists: data[0].concat(
...(await resolvePlaylistStack(data[1])),
...(await resolveUserList(data[2]))
Expand All @@ -487,10 +488,10 @@ async function getPlaylists(uid) {
}
}
}
return [r, playlistStack, userList];
return [r, playlistStack, userList, playlistFolders];
}

let [r, playlistStack, userList] = await processPlaylist();
let [r, playlistStack, userList, playlistFolders] = await processPlaylist();
// get topPlaylist & hqPlaylist
let catList = await getCatList()
await Promise.all(['topPlaylist', 'hqPlaylist'].map(async playlistId => {
Expand All @@ -502,7 +503,7 @@ async function getPlaylists(uid) {
config[playlistId].category = ["ACG", "日语", "欧美"];
}
let translatedCategory = await zhconvert(category)
r.push({
playlistFolders.push({
name: `${translatedCategory} - ${playlistId == 'hqPlaylist' ? '精品' : '精選'}歌單`,
source: "Netease2",
type: "folder",
Expand All @@ -521,7 +522,7 @@ async function getPlaylists(uid) {
id: "yunPan"
})
// get user playlists
r.push({
playlistFolders.push({
name: `收藏歌單`,
source: "Netease2",
type: "folder",
Expand Down Expand Up @@ -555,7 +556,7 @@ async function getPlaylists(uid) {
if (isLoggedin === undefined) {
login.then(async x => {
if (x.code == 200)
r.push({
playlistFolders.push({
name: "每日推薦歌單",
source: "Netease2",
image: config.dailyRecommendPlaylists.image || defaultImage,
Expand All @@ -570,7 +571,7 @@ async function getPlaylists(uid) {
} else if (!isLoggedin) {
pokaLog.logDMErr('Netease2', `未登入,無法獲取每日推薦歌單。`)
} else
r.push({
playlistFolders.push({
name: "每日推薦歌單",
source: "Netease2",
image: config.dailyRecommendPlaylists.image || defaultImage,
Expand All @@ -586,7 +587,8 @@ async function getPlaylists(uid) {
...r,
...(await resolveUserList(userList)),
...(await resolvePlaylistStack(playlistStack))
]
],
playlistFolders
};
}

Expand All @@ -606,7 +608,7 @@ async function getPlaylistSongs(id, br = 999000) {
url: `/pokaapi/song/?moduleName=Netease2&songId=${x.id}`,
codec: "mp3",
source: "Netease2",
id: x.id
id: `${x.id}`
}));
return {
songs: r,
Expand Down Expand Up @@ -689,7 +691,7 @@ async function searchLyrics(keyword) {
name: x.name,
artist: x.artist,
source: "Netease2",
id: x.id,
id: `${x.id}`,
lyric: await getLyric(x.id)
}))
)).filter(x => x.lyric && x.lyric != "[0:0] 純音樂");
Expand Down Expand Up @@ -875,7 +877,7 @@ async function getUserPlaylists(uid) {
source: "Netease2",
image: imageUrl(x.coverImgUrl) || defaultImage,
type: "playlist",
id: x.id
id: `${x.id}`
}));
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"chai": "*",
"mocha": "^8.3.2"
}
}
}

0 comments on commit c97122d

Please sign in to comment.