From ae1fa45eb67f84458f095568f0c500e79009ce23 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 28 Sep 2021 11:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 7 ++++++- .../io/legado/app/model/webBook/BookChapterList.kt | 10 ++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index c76253b7d..df8a6984e 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -71,8 +71,10 @@ class AnalyzeRule( } fun setRedirectUrl(url: String): URL? { - kotlin.runCatching { + try { redirectUrl = URL(url) + } catch (e: Exception) { + log("URL($url) error\n${e.localizedMessage}") } return redirectUrl } @@ -237,6 +239,8 @@ class AnalyzeRule( if (result == null) result = "" val str = kotlin.runCatching { Entities.unescape(result.toString()) + }.onFailure { + log("Entities.unescape() error\n${it.localizedMessage}") }.getOrElse { result.toString() } @@ -653,6 +657,7 @@ class AnalyzeRule( val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source) analyzeUrl.getStrResponse().body }.onFailure { + log("ajax(${urlStr}) error\n${it.stackTraceToString()}") it.printOnDebug() }.getOrElse { it.msg diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 9c4235e1b..2a4217c15 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -177,9 +177,7 @@ object BookChapterList { val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) val payRule = analyzeRule.splitSourceRule(tocRule.isPay) val upTimeRule = analyzeRule.splitSourceRule(tocRule.updateTime) - var isVip: String? - var isPay: String? - for (item in elements) { + elements.forEachIndexed { index, item -> scope.ensureActive() analyzeRule.setContent(item) val bookChapter = BookChapter(bookUrl = book.bookUrl, baseUrl = baseUrl) @@ -187,13 +185,13 @@ object BookChapterList { bookChapter.title = analyzeRule.getString(nameRule) bookChapter.url = analyzeRule.getString(urlRule) bookChapter.tag = analyzeRule.getString(upTimeRule) - isVip = analyzeRule.getString(vipRule) - isPay = analyzeRule.getString(payRule) if (bookChapter.url.isEmpty()) { bookChapter.url = baseUrl - Debug.log(bookSource.bookSourceUrl, "未获取到url,使用baseUrl替代") + Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代") } if (bookChapter.title.isNotEmpty()) { + val isVip = analyzeRule.getString(vipRule) + val isPay = analyzeRule.getString(payRule) if (isVip.isNotEmpty() && !isVip.matches(falseRegex)) { bookChapter.isVip = true }