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?) { constructor(url: String, body: String?) {
val request = try {
Request.Builder().url(url).build()
} catch (e: Exception) {
Request.Builder().url("http://localhost/").build()
}
raw = Builder() raw = Builder()
.code(200) .code(200)
.message("OK") .message("OK")
.protocol(Protocol.HTTP_1_1) .protocol(Protocol.HTTP_1_1)
.request(Request.Builder().url(url).build()) .request(request)
.build() .build()
this.body = body 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.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.TocRule 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.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -21,16 +22,17 @@ object BookChapterList {
suspend fun analyzeChapterList( suspend fun analyzeChapterList(
scope: CoroutineScope, scope: CoroutineScope,
book: Book, strResponse: StrResponse,
body: String?,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String, book: Book,
redirectUrl: String redirectUrl: String
): List<BookChapter> { ): List<BookChapter> {
val chapterList = ArrayList<BookChapter>() val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception( body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl) appCtx.getString(R.string.error_get_web_content, baseUrl)
) )
val chapterList = ArrayList<BookChapter>()
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
Debug.log(bookSource.bookSourceUrl, body, state = 30) Debug.log(bookSource.bookSourceUrl, body, state = 30)
val tocRule = bookSource.getTocRule() 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.BookSource
import io.legado.app.data.entities.rule.ContentRule import io.legado.app.data.entities.rule.ContentRule
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -24,14 +25,15 @@ object BookContent {
@Throws(Exception::class) @Throws(Exception::class)
suspend fun analyzeContent( suspend fun analyzeContent(
scope: CoroutineScope, scope: CoroutineScope,
body: String?, strResponse: StrResponse,
bookSource: BookSource,
book: Book, book: Book,
bookChapter: BookChapter, bookChapter: BookChapter,
bookSource: BookSource,
baseUrl: String,
redirectUrl: String, redirectUrl: String,
nextChapterUrl: String? = null nextChapterUrl: String? = null
): String { ): String {
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception( body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl) 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.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.HtmlFormatter
@ -18,13 +19,14 @@ object BookInfo {
@Throws(Exception::class) @Throws(Exception::class)
fun analyzeBookInfo( fun analyzeBookInfo(
scope: CoroutineScope, scope: CoroutineScope,
book: Book, strResponse: StrResponse,
body: String?,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String, book: Book,
redirectUrl: String, redirectUrl: String,
canReName: Boolean, canReName: Boolean,
) { ) {
val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception( body ?: throw Exception(
appCtx.getString(R.string.error_get_web_content, baseUrl) 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.SearchBook
import io.legado.app.data.entities.rule.BookListRule import io.legado.app.data.entities.rule.BookListRule
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -21,20 +22,21 @@ object BookList {
@Throws(Exception::class) @Throws(Exception::class)
fun analyzeBookList( fun analyzeBookList(
scope: CoroutineScope, scope: CoroutineScope,
body: String?, strResponse: StrResponse,
bookSource: BookSource, bookSource: BookSource,
analyzeUrl: AnalyzeUrl, analyzeUrl: AnalyzeUrl,
baseUrl: String,
variableBook: SearchBook, variableBook: SearchBook,
isSearch: Boolean = true, isSearch: Boolean = true,
): ArrayList<SearchBook> { ): ArrayList<SearchBook> {
val bookList = ArrayList<SearchBook>() val baseUrl = strResponse.url
val body = strResponse.body
body ?: throw Exception( body ?: throw Exception(
appCtx.getString( appCtx.getString(
R.string.error_get_web_content, R.string.error_get_web_content,
analyzeUrl.ruleUrl analyzeUrl.ruleUrl
) )
) )
val bookList = ArrayList<SearchBook>()
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}") Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
Debug.log(bookSource.bookSourceUrl, body, state = 10) Debug.log(bookSource.bookSourceUrl, body, state = 10)
val analyzeRule = AnalyzeRule(variableBook) 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.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.coroutine.Coroutine 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.Debug
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -47,15 +48,7 @@ class WebBook(val bookSource: BookSource) {
book = variableBook book = variableBook
) )
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl) val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
return BookList.analyzeBookList( return BookList.analyzeBookList(scope, res, bookSource, analyzeUrl, variableBook, true)
scope,
res.body,
bookSource,
analyzeUrl,
res.url,
variableBook,
true
)
} }
return arrayListOf() return arrayListOf()
} }
@ -88,15 +81,7 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl) val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
return BookList.analyzeBookList( return BookList.analyzeBookList(scope, res, bookSource, analyzeUrl, variableBook, false)
scope,
res.body,
bookSource,
analyzeUrl,
res.url,
variableBook,
false
)
} }
/** /**
@ -120,16 +105,8 @@ class WebBook(val bookSource: BookSource) {
): Book { ): Book {
book.type = bookSource.bookSourceType book.type = bookSource.bookSourceType
if (!book.infoHtml.isNullOrEmpty()) { if (!book.infoHtml.isNullOrEmpty()) {
book.infoHtml val strResponse = StrResponse(book.bookUrl, book.infoHtml)
BookInfo.analyzeBookInfo( BookInfo.analyzeBookInfo(scope, strResponse, bookSource, book, book.bookUrl, canReName)
scope,
book,
book.infoHtml,
bookSource,
book.bookUrl,
book.bookUrl,
canReName
)
} else { } else {
val res = AnalyzeUrl( val res = AnalyzeUrl(
ruleUrl = book.bookUrl, ruleUrl = book.bookUrl,
@ -137,15 +114,7 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap(), headerMapF = bookSource.getHeaderMap(),
book = book book = book
).getStrResponse(bookSource.bookSourceUrl) ).getStrResponse(bookSource.bookSourceUrl)
BookInfo.analyzeBookInfo( BookInfo.analyzeBookInfo(scope, res, bookSource, book, book.bookUrl, canReName)
scope,
book,
res.body,
bookSource,
book.bookUrl,
res.url,
canReName
)
} }
return book return book
} }
@ -169,14 +138,8 @@ class WebBook(val bookSource: BookSource) {
): List<BookChapter> { ): List<BookChapter> {
book.type = bookSource.bookSourceType book.type = bookSource.bookSourceType
return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList( val strResponse = StrResponse(book.tocUrl, book.tocHtml)
scope, BookChapterList.analyzeChapterList(scope, strResponse, bookSource, book, book.tocUrl)
book,
book.tocHtml,
bookSource,
book.tocUrl,
book.tocUrl
)
} else { } else {
val res = AnalyzeUrl( val res = AnalyzeUrl(
book = book, book = book,
@ -184,14 +147,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.bookUrl, baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl) ).getStrResponse(bookSource.bookSourceUrl)
BookChapterList.analyzeChapterList( BookChapterList.analyzeChapterList(scope, res, bookSource, book, book.tocUrl)
scope,
book,
res.body,
bookSource,
book.tocUrl,
res.url
)
} }
} }
@ -221,13 +177,13 @@ class WebBook(val bookSource: BookSource) {
return bookChapter.url return bookChapter.url
} }
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
val strResponse = StrResponse(bookChapter.getAbsoluteURL(), book.tocHtml)
BookContent.analyzeContent( BookContent.analyzeContent(
scope, scope,
book.tocHtml, strResponse,
bookSource,
book, book,
bookChapter, bookChapter,
bookSource,
bookChapter.getAbsoluteURL(),
bookChapter.getAbsoluteURL(), bookChapter.getAbsoluteURL(),
nextChapterUrl nextChapterUrl
) )
@ -245,12 +201,11 @@ class WebBook(val bookSource: BookSource) {
) )
BookContent.analyzeContent( BookContent.analyzeContent(
scope, scope,
res.body, res,
bookSource,
book, book,
bookChapter, bookChapter,
bookSource,
bookChapter.getAbsoluteURL(), bookChapter.getAbsoluteURL(),
res.url,
nextChapterUrl nextChapterUrl
) )
} }

Loading…
Cancel
Save