feat: 优化代码

pull/120/head
kunfei 5 years ago
parent 310d89d23a
commit ea3db51478
  1. 77
      app/src/main/java/io/legado/app/model/WebBook.kt

@ -86,17 +86,18 @@ class WebBook(val bookSource: BookSource) {
): Coroutine<Book> { ): Coroutine<Book> {
book.type = bookSource.bookSourceType book.type = bookSource.bookSourceType
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val body = if (!book.infoHtml.isNullOrEmpty()) { val body =
book.infoHtml if (!book.infoHtml.isNullOrEmpty()) {
} else { book.infoHtml
val analyzeUrl = AnalyzeUrl( } else {
book = book, val analyzeUrl = AnalyzeUrl(
ruleUrl = book.bookUrl, book = book,
baseUrl = sourceUrl, ruleUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap() baseUrl = sourceUrl,
) headerMapF = bookSource.getHeaderMap()
analyzeUrl.getResponseAwait().body )
} analyzeUrl.getResponseAwait().body
}
BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl) BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl)
book book
} }
@ -112,16 +113,17 @@ class WebBook(val bookSource: BookSource) {
): Coroutine<List<BookChapter>> { ): Coroutine<List<BookChapter>> {
book.type = bookSource.bookSourceType book.type = bookSource.bookSourceType
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val body = if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { val body =
book.tocHtml if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
} else { book.tocHtml
AnalyzeUrl( } else {
book = book, AnalyzeUrl(
ruleUrl = book.tocUrl, book = book,
baseUrl = book.bookUrl, ruleUrl = book.tocUrl,
headerMapF = bookSource.getHeaderMap() baseUrl = book.bookUrl,
).getResponseAwait().body headerMapF = bookSource.getHeaderMap()
} ).getResponseAwait().body
}
BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl) BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl)
} }
} }
@ -141,22 +143,23 @@ class WebBook(val bookSource: BookSource) {
Debug.log(sourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}") Debug.log(sourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
return@async bookChapter.url return@async bookChapter.url
} }
val body = if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { val body =
book.tocHtml if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
} else { book.tocHtml
val analyzeUrl = } else {
AnalyzeUrl( val analyzeUrl =
book = book, AnalyzeUrl(
ruleUrl = bookChapter.url, book = book,
baseUrl = book.tocUrl, ruleUrl = bookChapter.url,
headerMapF = bookSource.getHeaderMap() baseUrl = book.tocUrl,
) headerMapF = bookSource.getHeaderMap()
analyzeUrl.getResponseAwait( )
bookSource.bookSourceUrl, analyzeUrl.getResponseAwait(
jsStr = bookSource.getContentRule().webJs, bookSource.bookSourceUrl,
sourceRegex = bookSource.getContentRule().sourceRegex jsStr = bookSource.getContentRule().webJs,
).body sourceRegex = bookSource.getContentRule().sourceRegex
} ).body
}
BookContent.analyzeContent( BookContent.analyzeContent(
this, this,
body, body,

Loading…
Cancel
Save