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

pull/1155/head
gedoor 3 years ago
parent 3a4a47b6a6
commit db1fc2ee19
  1. 20
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  2. 23
      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, "┌获取分类")
try {
analyzeRule.getStringList(infoRule.kind) analyzeRule.getStringList(infoRule.kind)
?.joinToString(",") ?.joinToString(",")
?.let { ?.let {
if (it.isNotEmpty()) book.kind = it 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, "┌获取字数")
try {
wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let { wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let {
if (it.isNotEmpty()) book.wordCount = it if (it.isNotEmpty()) book.wordCount = it
} }
Debug.log(bookSource.bookSourceUrl, "${book.wordCount}") Debug.log(bookSource.bookSourceUrl, "${book.wordCount}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节") Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
try {
analyzeRule.getString(infoRule.lastChapter).let { analyzeRule.getString(infoRule.lastChapter).let {
if (it.isNotEmpty()) book.latestChapterTitle = it if (it.isNotEmpty()) book.latestChapterTitle = it
} }
Debug.log(bookSource.bookSourceUrl, "${book.latestChapterTitle}") Debug.log(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取简介") Debug.log(bookSource.bookSourceUrl, "┌获取简介")
try {
analyzeRule.getString(infoRule.intro).let { analyzeRule.getString(infoRule.intro).let {
if (it.isNotEmpty()) book.intro = HtmlFormatter.format(it) if (it.isNotEmpty()) book.intro = HtmlFormatter.format(it)
} }
Debug.log(bookSource.bookSourceUrl, "${book.intro}") Debug.log(bookSource.bookSourceUrl, "${book.intro}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
}
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接") Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
try {
analyzeRule.getString(infoRule.coverUrl).let { analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it) if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it)
} }
Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}") Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}")
} catch (e: Exception) {
Debug.log(bookSource.bookSourceUrl, "${e.localizedMessage}")
}
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)
try {
searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",") searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",")
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}", log) 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)
try {
searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount)) searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount))
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}", log) 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)
try {
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", log) 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)
try {
searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro)) searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro))
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}", log) 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)
try {
analyzeRule.getString(ruleCoverUrl).let { analyzeRule.getString(ruleCoverUrl).let {
if (it.isNotEmpty()) searchBook.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it) if (it.isNotEmpty()) searchBook.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it)
} }
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", log) Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", 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.bookUrl = analyzeRule.getString(ruleBookUrl, true) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)

Loading…
Cancel
Save