Skip to content

Commit

Permalink
Merge pull request raawaa#7 from qiusli/master
Browse files Browse the repository at this point in the history
--search 某一具体番号时,只处理第一页。
  • Loading branch information
raawaa committed Nov 6, 2015
2 parents 3a11cf8 + 1f48031 commit cd463a4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions jav.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (program.cover && !program.timeout) {
}

var count = parseInt(program.limit);
var hasLimit = (count !== 0);
var hasLimit = (count !== 0), targetFound = false;
var output = program.output.replace(/['"]/g, '');
var errorCount = 0;

Expand Down Expand Up @@ -78,7 +78,7 @@ async.during(
}
if (hasLimit && (count < 1)) {
console.log('已尝试抓取%s个%s,其中%d个%s抓取失败,本次抓取完毕'.green.bold,
program.limit,
program.limit,
( program.cover ? '封面' : '磁链' ),
errorCount,
( program.cover ? '封面' : '磁链' ));
Expand Down Expand Up @@ -137,17 +137,19 @@ function getItems(links, next) {
}

function pageExist(callback) {
if (hasLimit && (count < 1)) {
if (hasLimit && (count < 1) || targetFound) {
return callback();
}
var url = baseUrl + (pageIndex === 1 ? '' : ('/page/' + pageIndex));
if (program.search) {
url = baseUrl + searchUrl + '/' + program.search + (pageIndex === 1 ? '' : ('/' + pageIndex));
} else if (program.base) {
url = program.base + (pageIndex === 1 ? '' : ('/' + pageIndex));
} else {
// 只在没有指定搜索条件时显示
console.log('获取第%d页中的影片链接 ( %s )...'.green, pageIndex, url);
}

console.log('获取第%d页中的影片链接 ( %s )...'.green, pageIndex, url);
let retryCount = 1;
async.retry(3,
function(callback, result) {
Expand Down Expand Up @@ -178,6 +180,9 @@ function pageExist(callback) {
}
return callback(err);
}
if(program.search) {
targetFound = true;
}
callback(null, res.ok);
});
}
Expand Down

0 comments on commit cd463a4

Please sign in to comment.