diff --git a/netease_music/src/dataManager.js b/netease_music/src/dataManager.js index d55c0e1..e8a5bfd 100644 --- a/netease_music/src/dataManager.js +++ b/netease_music/src/dataManager.js @@ -74,6 +74,25 @@ module.exports = { albumIds = albumIds.map(item => item.id); return albumIds; }, + + getInfoById: async (albumId, { getRelation = true }) => { + if (!albumId) return {} + // 查询出专辑 + const sql = 'SELECT * FROM album WHERE album_id = ?' + let infoResultSet = await dbUtils.query(sql, [albumId]); + if (infoResultSet.length == 0) return {}; + let albumInfo = JSON.parse(JSON.stringify(infoResultSet[0])); + if (getRelation) { + // 查出专辑与歌曲对应关系 + const sql2 = 'SELECT * FROM song_album_relation WHERE album_id = ?' + let relationResultSet = await dbUtils.query(sql2, [albumId]); + // 拼装 + albumInfo.songIds = relationResultSet.map(song => song.song_id); + } else { + albumInfo.songIds = null; + } + return albumInfo; + }, }, @@ -97,6 +116,25 @@ module.exports = { artistIds = artistIds.map(item => item.id); return artistIds; }, + + getInfoById: async (artistId, { getRelation = true }) => { + if (!artistId) return {} + // 查询出歌手 + const sql = 'SELECT * FROM artist WHERE artist_id = ?' + let infoResultSet = await dbUtils.query(sql, [artistId]); + if (infoResultSet.length == 0) return {}; + let artistInfo = JSON.parse(JSON.stringify(infoResultSet[0])); + if (getRelation) { + // 查出歌手与歌曲对应关系 + const sql2 = 'SELECT * FROM song_artist_relation WHERE artist_id = ?' + let relationResultSet = await dbUtils.query(sql2, [artistId]); + // 拼装 + artistInfo.songIds = relationResultSet.map(song => song.song_id); + } else { + artistInfo.songIds = null; + } + return artistInfo; + }, }, diff --git a/netease_music/src/getInfo/albumInfoUtils.js b/netease_music/src/getInfo/albumInfoUtils.js index cf9ff14..ae88dbc 100644 --- a/netease_music/src/getInfo/albumInfoUtils.js +++ b/netease_music/src/getInfo/albumInfoUtils.js @@ -7,21 +7,6 @@ const dataManager = require('../dataManager'); const dbUtils = global.dbUtils; -// 从数据库中查询 -async function getFromDatabase({ albumId }) { - // 查询出专辑 - let infoResultSet = await dbUtils.query('SELECT * FROM album WHERE album_id = ?', [albumId]); - if (infoResultSet.length == 0) return {}; - - // 查出专辑与歌曲对应关系 - let relationResultSet = await dbUtils.query('SELECT * FROM song_album_relation WHERE album_id = ?', [albumId]); - - // 拼装 - let albumInfo = JSON.parse(JSON.stringify(infoResultSet[0])); - albumInfo.songIds = relationResultSet.map(song => song.song_id); - return albumInfo; -} - // 正常应该查不出记录才对 /* SELECT * FROM album WHERE (full_description = '' or full_description is null) and description like '%专辑《%》,简介:%' and description not regexp '^.*?专辑《.*?》,简介:([:space:]*?|[ ]*?)。,更多.*$' @@ -184,7 +169,6 @@ async function fetch({ albumId, debug = false, update = false }) { } module.exports = { - getFromDatabase: getFromDatabase, fetch: fetch, fetchAll: fetchAll, } \ No newline at end of file diff --git a/netease_music/src/getInfo/artistInfoUtils.js b/netease_music/src/getInfo/artistInfoUtils.js index 59f5d19..30cd8c5 100644 --- a/netease_music/src/getInfo/artistInfoUtils.js +++ b/netease_music/src/getInfo/artistInfoUtils.js @@ -7,21 +7,6 @@ const dataManager = require('../dataManager'); const dbUtils = global.dbUtils; -// 从数据库中查询 -async function getFromDatabase({ artistId }) { - // 查询出专辑 - let infoResultSet = await dbUtils.query('SELECT * FROM artist WHERE artist_id = ?', [artistId]); - if (infoResultSet.length == 0) return {}; - - // 查出专辑与歌曲对应关系 - let relationResultSet = await dbUtils.query('SELECT * FROM song_artist_relation WHERE artist_id = ?', [artistId]); - - // 拼装 - let artistInfo = JSON.parse(JSON.stringify(infoResultSet[0])); - artistInfo.songIds = relationResultSet.map(song => song.song_id); - return artistInfo; -} - // 从数据库中查出还缺少的歌手,并进行爬取 async function fetchAll({ args = {} }) { console.log("start fetching artists ..."); @@ -129,7 +114,6 @@ async function fetch({ artistId, debug = false }) { } module.exports = { - getFromDatabase: getFromDatabase, fetch: fetch, fetchAll: fetchAll, } \ No newline at end of file diff --git a/netease_music/src/index.js b/netease_music/src/index.js index 805fd05..8941195 100644 --- a/netease_music/src/index.js +++ b/netease_music/src/index.js @@ -47,10 +47,6 @@ async function test() { // let res = await testUtils.fetch(); - // let res = await albumInfoUtils.getFromDatabase({ albumId: "9156" }); - // let res = await artistInfoUtils.getFromDatabase({ artistId: "12023508" }); - // let res = await songInfoUtils.getFromDatabase({ songId: "437608327" }); - // console.log(res); }