非关键规则添加try防止报错中断解析

pull/1155/head
gedoor 3 years ago
parent 3a4a47b6a6
commit db1fc2ee19
  1. 56
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  2. 43
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -73,36 +73,56 @@ object BookInfo {
} }
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取分类") Debug.log(bookSource.bookSourceUrl, "┌获取分类")
analyzeRule.getStringList(infoRule.kind) try {
?.joinToString(",") analyzeRule.getStringList(infoRule.kind)
?.let { ?.joinToString(",")
if (it.isNotEmpty()) book.kind = it ?.let {
} if (it.isNotEmpty()) book.kind = it
Debug.log(bookSource.bookSourceUrl, "${book.kind}") }
Debug.log(bookSource.bookSourceUrl, "${book.kind}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取字数") Debug.log(bookSource.bookSourceUrl, "┌获取字数")
wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let { try {
if (it.isNotEmpty()) book.wordCount = it wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let {
if (it.isNotEmpty()) book.wordCount = it
}
Debug.log(bookSource.bookSourceUrl, "${book.wordCount}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
} }
Debug.log(bookSource.bookSourceUrl, "${book.wordCount}")
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节") Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
analyzeRule.getString(infoRule.lastChapter).let { try {
if (it.isNotEmpty()) book.latestChapterTitle = it analyzeRule.getString(infoRule.lastChapter).let {
if (it.isNotEmpty()) book.latestChapterTitle = it
}
Debug.log(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
} }
Debug.log(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取简介") Debug.log(bookSource.bookSourceUrl, "┌获取简介")
analyzeRule.getString(infoRule.intro).let { try {
if (it.isNotEmpty()) book.intro = HtmlFormatter.format(it) analyzeRule.getString(infoRule.intro).let {
if (it.isNotEmpty()) book.intro = HtmlFormatter.format(it)
}
Debug.log(bookSource.bookSourceUrl, "${book.intro}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
} }
Debug.log(bookSource.bookSourceUrl, "${book.intro}")
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接") Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
analyzeRule.getString(infoRule.coverUrl).let { try {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it) analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it)
}
Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
} }
Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}")
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") Debug.log(bookSource.bookSourceUrl, "┌获取目录链接")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true)

@ -186,26 +186,47 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}", log) Debug.log(bookSource.bookSourceUrl, "${searchBook.author}", log)
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取分类", log) Debug.log(bookSource.bookSourceUrl, "┌获取分类", log)
searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",") try {
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}", log) searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",")
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}", log)
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}", log)
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取字数", log) Debug.log(bookSource.bookSourceUrl, "┌获取字数", log)
searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount)) try {
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}", log) searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount))
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}", log)
} catch (e: java.lang.Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}", log)
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log) Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) try {
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", log) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", log)
} catch (e: java.lang.Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}", log)
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取简介", log) Debug.log(bookSource.bookSourceUrl, "┌获取简介", log)
searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro)) try {
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}", log) searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro))
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}", log)
} catch (e: java.lang.Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}", log)
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log) Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
analyzeRule.getString(ruleCoverUrl).let { try {
if (it.isNotEmpty()) searchBook.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it) analyzeRule.getString(ruleCoverUrl).let {
if (it.isNotEmpty()) searchBook.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it)
}
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", log)
} catch (e: java.lang.Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}", log)
} }
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", log)
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log) Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)

Loading…
Cancel
Save