暂存
This commit is contained in:
parent
5877674187
commit
72427338f4
63
netease_music/src/getInfo/playlistUtils.js
Normal file
63
netease_music/src/getInfo/playlistUtils.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const sleepUtils = require('../../../utils/sleepUtils');
|
||||||
|
const dataManager = require('../dataManager');
|
||||||
|
|
||||||
|
const dbUtils = global.dbUtils;
|
||||||
|
|
||||||
|
// refer:
|
||||||
|
// https://neteasecloudmusicapi-docs.4everland.app/
|
||||||
|
// https://github.com/Binaryify/NeteaseCloudMusicApi
|
||||||
|
const { top_playlist, top_playlist_highquality, related_playlist } = require('NeteaseCloudMusicApi');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这里有几种情况:
|
||||||
|
*
|
||||||
|
* top_playlist 并保存相关歌单信息(只有id)
|
||||||
|
* top_playlist_highquality 并保存相关歌单信息(只有id)
|
||||||
|
* 还有就是从数据库中查出的待爬取歌单详情 并保存相关歌单信息(只有id)
|
||||||
|
*/
|
||||||
|
|
||||||
|
async function fetchTop({ args = {} }) {
|
||||||
|
console.log("start fetching playlist ...");
|
||||||
|
|
||||||
|
let limit = 50; // 默认为 50
|
||||||
|
let page = 0;
|
||||||
|
let hasMore = true;
|
||||||
|
while (hasMore) {
|
||||||
|
try {
|
||||||
|
var result = await top_playlist({
|
||||||
|
id: 1
|
||||||
|
});
|
||||||
|
fs.writeFileSync(path.join(__dirname, "../../temp", `test.json`), JSON.stringify(result.body));
|
||||||
|
} catch (errors) {
|
||||||
|
console.error("error", errors);
|
||||||
|
await sleepUtils.sleep(10 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 针对每一个歌单调用相关歌单接口,然后加入待爬取歌单
|
||||||
|
|
||||||
|
hasMore = false;
|
||||||
|
console.log(result.body.playlists);
|
||||||
|
}
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (let i = 0; i < songIds.length; i++) {
|
||||||
|
await global.checkIsExit();
|
||||||
|
const songId = songIds[i];
|
||||||
|
console.log(`${i + 1}/${songIds.length} | playlist: ${songId} | ${args.min || "?"}-${args.max || "?"}`);
|
||||||
|
try {
|
||||||
|
await fetch({ songId: songId });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
await sleepUtils.sleep(global.sleepTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
fetchTop: fetchTop,
|
||||||
|
}
|
@ -32,13 +32,18 @@ async function test() {
|
|||||||
|
|
||||||
// 不是所有歌手都有个人主页 例如 https://music.163.com/#/artist?id=1079075
|
// 不是所有歌手都有个人主页 例如 https://music.163.com/#/artist?id=1079075
|
||||||
|
|
||||||
|
// let res = await playlistUtils.fetchTop();
|
||||||
|
|
||||||
// let res = await songInfoUtils.fetchAll({ args: {} });
|
// let res = await songInfoUtils.fetchAll({ args: {} });
|
||||||
// let res = await playlistUtilsOld.fetchAll();
|
// let res = await playlistUtilsOld.fetchAll();
|
||||||
|
// let res = await playlistUtils.fetchAll({ args: {} });
|
||||||
|
|
||||||
// let res = await albumInfoUtils.fetch({ albumId: "9156", debug: true });
|
// let res = await albumInfoUtils.fetch({ albumId: "9156", debug: true });
|
||||||
// let res = await artistInfoUtils.fetch({ artistId: "12023508" });
|
// let res = await artistInfoUtils.fetch({ artistId: "12023508" });
|
||||||
// let res = await songInfoUtils.fetch({ songId: "437608327" });
|
// let res = await songInfoUtils.fetch({ songId: "437608327" });
|
||||||
// let res = await playlistUtilsOld.fetch({ playlistId: "4980157066", debug: true });
|
// let res = await playlistUtilsOld.fetch({ playlistId: "4980157066", debug: true });
|
||||||
|
// let res = await commentUtils.fetch({ songId: "4980157066" });
|
||||||
|
|
||||||
// let res = await testUtils.fetch();
|
// let res = await testUtils.fetch();
|
||||||
|
|
||||||
// let res = await albumInfoUtils.getFromDatabase({ albumId: "9156" });
|
// let res = await albumInfoUtils.getFromDatabase({ albumId: "9156" });
|
||||||
|
Loading…
Reference in New Issue
Block a user