update
This commit is contained in:
parent
cf4449604d
commit
ba395bac47
1
index.js
1
index.js
@ -1,2 +1,3 @@
|
||||
global.useMysqlPool = true;
|
||||
const neteaseMusic = require('./netease_music/index');
|
||||
neteaseMusic.main();
|
@ -1,7 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
// const dbUtils = require('../utils/dbUtils');
|
||||
const dbUtils = require('../utils/dbPoolUtils');
|
||||
const dbUtils = require(global.useMysqlPool ? '../utils/dbPoolUtils' : '../utils/dbUtils');
|
||||
|
||||
const requestUtils = require('../utils/requestUtils');
|
||||
const sleepUtils = require('../utils/sleepUtils');
|
||||
@ -10,12 +9,13 @@ dbUtils.create({
|
||||
database: "neteaseMusic", // 指定数据库
|
||||
connectionLimit: 8, // 设置数据库连接池数量
|
||||
});
|
||||
|
||||
global.dbUtils = dbUtils;
|
||||
|
||||
const songInfoUtils = require('./src/getInfo/songInfoUtils');
|
||||
const artistInfoUtils = require('./src/getInfo/artistInfoUtils');
|
||||
const albumInfoUtils = require('./src/getInfo/albumInfoUtils');
|
||||
|
||||
console.log("global.useMysqlPool:", !!global.useMysqlPool);
|
||||
|
||||
// 退出检查
|
||||
async function checkIsExit() {
|
||||
|
@ -2,10 +2,24 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 获取专辑详情
|
||||
async function fetch({ albumId }) {
|
||||
let result = await dbUtils.query('SELECT count(*) as count FROM album WHERE album_id = ?', [albumId]);
|
||||
@ -170,6 +184,7 @@ async function update({ albumId }) {
|
||||
|
||||
|
||||
module.exports = {
|
||||
getFromDatabase: getFromDatabase,
|
||||
fetch: fetch,
|
||||
update: update,
|
||||
}
|
@ -2,25 +2,30 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
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 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}`);
|
||||
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;
|
||||
}
|
||||
|
||||
let url = `https://music.163.com/artist?id=${artistId}`;
|
||||
@ -78,5 +83,6 @@ async function fetch({ artistId }) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getFromDatabase: getFromDatabase,
|
||||
fetch: fetch,
|
||||
}
|
@ -2,10 +2,26 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
// 从数据库中查询
|
||||
async function getFromDatabase({ songId }) {
|
||||
// 查询出专辑
|
||||
let infoResultSet = await dbUtils.query('SELECT * FROM song WHERE song_id = ?', [songId]);
|
||||
if (infoResultSet.length == 0) return {};
|
||||
|
||||
// 查出专辑与歌曲对应关系
|
||||
let albumRelationResultSet = await dbUtils.query('SELECT * FROM song_album_relation WHERE song_id = ?', [songId]);
|
||||
let artistRelationResultSet = await dbUtils.query('SELECT * FROM song_artist_relation WHERE song_id = ?', [songId]);
|
||||
|
||||
// 拼装
|
||||
let songInfo = JSON.parse(JSON.stringify(infoResultSet[0]));
|
||||
songInfo.albumIds = albumRelationResultSet.map(album => album.album_id);
|
||||
songInfo.artistIds = artistRelationResultSet.map(artist => artist.artist_id);
|
||||
return songInfo;
|
||||
}
|
||||
|
||||
// 获取音乐详情
|
||||
async function fetch({ songId }) {
|
||||
let result = await dbUtils.query('SELECT count(*) as count FROM song WHERE song_id = ?', [songId]);
|
||||
@ -61,7 +77,6 @@ async function fetch({ songId }) {
|
||||
// 歌曲不在专辑中
|
||||
}
|
||||
|
||||
|
||||
const reg = /<meta property="music:musician" content="https:\/\/music\.163\.com\/artist\?id=(.*?)"\/>/g;
|
||||
let artistIds = [];
|
||||
let matched = null;
|
||||
@ -102,5 +117,6 @@ async function fetch({ songId }) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getFromDatabase: getFromDatabase,
|
||||
fetch: fetch,
|
||||
}
|
1
test.js
1
test.js
@ -1,2 +1,3 @@
|
||||
global.useMysqlPool = false;
|
||||
const neteaseMusic = require('./netease_music/index');
|
||||
neteaseMusic.test();
|
Loading…
Reference in New Issue
Block a user