1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-10-01 20:35:42 +08:00
parent cf4449604d
commit ba395bac47
7 changed files with 56 additions and 16 deletions

View File

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

View File

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

View File

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