Skip to content

Commit

Permalink
🎨 Second Formatting Code
Browse files Browse the repository at this point in the history
  • Loading branch information
freeok committed Dec 24, 2024
1 parent d40c8f0 commit 6fc87ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
*/
public class CheckUpdateAction {

private final int timeoutMills;
public static final String GHP = "https://ghp.ci/";
public static final String RELEASE_URL = "https://api.github.com/repos/freeok/so-novel/releases";
public static final String ASSETS_URL = "https://github.com/freeok/so-novel/releases/download/{}/sonovel-{}.tar.gz";
private final int timeoutMills;

public CheckUpdateAction() {
this.timeoutMills = 10_000;
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/pcdd/sonovel/action/DownloadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public class DownloadAction {

private final ConfigBean config;

private static void printSearchResult(List<SearchResult> results) {
ConsoleTable consoleTable = ConsoleTable.create().addHeader("序号", "书名", "作者", "最新章节", "最后更新时间");
for (int i = 1; i <= results.size(); i++) {
SearchResult r = results.get(i - 1);
consoleTable.addBody(String.valueOf(i),
r.getBookName(),
r.getAuthor(),
r.getLatestChapter(),
r.getLatestUpdate());
}
Console.table(consoleTable);
}

@SneakyThrows
public void execute(Terminal terminal) {
LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();
Expand Down Expand Up @@ -88,17 +101,4 @@ public void execute(Terminal terminal) {
Console.log("<== 完成!总耗时 {} s\n", NumberUtil.round(res, 2));
}

private static void printSearchResult(List<SearchResult> results) {
ConsoleTable consoleTable = ConsoleTable.create().addHeader("序号", "书名", "作者", "最新章节", "最后更新时间");
for (int i = 1; i <= results.size(); i++) {
SearchResult r = results.get(i - 1);
consoleTable.addBody(String.valueOf(i),
r.getBookName(),
r.getAuthor(),
r.getLatestChapter(),
r.getLatestUpdate());
}
Console.table(consoleTable);
}

}
}
52 changes: 26 additions & 26 deletions src/main/java/com/pcdd/sonovel/parse/BookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,13 @@
*/
public class BookParser extends Source {

private static final int TIMEOUT_MILLS = 15_000;
public static final String CONTENT = "content";
private static final int TIMEOUT_MILLS = 15_000;

public BookParser(int sourceId) {
super(sourceId);
}

@SneakyThrows
public Book parse(String url) {
Rule.Book r = this.rule.getBook();
Document document = Jsoup.connect(url)
.timeout(TIMEOUT_MILLS)
.header(Header.USER_AGENT.getValue(), RandomUA.generate())
.get();
String bookName = document.select(r.getBookName()).attr(CONTENT);
String author = document.select(r.getAuthor()).attr(CONTENT);
String intro = document.select(r.getIntro()).attr(CONTENT);
intro = StrUtil.cleanBlank(intro);
String coverUrl = document.select(r.getCoverUrl()).attr("src");

Book book = new Book();
book.setUrl(url);
book.setBookName(bookName);
book.setAuthor(author);
book.setIntro(intro);
book.setCoverUrl(CrawlUtils.normalizeUrl(coverUrl, this.rule.getUrl()));
book.setCoverUrl(replaceCover(book));

return book;
}

/**
* 封面替换为起点最新封面
*/
Expand Down Expand Up @@ -96,4 +72,28 @@ public static String replaceCover(Book book) {
return book.getCoverUrl();
}

}
@SneakyThrows
public Book parse(String url) {
Rule.Book r = this.rule.getBook();
Document document = Jsoup.connect(url)
.timeout(TIMEOUT_MILLS)
.header(Header.USER_AGENT.getValue(), RandomUA.generate())
.get();
String bookName = document.select(r.getBookName()).attr(CONTENT);
String author = document.select(r.getAuthor()).attr(CONTENT);
String intro = document.select(r.getIntro()).attr(CONTENT);
intro = StrUtil.cleanBlank(intro);
String coverUrl = document.select(r.getCoverUrl()).attr("src");

Book book = new Book();
book.setUrl(url);
book.setBookName(bookName);
book.setAuthor(author);
book.setIntro(intro);
book.setCoverUrl(CrawlUtils.normalizeUrl(coverUrl, this.rule.getUrl()));
book.setCoverUrl(replaceCover(book));

return book;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/pcdd/sonovel/parse/ChapterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
*/
public class ChapterParser extends Source {

private static final int TIMEOUT_MILLS = 15_000;
private final ConfigBean config;
private final ChapterConverter chapterConverter;
private static final int TIMEOUT_MILLS = 15_000;

public ChapterParser(ConfigBean config) {
super(config.getSourceId());
Expand Down

0 comments on commit 6fc87ac

Please sign in to comment.