pull/1259/head
gedoor 3 years ago
parent 621dd557d3
commit ffb95cb53d
  1. 7
      app/src/main/java/io/legado/app/help/http/StrResponse.kt
  2. 10
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  3. 8
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  4. 8
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  5. 8
      app/src/main/java/io/legado/app/model/webBook/BookList.kt
  6. 73
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@ -21,11 +21,16 @@ class StrResponse {
}
constructor(url: String, body: String?) {
val request = try {
Request.Builder().url(url).build()
} catch (e: Exception) {
Request.Builder().url("http://localhost/").build()
}
raw = Builder()
.code(200)
.message("OK")
.protocol(Protocol.HTTP_1_1)
.request(Request.Builder().url(url).build())
.request(request)
.build()
this.body = body
}

@ -6,6 +6,7 @@ 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.TocRule
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -21,16 +22,17 @@ object BookChapterList {
suspend fun analyzeChapterList(
scope: CoroutineScope,
book: Book,
body: String?,
strResponse: StrResponse,
bookSource: BookSource,
baseUrl: String,
book: Book,
redirectUrl: String
): List<BookChapter> {
val chapterList = ArrayList<BookChapter>()
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl)
)
val chapterList = ArrayList<BookChapter>()
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
Debug.log(bookSource.bookSourceUrl, body, state = 30)
val tocRule = bookSource.getTocRule()

@ -7,6 +7,7 @@ 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.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -24,14 +25,15 @@ object BookContent {
@Throws(Exception::class)
suspend fun analyzeContent(
scope: CoroutineScope,
body: String?,
strResponse: StrResponse,
bookSource: BookSource,
book: Book,
bookChapter: BookChapter,
bookSource: BookSource,
baseUrl: String,
redirectUrl: String,
nextChapterUrl: String? = null
): String {
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl)
)

@ -4,6 +4,7 @@ import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.HtmlFormatter
@ -18,13 +19,14 @@ object BookInfo {
@Throws(Exception::class)
fun analyzeBookInfo(
scope: CoroutineScope,
book: Book,
body: String?,
strResponse: StrResponse,
bookSource: BookSource,
baseUrl: String,
book: Book,
redirectUrl: String,
canReName: Boolean,
) {
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl)
)

@ -6,6 +6,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.rule.BookListRule
import io.legado.app.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -21,20 +22,21 @@ object BookList {
@Throws(Exception::class)
fun analyzeBookList(
scope: CoroutineScope,
body: String?,
strResponse: StrResponse,
bookSource: BookSource,
analyzeUrl: AnalyzeUrl,
baseUrl: String,
variableBook: SearchBook,
isSearch: Boolean = true,
): ArrayList<SearchBook> {
val bookList = ArrayList<SearchBook>()
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception(
appCtx.getString(
R.string.error_get_web_content,
analyzeUrl.ruleUrl
)
)
val bookList = ArrayList<SearchBook>()
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
Debug.log(bookSource.bookSourceUrl, body, state = 10)
val analyzeRule = AnalyzeRule(variableBook)

@ -5,6 +5,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope
@ -47,15 +48,7 @@ class WebBook(val bookSource: BookSource) {
book = variableBook
)
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
return BookList.analyzeBookList(
scope,
res.body,
bookSource,
analyzeUrl,
res.url,
variableBook,
true
)
return BookList.analyzeBookList(scope, res, bookSource, analyzeUrl, variableBook, true)
}
return arrayListOf()
}
@ -88,15 +81,7 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap()
)
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
return BookList.analyzeBookList(
scope,
res.body,
bookSource,
analyzeUrl,
res.url,
variableBook,
false
)
return BookList.analyzeBookList(scope, res, bookSource, analyzeUrl, variableBook, false)
}
/**
@ -120,16 +105,8 @@ class WebBook(val bookSource: BookSource) {
): Book {
book.type = bookSource.bookSourceType
if (!book.infoHtml.isNullOrEmpty()) {
book.infoHtml
BookInfo.analyzeBookInfo(
scope,
book,
book.infoHtml,
bookSource,
book.bookUrl,
book.bookUrl,
canReName
)
val strResponse = StrResponse(book.bookUrl, book.infoHtml)
BookInfo.analyzeBookInfo(scope, strResponse, bookSource, book, book.bookUrl, canReName)
} else {
val res = AnalyzeUrl(
ruleUrl = book.bookUrl,
@ -137,15 +114,7 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap(),
book = book
).getStrResponse(bookSource.bookSourceUrl)
BookInfo.analyzeBookInfo(
scope,
book,
res.body,
bookSource,
book.bookUrl,
res.url,
canReName
)
BookInfo.analyzeBookInfo(scope, res, bookSource, book, book.bookUrl, canReName)
}
return book
}
@ -169,14 +138,8 @@ class WebBook(val bookSource: BookSource) {
): List<BookChapter> {
book.type = bookSource.bookSourceType
return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList(
scope,
book,
book.tocHtml,
bookSource,
book.tocUrl,
book.tocUrl
)
val strResponse = StrResponse(book.tocUrl, book.tocHtml)
BookChapterList.analyzeChapterList(scope, strResponse, bookSource, book, book.tocUrl)
} else {
val res = AnalyzeUrl(
book = book,
@ -184,14 +147,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl)
BookChapterList.analyzeChapterList(
scope,
book,
res.body,
bookSource,
book.tocUrl,
res.url
)
BookChapterList.analyzeChapterList(scope, res, bookSource, book, book.tocUrl)
}
}
@ -221,13 +177,13 @@ class WebBook(val bookSource: BookSource) {
return bookChapter.url
}
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
val strResponse = StrResponse(bookChapter.getAbsoluteURL(), book.tocHtml)
BookContent.analyzeContent(
scope,
book.tocHtml,
strResponse,
bookSource,
book,
bookChapter,
bookSource,
bookChapter.getAbsoluteURL(),
bookChapter.getAbsoluteURL(),
nextChapterUrl
)
@ -245,12 +201,11 @@ class WebBook(val bookSource: BookSource) {
)
BookContent.analyzeContent(
scope,
res.body,
res,
bookSource,
book,
bookChapter,
bookSource,
bookChapter.getAbsoluteURL(),
res.url,
nextChapterUrl
)
}

Loading…
Cancel
Save