1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-10-01 21:09:05 +08:00
parent ba395bac47
commit c98d453e14
3 changed files with 100 additions and 34 deletions

View File

@@ -0,0 +1,44 @@
const fs = require('fs');
const path = require('path');
const requestUtils = require('../../../utils/requestUtils');
const dbUtils = global.dbUtils;
// 获取歌词详情
async function fetch({ songId }) {
var url = `https://music.163.com/api/song/lyric?id=${songId}&lv=1`;
try {
// var json = fs.readFileSync(path.join(__dirname, "../../temp", `lyric-${songId}.json`), 'utf8');
var json = await requestUtils.getApiResult(url);
// fs.writeFileSync(path.join(__dirname, "../../temp", `lyric-${songId}.json`), json);
} catch (errors) {
console.error(errors);
return;
}
try {
var lyric = JSON.parse(json).lrc; // { version: xx, lyric: 'xxx' }
} catch (error) {
console.error(error);
return;
}
let lyricInfo = {
songId: songId,
lyric: lyric.lyric,
version: lyric.version,
};
// console.log("lyricInfo", lyricInfo);
dbUtils.query('INSERT IGNORE INTO lyric SET ?', {
song_id: lyricInfo.songId,
lyric: lyricInfo.lyric,
version: lyricInfo.version,
});
return lyricInfo;
}
module.exports = {
fetch: fetch,
}