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

album,artist请求增加超时时间;小调整

This commit is contained in:
2022-10-29 14:32:51 +08:00
parent bf74284ab2
commit 71eb3b7ce5
8 changed files with 80 additions and 85 deletions

View File

@@ -34,13 +34,14 @@ async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null
// 插入待爬取列表
if (finalIds.length > 0) {
await dbUtils.query(insertSql ? insertSql : `INSERT IGNORE INTO wait_fetch_${tableName} (id) VALUES ?`, [finalIds.map(id => [id])]);
var result = await dbUtils.query(insertSql ? insertSql : `INSERT IGNORE INTO wait_fetch_${tableName} (id) VALUES ?`, [finalIds.map(id => [id])]);
// console.log(result);
}
// 从待检查表中删除
if (ids.length > 0)
await dbUtils.query(`DELETE FROM wait_check_${tableName} WHERE id IN ?`, [[ids]]);
console.log(`table: ${tableName} | ${ids[0]} - ${ids.slice(-1)[0]}`);
console.log(`table: ${tableName} | ${ids[0]} - ${ids.slice(-1)[0]} (${result?.affectedRows}/${finalIds.length}/${ids.length})`);
}
}

View File

@@ -59,7 +59,7 @@ async function fetch({ albumId, debug = false, update = false }) {
let url = `https://music.163.com/album?id=${albumId}`;
try {
// var html = fs.readFileSync(path.join(__dirname, "../../temp", `album-${albumId}.html`), 'utf8');
var html = await requestUtils.getApiResult(url);
var html = await requestUtils.getApiResult(url, { timeout: 3000 });
// fs.writeFileSync(path.join(__dirname, "../../temp", `album-${albumId}.html`), html);
} catch (errors) {
console.error(errors);

View File

@@ -52,7 +52,7 @@ async function fetch({ artistId, debug = false }) {
let url = `https://music.163.com/artist?id=${artistId}`;
try {
// var html = fs.readFileSync(path.join(__dirname, "../../temp", `artist-${artistId}.html`), 'utf8');
var html = await requestUtils.getApiResult(url);
var html = await requestUtils.getApiResult(url, { timeout: 3000 });
// fs.writeFileSync(path.join(__dirname, "../../temp", `artist-${artistId}.html`), html);
} catch (errors) {
console.error(errors);

View File

@@ -21,7 +21,7 @@ async function fetchAll({ args = {} }) {
for (let i = 0; i < count; i++) {
await global.checkIsExit();
var subArray = songIds.slice(i * step, (i + 1) * step);
console.log(`${i + 1}/${count} | song: ${subArray[0]}-${subArray.slice(-1)[0]} | ${args.min || "?"}-${args.max || "?"}`);
console.log(`${i + 1}/${count} | song: ${subArray[0]}-${subArray.slice(-1)[0]} (${subArray.length}) | ${args.min || "?"}-${args.max || "?"}`);
try {
await fetch({ songIdArray: subArray });
} catch (err) {

View File

@@ -59,31 +59,37 @@ async function main(args) {
switch (args.utils) {
case 'song':
await songInfoUtils.fetchAll({ args: args });
await sleepUtils.sleep(60 * 1000);
break;
case 'album':
await albumInfoUtils.fetchAll({ args: args });
await sleepUtils.sleep(30 * 1000);
break;
case 'artist':
await artistInfoUtils.fetchAll({ args: args });
await sleepUtils.sleep(30 * 1000);
break;
case 'lyric':
await lyricInfoUtils.fetchAll({ args: args });
await sleepUtils.sleep(30 * 1000);
break;
case 'comment':
await commentUtils.fetchAll({ args: args });
await sleepUtils.sleep(30 * 1000);
break;
case 'playlist':
await playlistUtils.fetchAll({ args: args });
process.exit(0);
break;
case 'assistant':
await assistantUtils.updateWaitTable();
await sleepUtils.sleep(5000);
break;
default:
console.log("utils参数不匹配退出");
return;
}
await sleepUtils.sleep(2000);
}
}