1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

watch update

This commit is contained in:
程序员小墨 2022-10-02 23:48:07 +08:00
parent 326201fb2f
commit dfab62b437
3 changed files with 48 additions and 14 deletions

View File

@ -75,6 +75,14 @@ async function update() {
/** /**
* 统计数据库中数据 * 统计数据库中数据
*/ */
let watchParam = {
songCount: 0,
albumCount: 0,
artistCount: 0,
lyricCount: 0,
commentCount: 0,
commentTotalCount: 0,
};
async function watch() { async function watch() {
let sql = ` let sql = `
SELECT SELECT
@ -88,7 +96,9 @@ async function watch() {
artist_waiting, artist_waiting,
lyric_count, lyric_count,
lyric_waiting,
comment_count,
comment_total_count,
song_album_count, song_album_count,
song_artist_count song_artist_count
@ -104,12 +114,16 @@ async function watch() {
( SELECT count( DISTINCT artist_id ) as artist_waiting FROM song_artist_relation WHERE artist_id NOT IN ( SELECT DISTINCT artist_id FROM artist ) ) as t_album_waiting_song_artist, ( SELECT count( DISTINCT artist_id ) as artist_waiting FROM song_artist_relation WHERE artist_id NOT IN ( SELECT DISTINCT artist_id FROM artist ) ) as t_album_waiting_song_artist,
( SELECT count(*) AS lyric_count FROM lyric ) t_lyric, ( SELECT count(*) AS lyric_count FROM lyric ) t_lyric,
( SELECT count( DISTINCT song_id ) as lyric_waiting FROM song WHERE song_id NOT IN ( SELECT DISTINCT song_id FROM lyric ) ) as t_lyric_waiting_song,
( SELECT count( DISTINCT song_id ) AS comment_count, count( comment_id ) AS comment_total_count FROM comment ) t_comment,
( SELECT count(*) AS song_album_count FROM song_album_relation ) t_song_album, ( SELECT count(*) AS song_album_count FROM song_album_relation ) t_song_album,
( SELECT count(*) AS song_artist_count FROM song_artist_relation ) t_song_artist ( SELECT count(*) AS song_artist_count FROM song_artist_relation ) t_song_artist
`; `;
console.log("开始统计 ...");
let startTime = Date.now();
let result = await dbUtils.query(sql, []); let result = await dbUtils.query(sql, []);
let timeSpent = Date.now() - startTime;
let songCount = result[0].song_count; let songCount = result[0].song_count;
let songWaiting = result[0].song_waiting; let songWaiting = result[0].song_waiting;
@ -121,19 +135,35 @@ async function watch() {
let artistWaiting = result[0].artist_waiting; let artistWaiting = result[0].artist_waiting;
let lyricCount = result[0].lyric_count; let lyricCount = result[0].lyric_count;
let lyricWaiting = result[0].lyric_waiting;
let commentCount = result[0].comment_count;
let commentTotalCount = result[0].comment_total_count;
let songAlbumCount = result[0].song_album_count; let songAlbumCount = result[0].song_album_count;
let songArtistCount = result[0].song_artist_count; let songArtistCount = result[0].song_artist_count;
let statisticsString = [ let statisticsString = [
`song: ${songCount}/${songCount + songWaiting}`, `[与上次运行统计时相比]`,
`album: ${albumCount}/${albumCount + albumWaiting}`, `song: ${songCount - watchParam.songCount}, album: ${albumCount - watchParam.albumCount}, artist: ${artistCount - watchParam.artistCount}, lyric: ${lyricCount - watchParam.lyricCount}, comment: ${commentCount - watchParam.commentCount}(song)/${commentTotalCount - watchParam.commentTotalCount}(comment)`,
`artist: ${artistCount}/${artistCount + artistWaiting}`, `[已爬取]`,
`lyric: ${lyricCount}/${lyricCount + lyricWaiting}`, `song: ${songCount}, album: ${albumCount}, artist: ${artistCount}, lyric: ${lyricCount}, comment: ${commentCount}(song)/${commentTotalCount}(comment)`,
`songAlbum: ${songAlbumCount}`, `[待爬取]`,
`songArtist: ${songArtistCount}` `song: ${songWaiting}, album: ${albumWaiting}, artist: ${artistWaiting}, lyric: ${songCount - lyricCount}, comment: ${songCount - commentCount}`,
].join(', '); `[总计] (已爬取 + 待爬取)`,
`song: ${songCount + songWaiting}, album: ${albumCount + albumWaiting}, artist: ${artistCount + artistWaiting}, lyric: ${songCount}, comment: ${songCount}`,
`[关联关系统计]`,
`song-album: ${songAlbumCount}, song-artist: ${songArtistCount}`,
`time spent: ${timeSpent}ms(${(timeSpent / 1000).toFixed(2)}s)`,
``
].join('\n');
console.log(statisticsString); console.log(statisticsString);
watchParam = {
songCount: songCount,
albumCount: albumCount,
artistCount: artistCount,
lyricCount: lyricCount,
commentCount: commentCount,
commentTotalCount: commentTotalCount,
}
} }
/** /**

View File

@ -6,6 +6,9 @@ const sleepUtils = require('../../../utils/sleepUtils');
const dbUtils = global.dbUtils; const dbUtils = global.dbUtils;
// refer:
// https://neteasecloudmusicapi-docs.4everland.app/
// https://github.com/Binaryify/NeteaseCloudMusicApi
const { comment_music } = require('NeteaseCloudMusicApi'); const { comment_music } = require('NeteaseCloudMusicApi');
async function fetchAll() { async function fetchAll() {

View File

@ -1,11 +1,12 @@
const neteaseMusic = require('./netease_music/index'); let keepWatching = true;
let keepWatching = false;
if (keepWatching) { if (keepWatching) {
global.useMysqlPool = true; global.useMysqlPool = true;
global.connectionLimit = 1; global.connectionLimit = 1;
setInterval(neteaseMusic.watch, 10 * 1000);
} else { } else {
global.useMysqlPool = false; global.useMysqlPool = false;
} }
const neteaseMusic = require('./netease_music/index');
neteaseMusic.watch(); neteaseMusic.watch();
if (keepWatching)
setInterval(neteaseMusic.watch, 15 * 1000);