From 70e15f7e4955e3c6dbd8bb3c2cbb869fcce32978 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: Sat, 3 Jun 2023 00:10:47 +0800 Subject: [PATCH] =?UTF-8?q?netease=5Fmusic=20=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- netease_music/src/getInfo/playlistUtils.js | 36 +++++++++++----------- netease_music/src/getInfo/songInfoUtils.js | 4 +-- netease_music/src/index.js | 2 +- netease_music/todo.txt | 18 ++++++++++- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/netease_music/src/getInfo/playlistUtils.js b/netease_music/src/getInfo/playlistUtils.js index e8a9b12..5fed310 100644 --- a/netease_music/src/getInfo/playlistUtils.js +++ b/netease_music/src/getInfo/playlistUtils.js @@ -5,6 +5,7 @@ const sleepUtils = require('../../../utils/sleepUtils'); const dataManager = require('../dataManager'); const dbUtils = global.dbUtils; +const oldPlaylistUtils = require('./playlistUtils_old'); // refer: // https://neteasecloudmusicapi-docs.4everland.app/ @@ -27,10 +28,9 @@ async function fetchTop({ args = {} }) { 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)); + // var result = await top_playlist({ id: 1 }); + var result = await top_playlist_highquality({ 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); @@ -38,23 +38,23 @@ async function fetchTop({ args = {} }) { // 针对每一个歌单调用相关歌单接口,然后加入待爬取歌单 - hasMore = false; - console.log(result.body.playlists); - } - console.log(result); + hasMore = result.more; - return; + let playlists = result.body.playlists; + // console.log(playlists); - 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); + for (let i in playlists) { + await global.checkIsExit(); + const playlist = playlists[i]; + const playlistId = playlist.id; + console.log(`${i + 1}/${playlists.length} | playlist: ${playlistId} | limit: ${limit}, page: ${page}`); + try { + await oldPlaylistUtils.fetch({ playlistId: playlist.id }) + } catch (err) { + console.error(err); + } + // await sleepUtils.sleep(global.sleepTime); } - await sleepUtils.sleep(global.sleepTime); } } diff --git a/netease_music/src/getInfo/songInfoUtils.js b/netease_music/src/getInfo/songInfoUtils.js index 39487bf..cb33cd4 100644 --- a/netease_music/src/getInfo/songInfoUtils.js +++ b/netease_music/src/getInfo/songInfoUtils.js @@ -60,7 +60,7 @@ async function fetch({ songIdArray, debug = false }) { albumIds.push(song.al.id || 0); songAlbumRel.push([song.id, song.al.id || 0]) return { - title: song.name, // 歌曲标题 + title: song.name || "", // 歌曲标题 id: song.id, // 歌曲ID type: song.t, // 0: 一般类型 1: 通过云盘上传的音乐,网易云不存在公开对应 2: 通过云盘上传的音乐,网易云存在公开对应 alias: JSON.stringify(song.alia), // 别名列表,第一个别名会被显示作副标题 @@ -69,7 +69,7 @@ async function fetch({ songIdArray, debug = false }) { duration: song.dt, // 歌曲时长 quality: JSON.stringify({ h: song.h, m: song.m, l: song.l, sq: song.sq }), // 高/中/低/无损质量文件信息 version: song.version, // 歌曲版本信息 - cd: song.cd, // None或如"04", "1/2", "3", "null"的字符串,表示歌曲属于专辑中第几张CD,对应音频文件的Tag + cd: song.cd || "", // None或如"04", "1/2", "3", "null"的字符串,表示歌曲属于专辑中第几张CD,对应音频文件的Tag no: song.no, // 表示歌曲属于CD中第几曲,0表示没有这个字段,对应音频文件的Tag djId: song.djId, // 0: 不是DJ节目 其他:是DJ节目,表示DJ ID sId: song.s_id, // 对于t == 2的歌曲,表示匹配到的公开版本歌曲ID diff --git a/netease_music/src/index.js b/netease_music/src/index.js index 8941195..9eac85c 100644 --- a/netease_music/src/index.js +++ b/netease_music/src/index.js @@ -83,7 +83,7 @@ async function main(args) { await sleepUtils.sleep(30 * 1000); break; case 'playlist': - await playlistUtils.fetchAll({ args: args }); + await playlistUtils.fetchTop({ args: args }); process.exit(0); break; diff --git a/netease_music/todo.txt b/netease_music/todo.txt index d079eb2..7e6eefb 100644 --- a/netease_music/todo.txt +++ b/netease_music/todo.txt @@ -55,4 +55,20 @@ alter table song add partition ( SQL文件说明 sql/structure.sql 中的SQL为最简,不包含字段的编码集 sql/neteasemusic.sql 中的SQL为数据库导出,包含字段的编码集 -项目数据库 CHARACTER SET 统一使用 'utf8mb4',COLLATE 统一使用 'utf8mb4_general_ci' \ No newline at end of file +项目数据库 CHARACTER SET 统一使用 'utf8mb4',COLLATE 统一使用 'utf8mb4_general_ci' + + + + + +# # 查看列表 +# screen -ls + +# # 创建一个screen +# screen + + +# # 切换到指定屏幕 +# screen -r + +# # 切出屏幕 +# Ctrl + A D \ No newline at end of file