update
This commit is contained in:
		
							
								
								
									
										65
									
								
								netease_music/src/getInfo/playlistUtils.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								netease_music/src/getInfo/playlistUtils.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
 | 
			
		||||
const requestUtils = require('../../../utils/requestUtils');
 | 
			
		||||
const sleepUtils = require('../../../utils/sleepUtils');
 | 
			
		||||
 | 
			
		||||
const dbUtils = global.dbUtils;
 | 
			
		||||
 | 
			
		||||
// refer:
 | 
			
		||||
// https://neteasecloudmusicapi-docs.4everland.app/
 | 
			
		||||
// https://github.com/Binaryify/NeteaseCloudMusicApi
 | 
			
		||||
const { playlist_catlist, playlist_hot } = require('NeteaseCloudMusicApi');
 | 
			
		||||
 | 
			
		||||
// // 从数据库中查出还缺少的歌词,并进行爬取
 | 
			
		||||
// async function fetchAll() {
 | 
			
		||||
//     console.log("start fetching lyrics ...");
 | 
			
		||||
//     var playlistIds = await dbUtils.query(`
 | 
			
		||||
//         SELECT DISTINCT playlist_id FROM playlist WHERE playlist_id NOT IN ( SELECT playlist_id FROM lyric )
 | 
			
		||||
//     `, []);
 | 
			
		||||
//     playlistIds = playlistIds.map(playlist => playlist.playlist_id);
 | 
			
		||||
//     for (let i = 0; i < playlistIds.length; i++) {
 | 
			
		||||
//         await global.checkIsExit();
 | 
			
		||||
//         const playlistId = playlistIds[i];
 | 
			
		||||
//         console.log(`${i + 1}/${playlistIds.length} | lyric: ${playlistId}`);
 | 
			
		||||
//         try {
 | 
			
		||||
//             await fetch({ playlistId: playlistId });
 | 
			
		||||
//         } catch (err) {
 | 
			
		||||
//             console.error(err);
 | 
			
		||||
//         }
 | 
			
		||||
//         await sleepUtils.sleep(global.sleepTime);
 | 
			
		||||
//     }
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
// 获取歌词详情
 | 
			
		||||
async function fetch({ playlistId, debug = false }) {
 | 
			
		||||
    // https://neteasecloudmusicapi-docs.4everland.app/#/?id=%e6%ad%8c%e5%8d%95%e5%88%86%e7%b1%bb
 | 
			
		||||
    var queryParams = {};
 | 
			
		||||
    try {
 | 
			
		||||
        var playlistResult = await playlist_catlist(queryParams);
 | 
			
		||||
        fs.writeFileSync(path.join(__dirname, "../../temp", `playlist-${playlistId}.json`), JSON.stringify(playlistResult));
 | 
			
		||||
    } catch (errors) {
 | 
			
		||||
        console.error(errors);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    console.log(playlistResult);
 | 
			
		||||
 | 
			
		||||
    // let lyricInfo = {
 | 
			
		||||
    //     playlistId: playlistId,
 | 
			
		||||
    //     lyric: lyric.lyric,
 | 
			
		||||
    //     version: lyric.version,
 | 
			
		||||
    // };
 | 
			
		||||
    // // console.log("lyricInfo", lyricInfo);
 | 
			
		||||
    // dbUtils.query('INSERT IGNORE INTO lyric SET ?', {
 | 
			
		||||
    //     playlist_id: lyricInfo.playlistId,
 | 
			
		||||
    //     lyric: lyricInfo.lyric,
 | 
			
		||||
    //     version: lyricInfo.version,
 | 
			
		||||
    // });
 | 
			
		||||
    // return lyricInfo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    fetch: fetch,
 | 
			
		||||
    // fetchAll: fetchAll,
 | 
			
		||||
}
 | 
			
		||||
@@ -76,6 +76,8 @@ async function fetch({ songId, debug = false }) {
 | 
			
		||||
    let songInfoDict = JSON.parse(songInfoJSONString);
 | 
			
		||||
    // console.log(songInfoDict);
 | 
			
		||||
 | 
			
		||||
    // TODO 考虑歌曲别名 例如:https://music.163.com/#/song?id=26830207
 | 
			
		||||
 | 
			
		||||
    let title = /<meta property="og:title" content="(.*?)" \/>/.exec(html)[1];
 | 
			
		||||
    let image = /<meta property="og:image" content="http:\/\/p.\.music\.126\.net\/(.*?)" \/>/.exec(html)[1];
 | 
			
		||||
    let artist = /<meta property="og:music:artist" content="(.*?)" \/>/.exec(html)[1];
 | 
			
		||||
 
 | 
			
		||||
@@ -7,9 +7,8 @@ const sleepUtils = require('../../../utils/sleepUtils');
 | 
			
		||||
const dbUtils = global.dbUtils;
 | 
			
		||||
 | 
			
		||||
// 获取用户详情
 | 
			
		||||
async function fetch({ userId }) {
 | 
			
		||||
async function fetch({ userId, debug = false }) {
 | 
			
		||||
    let url = `https://music.163.com/user/home?id=${userId}`;
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        var html = fs.readFileSync(path.join(__dirname, "../../temp", ` user-${userId}.html`), 'utf8');
 | 
			
		||||
    } catch (errors) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user