暂存
This commit is contained in:
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,
|
||||
}
|
Reference in New Issue
Block a user