From e83558035815f4a43410954ead175d982de8c6e5 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: Fri, 30 Sep 2022 08:20:55 +0800 Subject: [PATCH] 1 --- netease_music/index.js | 45 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/netease_music/index.js b/netease_music/index.js index 89c124e..ea528d1 100644 --- a/netease_music/index.js +++ b/netease_music/index.js @@ -29,7 +29,6 @@ async function main() { } async function startGetMusic({ songId }) { - await sleepUtils.sleep(500); var songInfo = await getMusicInfo({ songId: songId }); var albumInfo = await getAlbumInfo({ albumId: songInfo.albumId }); @@ -52,11 +51,24 @@ async function startGetMusic({ songId }) { // 获取音乐详情 async function getMusicInfo({ songId }) { console.log(`开始处理 song: ${songId}`); - // let result = await dbUtils.query('SELECT count(*) as count FROM song WHERE song_id = ?', [songId]); - // if (result[0].count > 0) { - // console.log(`数据库中已有数据,跳过 songId: ${songId}`); - // return; - // } + let result = await dbUtils.query('SELECT count(*) as count FROM song WHERE song_id = ?', [songId]); + if (result[0].count > 0) { + console.log(`数据库中已有数据,跳过 songId: ${songId}`); + let songResult = await dbUtils.query('SELECT * FROM song WHERE song_id = ?', [songId]); + songResult = JSON.parse(JSON.stringify(songResult)); + + let songArtistResult = await dbUtils.query('SELECT * FROM song_artist_relation WHERE song_id = ?', [songId]); + songArtistResult = JSON.parse(JSON.stringify(songArtistResult)); + songResult.artistIds = songArtistResult.map(song => song.artist_id); + + let songAlbumResult = await dbUtils.query('SELECT * FROM song_album_relation WHERE song_id = ?', [songId]); + songAlbumResult = JSON.parse(JSON.stringify(songAlbumResult)); + songResult.albumId = songAlbumResult.map(song => song.album_id)[0]; + + // console.log(songResult); + return songResult; + } + await sleepUtils.sleep(500); let url = `https://music.163.com/song?id=${songId}`; @@ -126,8 +138,17 @@ async function getArtistInfo({ artistId }) { let result = await dbUtils.query('SELECT count(*) as count FROM artist WHERE artist_id = ?', [artistId]); if (result[0].count > 0) { console.log(`数据库中已有数据,跳过 artistId: ${artistId}`); - return; + // // let artistResult = await dbUtils.query('SELECT * FROM artist LEFT JOIN song_artist_relation ON artist.artist_id = song_artist_relation.artist_id WHERE artist.artist_id = ?', [artistId]); + // let artistResult = await dbUtils.query('SELECT * FROM artist WHERE artist_id = ?', [artistId]); + // artistResult = JSON.parse(JSON.stringify(artistResult)); + // let songArtistResult = await dbUtils.query('SELECT * FROM song_artist_relation WHERE artist_id = ?', [artistId]); + // songArtistResult = JSON.parse(JSON.stringify(songArtistResult)); + // artistResult.songIds = songArtistResult.map(song => song.song_id); + // // console.log(artistResult); + // return artistResult; + return null; } + await sleepUtils.sleep(500); let url = `https://music.163.com/artist?id=${artistId}`; @@ -182,8 +203,16 @@ async function getAlbumInfo({ albumId }) { let result = await dbUtils.query('SELECT count(*) as count FROM album WHERE album_id = ?', [albumId]); if (result[0].count > 0) { console.log(`数据库中已有数据,跳过 albumId: ${albumId}`); - return; + // let albumResult = await dbUtils.query('SELECT * FROM album WHERE album_id = ?', [albumId]); + // albumResult = JSON.parse(JSON.stringify(albumResult)); + // let songAlbumResult = await dbUtils.query('SELECT * FROM song_album_relation WHERE album_id = ?', [albumId]); + // songAlbumResult = JSON.parse(JSON.stringify(songAlbumResult)); + // albumResult.songIds = songAlbumResult.map(song => song.song_id); + // // console.log(albumResult); + // return albumResult; + return null; } + await sleepUtils.sleep(500); let url = `https://music.163.com/album?id=${albumId}`;