pull/32/head
kunfei 5 years ago
parent 5d0462c2f7
commit 65e926d4c1
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
  2. 4
      app/src/main/java/io/legado/app/model/WebBook.kt
  3. 13
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  4. 8
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt

@ -3,11 +3,15 @@ package io.legado.app.data.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.legado.app.data.entities.BookChapter
@Dao
interface BookChapterDao {
@Query("select * from chapters where bookUrl = :bookUrl and `index` = :index")
fun getChapter(bookUrl: String, index: Int): BookChapter?
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookChapter: BookChapter)

@ -44,11 +44,11 @@ class WebBook(private val bookSource: BookSource) {
}
}
fun getContent(book: Book, bookChapter: BookChapter): Coroutine<String> {
fun getContent(book: Book, bookChapter: BookChapter, nextChapterUrl: String? = null): Coroutine<String> {
return Coroutine.async {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = bookChapter.url, baseUrl = book.tocUrl)
val response = analyzeUrl.getResponseAsync().await()
BookContent.analyzeContent(this, response, book, bookSource)
BookContent.analyzeContent(this, response, book, bookChapter, bookSource, nextChapterUrl)
}
}
}

@ -3,6 +3,7 @@ package io.legado.app.model.webbook
import io.legado.app.App
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.ContentRule
import io.legado.app.model.analyzeRule.AnalyzeRule
@ -20,7 +21,9 @@ object BookContent {
coroutineScope: CoroutineScope,
response: Response<String>,
book: Book,
bookSource: BookSource
bookChapter: BookChapter,
bookSource: BookSource,
nextChapterUrlF: String? = null
): String {
val baseUrl: String = NetworkUtils.getUrl(response)
val body: String? = response.body()
@ -38,7 +41,15 @@ object BookContent {
content.append(contentData.content)
if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0]
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())
nextChapterUrlF
else
App.db.bookChapterDao().getChapter(book.bookUrl, bookChapter.index + 1)?.url
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
if (!nextChapterUrl.isNullOrEmpty()
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl)
== NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl)
) break
nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute()
.body()?.let { nextBody ->

@ -5,7 +5,6 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook
import io.legado.app.utils.htmlFormat
import io.legado.app.utils.isAbsUrl
@ -117,7 +116,8 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
if (it.isNotEmpty()) {
printLog(debugSource, 1, "目录完成")
printLog(debugSource, 1, "", showTime = false)
contentDebug(book, it[0])
val nextChapterUrl = if (it.size > 1) it[1].url else null
contentDebug(book, it[0], nextChapterUrl)
} else {
printLog(debugSource, -1, "目录列表为空")
}
@ -129,9 +129,9 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
tasks.add(chapterList)
}
private fun contentDebug(book: Book, bookChapter: BookChapter) {
private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) {
printLog(debugSource, 1, "开始获取内容")
val content = webBook.getContent(book, bookChapter)
val content = webBook.getContent(book, bookChapter, nextChapterUrl)
.onSuccess { content ->
content?.let {
printLog(debugSource, 1000, it)

Loading…
Cancel
Save