update
This commit is contained in:
		@@ -15,6 +15,7 @@ async function main() {
 | 
			
		||||
 | 
			
		||||
    // 指定数据库
 | 
			
		||||
    dbUtils.create("neteaseMusic");
 | 
			
		||||
    console.log(`${await statistics()}`);
 | 
			
		||||
 | 
			
		||||
    // getMusicInfo({ songId: "1855221507" });
 | 
			
		||||
    // getArtistInfo({ artistId: "1079074" });
 | 
			
		||||
@@ -29,13 +30,12 @@ async function main() {
 | 
			
		||||
        var affectRows2 = await dbUtils.query(`DELETE FROM song_album_relation WHERE song_id = 0 OR album_id = 0`, []);
 | 
			
		||||
        console.log(affectRows1.affectedRows, affectRows2.affectedRows);
 | 
			
		||||
 | 
			
		||||
        await startGetMusic(1);
 | 
			
		||||
 | 
			
		||||
        await startGet(1);
 | 
			
		||||
        await sleepUtils.sleep(2000);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function startGetMusic(sleepTime) {
 | 
			
		||||
async function startGet(sleepTime) {
 | 
			
		||||
 | 
			
		||||
    // 从数据库中查出还缺少的歌曲,并进行爬取
 | 
			
		||||
    console.log("start fetching songs ...");
 | 
			
		||||
@@ -80,7 +80,7 @@ async function startGetMusic(sleepTime) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 从数据库中查出还缺少的歌手,并进行爬取
 | 
			
		||||
    console.log("start fetching albums ...")
 | 
			
		||||
    console.log("start fetching artists ...")
 | 
			
		||||
    let artistIds = await dbUtils.query(`
 | 
			
		||||
        SELECT DISTINCT artist_id FROM song_artist_relation WHERE artist_id NOT IN ( SELECT DISTINCT artist_id FROM artist )
 | 
			
		||||
    `, []);
 | 
			
		||||
@@ -100,29 +100,65 @@ async function startGetMusic(sleepTime) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function update() {
 | 
			
		||||
    console.log("neteaseMusic update ...");
 | 
			
		||||
    dbUtils.create("neteaseMusic");
 | 
			
		||||
    console.log(`${await statistics()}`);
 | 
			
		||||
 | 
			
		||||
    let sleepTime = 100;
 | 
			
		||||
 | 
			
		||||
    // 从数据库中查出现有专辑,并进行更新
 | 
			
		||||
    console.log("start fetching albums ...")
 | 
			
		||||
    let albumIds = await dbUtils.query(`
 | 
			
		||||
        SELECT DISTINCT album_id FROM album WHERE version = 1 -- and description like '%专辑《%》,简介:%'
 | 
			
		||||
    `, []);
 | 
			
		||||
    albumIds = albumIds.map(item => item.album_id);
 | 
			
		||||
    for (let i = 0; i < albumIds.length; i++) {
 | 
			
		||||
        const albumId = albumIds[i];
 | 
			
		||||
        console.log(`${i}/${albumIds.length} | album: ${albumId} | ${await statistics()}`);
 | 
			
		||||
        try {
 | 
			
		||||
            await albumInfoUtils.update({ albumId: albumId });
 | 
			
		||||
        } catch (err) {
 | 
			
		||||
            console.error(err);
 | 
			
		||||
        }
 | 
			
		||||
        await sleepUtils.sleep(sleepTime);
 | 
			
		||||
        if (fs.readFileSync('stop.txt') == "1") {
 | 
			
		||||
            throw new Error(`Stopped`);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function statistics() {
 | 
			
		||||
    let sql = `
 | 
			
		||||
        SELECT
 | 
			
		||||
            song_count,
 | 
			
		||||
            album_count,
 | 
			
		||||
            album_v3_count,
 | 
			
		||||
            album_v4_count,
 | 
			
		||||
            artist_count,
 | 
			
		||||
            song_album_count,
 | 
			
		||||
            song_artist_count
 | 
			
		||||
        FROM
 | 
			
		||||
            ( SELECT count(*) AS song_count FROM song ) t1,
 | 
			
		||||
            ( SELECT count(*) AS album_count FROM album ) t2,
 | 
			
		||||
            ( SELECT count(*) AS album_v3_count FROM album WHERE version = 3 ) t3_2,
 | 
			
		||||
            ( SELECT count(*) AS album_v4_count FROM album WHERE version = 4 ) t4_2,
 | 
			
		||||
            ( SELECT count(*) AS artist_count FROM artist ) t3,
 | 
			
		||||
            ( SELECT count(*) AS song_album_count FROM song_album_relation ) t4,
 | 
			
		||||
            ( SELECT count(*) AS song_artist_count FROM song_artist_relation ) t5`;
 | 
			
		||||
    let result = await dbUtils.query(sql, []);
 | 
			
		||||
    let songCount = result[0].song_count;
 | 
			
		||||
    let albumCount = result[0].album_count;
 | 
			
		||||
    let albumV3Count = result[0].album_v3_count;
 | 
			
		||||
    let albumV4Count = result[0].album_v4_count;
 | 
			
		||||
    let artistCount = result[0].artist_count;
 | 
			
		||||
    let songAlbumCount = result[0].song_album_count;
 | 
			
		||||
    let songArtistCount = result[0].song_artist_count;
 | 
			
		||||
    return `song: ${songCount}, album: ${albumCount}, artist: ${artistCount} | songAlbum: ${songAlbumCount}, songArtist: ${songArtistCount}`;
 | 
			
		||||
    return `song: ${songCount}, album: ${albumCount}(v3: ${albumV3Count}, v4: ${albumV4Count}), artist: ${artistCount} | songAlbum: ${songAlbumCount}, songArtist: ${songArtistCount}`;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    main: main,
 | 
			
		||||
    update: update,
 | 
			
		||||
    test: test,
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user