Skip to content

Commit

Permalink
♻️ 搜索设置timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
freeok committed Nov 18, 2024
1 parent a195b35 commit 232a145
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/pcdd/sonovel/action/DownloadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void execute(Terminal terminal) {
int start = 1;
int end = Integer.MAX_VALUE;
if (downloadPolicy == 1) {
String[] split = reader.readLine("==> 请输起始章(最小为1)和结束章,用空格隔开").split("\\s+");
String[] split = reader.readLine("==> 请输起始章(最小为1)和结束章,用空格隔开:").trim().split("\\s+");
start = Integer.parseInt(split[0]);
end = Integer.parseInt(split[1]);
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/pcdd/sonovel/core/CrawlerPostHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public void handle(String extName, Book book, File saveDir) {
Console.log(s);

switch (extName) {
case "epub" -> convertToEpub(saveDir, book);
case "epub" -> convert2Epub(saveDir, book);
case "txt" -> mergeTxt(saveDir, book.getBookName(), book.getAuthor());
case "html" -> generateCatalog(saveDir);
default -> Console.error("暂不支持的格式:{}", extName);
}
}

@SneakyThrows
private void convertToEpub(File dir, Book b) {
private void convert2Epub(File dir, Book b) {
if (FileUtil.isDirEmpty(dir)) {
Console.error(render("==> @|red 《{}》({})下载章节数为 0,取消生成 epub|@"), b.getBookName(), b.getAuthor());
return;
Expand All @@ -68,12 +68,11 @@ private void convertToEpub(File dir, Book b) {
book.getMetadata().addTitle(b.getBookName());
book.getMetadata().addAuthor(new Author(b.getAuthor()));
book.getMetadata().addDescription(b.getDescription());
// 不设置会导致部分阅读器出现问题(例如ibooks无法使用中文字体)
// 不设置会导致 apple books 无法使用苹方字体
book.getMetadata().setLanguage("zh");
byte[] bytes = HttpUtil.downloadBytes(b.getCoverUrl());
book.setCoverImage(new Resource(bytes, ".jpg"));

// TODO 创建 guide
// Guide guide = book.getGuide();

int i = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SearchResultParser(int sourceId) {
@SneakyThrows
public List<SearchResult> parse(String keyword) {
Rule.Search search = this.rule.getSearch();
Connection connect = Jsoup.connect(search.getUrl());
Connection connect = Jsoup.connect(search.getUrl()).timeout(10_000);
// 搜索结果页DOM
Document document = connect.data(search.getParamName().getKeyword(), keyword).post();
Elements elements = document.select(search.getResult());
Expand Down

0 comments on commit 232a145

Please sign in to comment.