diff --git a/index.js b/index.js index edaa27f..e280a06 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,2 @@ -// const dbUtils = require('./utils/dbUtils'); -// const dbPoolUtils = require('./utils/dbPoolUtils'); - const neteaseMusic = require('./netease_music/index'); neteaseMusic.main(); \ No newline at end of file diff --git a/netease_music/index.js b/netease_music/index.js index 4f84dc8..57dd518 100644 --- a/netease_music/index.js +++ b/netease_music/index.js @@ -49,7 +49,7 @@ async function startGetMusic(sleepTime) { const songId = songIds[i]; console.log(`${i}/${songIds.length} | song: ${songId} | ${await statistics()}`); try { - await songInfoUtils.get({ songId: songId }); + await songInfoUtils.fetch({ songId: songId }); } catch (err) { console.error(err); } @@ -69,7 +69,7 @@ async function startGetMusic(sleepTime) { const albumId = albumIds[i]; console.log(`${i}/${albumIds.length} | album: ${albumId} | ${await statistics()}`); try { - await albumInfoUtils.get({ albumId: albumId }); + await albumInfoUtils.fetch({ albumId: albumId }); } catch (err) { console.error(err); } @@ -89,7 +89,7 @@ async function startGetMusic(sleepTime) { const artistId = artistIds[i]; console.log(`${i}/${artistIds.length} | artist: ${artistId} | ${await statistics()}`); try { - await artistInfoUtils.get({ artistId: artistId }); + await artistInfoUtils.fetch({ artistId: artistId }); } catch (err) { console.error(err); } diff --git a/netease_music/sql/structure.sql b/netease_music/sql/structure.sql index ed38dec..84764da 100644 --- a/netease_music/sql/structure.sql +++ b/netease_music/sql/structure.sql @@ -8,7 +8,7 @@ CREATE TABLE `song` ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY (`song_id`) -) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `artist` ( `artist_id` int(10) unsigned NOT NULL COMMENT '歌手id', @@ -19,7 +19,7 @@ CREATE TABLE `artist` ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY (`artist_id`) -) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `album` ( `album_id` int(10) unsigned NOT NULL COMMENT '专辑id', @@ -31,7 +31,7 @@ CREATE TABLE `album` ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY (`album_id`) -) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `song_album_relation` ( `song_id` int(10) unsigned NOT NULL COMMENT '歌曲id', @@ -39,7 +39,7 @@ CREATE TABLE `song_album_relation` ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY `song_id` (`song_id`,`album_id`) -) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `song_artist_relation` ( `song_id` int(10) unsigned NOT NULL COMMENT '歌曲id', @@ -47,4 +47,13 @@ CREATE TABLE `song_artist_relation` ( `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY `song_id` (`song_id`,`artist_id`) -) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +CREATE TABLE `lyric` ( + `song_id` int(10) unsigned NOT NULL COMMENT '歌曲id', + `lyric` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '歌词', + `version` int(10) unsigned NOT NULL COMMENT '版本号', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '爬取时间', + `modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + PRIMARY KEY (`song_id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file diff --git a/netease_music/src/getInfo/albumInfoUtils.js b/netease_music/src/getInfo/albumInfoUtils.js index 48e2c6c..5b3d6cb 100644 --- a/netease_music/src/getInfo/albumInfoUtils.js +++ b/netease_music/src/getInfo/albumInfoUtils.js @@ -6,7 +6,7 @@ const requestUtils = require('../../../utils/requestUtils'); const sleepUtils = require('../../../utils/sleepUtils'); // 获取专辑详情 -async function get({ albumId }) { +async function fetch({ 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}`); @@ -24,9 +24,9 @@ async function get({ albumId }) { let url = `https://music.163.com/album?id=${albumId}`; try { - // var html = fs.readFileSync(path.join(__dirname, "../temp", `album-${albumId}.html`), 'utf8'); + // var html = fs.readFileSync(path.join(__dirname, "../../temp", `album-${albumId}.html`), 'utf8'); var html = await requestUtils.getApiResult(url); - // fs.writeFileSync(path.join(__dirname, "../temp", `album-${albumId}.html`), html); + // fs.writeFileSync(path.join(__dirname, "../../temp", `album-${albumId}.html`), html); } catch (errors) { console.error(errors); return; @@ -85,5 +85,5 @@ async function get({ albumId }) { } module.exports = { - get: get, + fetch: fetch, } \ No newline at end of file diff --git a/netease_music/src/getInfo/artistInfoUtils.js b/netease_music/src/getInfo/artistInfoUtils.js index 388ff82..51073dc 100644 --- a/netease_music/src/getInfo/artistInfoUtils.js +++ b/netease_music/src/getInfo/artistInfoUtils.js @@ -6,7 +6,7 @@ const requestUtils = require('../../../utils/requestUtils'); const sleepUtils = require('../../../utils/sleepUtils'); // 获取音乐人详情 -async function get({ artistId }) { +async function fetch({ 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}`); @@ -25,9 +25,9 @@ async function get({ artistId }) { let url = `https://music.163.com/artist?id=${artistId}`; try { - // var html = fs.readFileSync(path.join(__dirname, "../temp", `artist-${artistId}.html`), 'utf8'); + // var html = fs.readFileSync(path.join(__dirname, "../../temp", `artist-${artistId}.html`), 'utf8'); var html = await requestUtils.getApiResult(url); - // fs.writeFileSync(path.join(__dirname, "../temp", `artist-${artistId}.html`), html); + // fs.writeFileSync(path.join(__dirname, "../../temp", `artist-${artistId}.html`), html); } catch (errors) { console.error(errors); return; @@ -78,5 +78,5 @@ async function get({ artistId }) { } module.exports = { - get: get, + fetch: fetch, } \ No newline at end of file diff --git a/netease_music/src/getInfo/songInfoUtils.js b/netease_music/src/getInfo/songInfoUtils.js index a9b6e2c..2db8228 100644 --- a/netease_music/src/getInfo/songInfoUtils.js +++ b/netease_music/src/getInfo/songInfoUtils.js @@ -6,7 +6,7 @@ const requestUtils = require('../../../utils/requestUtils'); const sleepUtils = require('../../../utils/sleepUtils'); // 获取音乐详情 -async function get({ songId }) { +async function fetch({ 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}`); @@ -30,9 +30,9 @@ async function get({ songId }) { let url = `https://music.163.com/song?id=${songId}`; try { - // var html = fs.readFileSync(path.join(__dirname, "../temp", `song-${songId}.html`), 'utf8'); + // var html = fs.readFileSync(path.join(__dirname, "../../temp", `song-${songId}.html`), 'utf8'); var html = await requestUtils.getApiResult(url); - // fs.writeFileSync(path.join(__dirname, "../temp", `song-${songId}.html`), html); + // fs.writeFileSync(path.join(__dirname, "../../temp", `song-${songId}.html`), html); } catch (errors) { console.error(errors); return; @@ -102,5 +102,5 @@ async function get({ songId }) { } module.exports = { - get: get, + fetch: fetch, } \ No newline at end of file diff --git a/netease_music/src/getInfo/userInfoUtils.js b/netease_music/src/getInfo/userInfoUtils.js index 5221e5b..ebc9f75 100644 --- a/netease_music/src/getInfo/userInfoUtils.js +++ b/netease_music/src/getInfo/userInfoUtils.js @@ -6,14 +6,14 @@ const requestUtils = require('../../../utils/requestUtils'); const sleepUtils = require('../../../utils/sleepUtils'); // 获取用户详情 -async function get({ userId }) { +async function fetch({ userId }) { let url = `https://music.163.com/user/home?id=${userId}`; try { - var html = fs.readFileSync(path.join(__dirname, "../temp", ` user-${userId}.html`), 'utf8'); + var html = fs.readFileSync(path.join(__dirname, "../../temp", ` user-${userId}.html`), 'utf8'); } catch (errors) { var html = await requestUtils.getApiResult(url); - fs.writeFileSync(path.join(__dirname, "../temp", ` user-${userId}.html`), html); + fs.writeFileSync(path.join(__dirname, "../../temp", ` user-${userId}.html`), html); } // console.log(html); @@ -21,5 +21,5 @@ async function get({ userId }) { } module.exports = { - get: get, + fetch: fetch, } \ No newline at end of file diff --git a/temp/.gitignore b/netease_music/temp/.gitignore similarity index 100% rename from temp/.gitignore rename to netease_music/temp/.gitignore diff --git a/test.js b/test.js new file mode 100644 index 0000000..0305a83 --- /dev/null +++ b/test.js @@ -0,0 +1,2 @@ +const neteaseMusic = require('./netease_music/index'); +neteaseMusic.test(); \ No newline at end of file