update
This commit is contained in:
		
							
								
								
									
										44
									
								
								netease_music/src/getInfo/lyricInfoUtils.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								netease_music/src/getInfo/lyricInfoUtils.js
									
									
									
									
									
										Normal 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,
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user