1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2022-10-01 16:16:39 +08:00
parent 37fe49c53c
commit 64834ae7f9
9 changed files with 35 additions and 27 deletions

View File

@ -1,5 +1,2 @@
// const dbUtils = require('./utils/dbUtils');
// const dbPoolUtils = require('./utils/dbPoolUtils');
const neteaseMusic = require('./netease_music/index');
neteaseMusic.main();

View File

@ -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);
}

View File

@ -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;
) 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;

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

2
test.js Normal file
View File

@ -0,0 +1,2 @@
const neteaseMusic = require('./netease_music/index');
neteaseMusic.test();