From 72427338f45b15390d84e7f07f149c81d75fd68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Thu, 10 Nov 2022 15:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- netease_music/src/getInfo/playlistUtils.js | 63 ++++++++++++++++++++++ netease_music/src/index.js | 5 ++ 2 files changed, 68 insertions(+) create mode 100644 netease_music/src/getInfo/playlistUtils.js diff --git a/netease_music/src/getInfo/playlistUtils.js b/netease_music/src/getInfo/playlistUtils.js new file mode 100644 index 0000000..e8a9b12 --- /dev/null +++ b/netease_music/src/getInfo/playlistUtils.js @@ -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, +} \ No newline at end of file diff --git a/netease_music/src/index.js b/netease_music/src/index.js index 6ce33fe..341df0c 100644 --- a/netease_music/src/index.js +++ b/netease_music/src/index.js @@ -32,13 +32,18 @@ async function test() { // 不是所有歌手都有个人主页 例如 https://music.163.com/#/artist?id=1079075 + // let res = await playlistUtils.fetchTop(); + // let res = await songInfoUtils.fetchAll({ args: {} }); // let res = await playlistUtilsOld.fetchAll(); + // let res = await playlistUtils.fetchAll({ args: {} }); // let res = await albumInfoUtils.fetch({ albumId: "9156", debug: true }); // let res = await artistInfoUtils.fetch({ artistId: "12023508" }); // let res = await songInfoUtils.fetch({ songId: "437608327" }); // let res = await playlistUtilsOld.fetch({ playlistId: "4980157066", debug: true }); + // let res = await commentUtils.fetch({ songId: "4980157066" }); + // let res = await testUtils.fetch(); // let res = await albumInfoUtils.getFromDatabase({ albumId: "9156" });