pull/38/head
kunfei 6 years ago
parent e70bf34472
commit f2fbdbec2d
  1. 3
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 15
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 14
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  4. 16
      app/src/main/java/io/legado/app/model/WebBook.kt
  5. 29
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  6. 2
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  7. 44
      app/src/main/java/io/legado/app/model/webbook/BookInfo.kt
  8. 94
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  9. 45
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt

@ -7,6 +7,9 @@ interface BaseBook {
var kind: String? var kind: String?
var wordCount: String? var wordCount: String?
var infoHtml: String?
var tocHtml: String?
fun putVariable(key: String, value: String) fun putVariable(key: String, value: String)
fun getKindList(): List<String> { fun getKindList(): List<String> {

@ -47,10 +47,18 @@ data class Book(
var useReplaceRule: Boolean = true, // 正文使用净化替换规则 var useReplaceRule: Boolean = true, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable, BaseBook { ) : Parcelable, BaseBook {
@IgnoredOnParcel
@Ignore @Ignore
@IgnoredOnParcel
override var variableMap: HashMap<String, String> = GSON.fromJsonObject(variable) ?: HashMap() override var variableMap: HashMap<String, String> = GSON.fromJsonObject(variable) ?: HashMap()
@Ignore
@IgnoredOnParcel
override var infoHtml: String? = null
@Ignore
@IgnoredOnParcel
override var tocHtml: String? = null
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0) fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
fun getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl fun getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl
@ -77,6 +85,9 @@ data class Book(
tocUrl = tocUrl, tocUrl = tocUrl,
originOrder = originOrder, originOrder = originOrder,
variable = variable variable = variable
) ).apply {
this.infoHtml = this@Book.infoHtml
this.tocHtml = this@Book.tocHtml
}
} }
} }

@ -27,10 +27,17 @@ data class SearchBook(
var tocUrl: String = "", // 目录页Url (toc=table of Contents) var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var time: Long = System.currentTimeMillis(), var time: Long = System.currentTimeMillis(),
var variable: String? = null, var variable: String? = null,
var bookInfoHtml: String? = null,
var originOrder: Int = 0 var originOrder: Int = 0
) : Parcelable, BaseBook, Comparable<SearchBook> { ) : Parcelable, BaseBook, Comparable<SearchBook> {
@Ignore
@IgnoredOnParcel
override var infoHtml: String? = null
@Ignore
@IgnoredOnParcel
override var tocHtml: String? = null
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (other is SearchBook) { if (other is SearchBook) {
if (other.bookUrl == bookUrl) { if (other.bookUrl == bookUrl) {
@ -72,6 +79,9 @@ data class SearchBook(
tocUrl = tocUrl, tocUrl = tocUrl,
originOrder = originOrder, originOrder = originOrder,
variable = variable variable = variable
) ).apply {
this.infoHtml = this@SearchBook.infoHtml
this.tocUrl = this@SearchBook.tocUrl
}
} }
} }

@ -73,14 +73,18 @@ class WebBook(val bookSource: BookSource) {
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<Book> { ): Coroutine<Book> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val body = if (book.infoHtml.isNullOrEmpty()) {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
book = book, book = book,
ruleUrl = book.bookUrl, ruleUrl = book.bookUrl,
baseUrl = sourceUrl, baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val response = analyzeUrl.getResponseAsync().await() analyzeUrl.getResponseAsync().await().body()
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl) } else {
book.infoHtml
}
BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl)
book book
} }
} }
@ -94,14 +98,18 @@ class WebBook(val bookSource: BookSource) {
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<List<BookChapter>> { ): Coroutine<List<BookChapter>> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val body = if (book.bookUrl == book.tocUrl && book.tocHtml.isNullOrEmpty()) {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
book = book, book = book,
ruleUrl = book.tocUrl, ruleUrl = book.tocUrl,
baseUrl = book.bookUrl, baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val response = analyzeUrl.getResponseAsync().await() analyzeUrl.getResponseAsync().await().body()
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl) } else {
book.tocUrl
}
BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl)
} }
} }

@ -9,30 +9,23 @@ 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.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import retrofit2.Response
object BookChapterList { object BookChapterList {
suspend fun analyzeChapterList( suspend fun analyzeChapterList(
coroutineScope: CoroutineScope, coroutineScope: CoroutineScope,
book: Book, book: Book,
response: Response<String>, body: String?,
bookSource: BookSource, bookSource: BookSource,
analyzeUrl: AnalyzeUrl baseUrl: String
): List<BookChapter> { ): List<BookChapter> {
var chapterList = arrayListOf<BookChapter>() var chapterList = arrayListOf<BookChapter>()
val baseUrl: String = NetworkUtils.getUrl(response)
val body: String? = response.body()
body ?: throw Exception( body ?: throw Exception(
App.INSTANCE.getString( App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
R.string.error_get_web_content,
analyzeUrl.ruleUrl
) )
) SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
val tocRule = bookSource.getTocRule() val tocRule = bookSource.getTocRule()
val nextUrlList = arrayListOf(baseUrl) val nextUrlList = arrayListOf(baseUrl)
var reverse = false var reverse = false
@ -140,7 +133,7 @@ object BookChapterList {
val analyzeRule = AnalyzeRule(book) val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
if (getNextUrl) { if (getNextUrl) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录下一页列表", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录下一页列表", print = printLog)
analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let { analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let {
for (item in it) { for (item in it) {
if (item != baseUrl) { if (item != baseUrl) {
@ -150,16 +143,15 @@ object BookChapterList {
} }
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, bookSource.bookSourceUrl,
1,
TextUtils.join(",", nextUrlList), TextUtils.join(",", nextUrlList),
printLog print = printLog
) )
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "解析目录列表", print = printLog)
val elements = analyzeRule.getElements(listRule) val elements = analyzeRule.getElements(listRule)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "目录数${elements.size}", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "目录数${elements.size}", print = printLog)
if (elements.isNotEmpty()) { if (elements.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录", print = printLog)
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "") val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "")
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "") val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "")
for (item in elements) { for (item in elements) {
@ -175,9 +167,8 @@ object BookChapterList {
} }
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, bookSource.bookSourceUrl,
1,
"${chapterList[0].title}${chapterList[0].url}", "${chapterList[0].title}${chapterList[0].url}",
printLog print = printLog
) )
} }
return ChapterData(chapterList, nextUrlList) return ChapterData(chapterList, nextUrlList)

@ -34,7 +34,7 @@ object BookContent {
analyzeUrl.ruleUrl analyzeUrl.ruleUrl
) )
) )
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}") SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${analyzeUrl.ruleUrl}")
val content = StringBuilder() val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl) val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule() val contentRule = bookSource.getContentRule()

@ -5,7 +5,6 @@ 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.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.htmlFormat import io.legado.app.utils.htmlFormat
object BookInfo { object BookInfo {
@ -15,59 +14,58 @@ object BookInfo {
book: Book, book: Book,
body: String?, body: String?,
bookSource: BookSource, bookSource: BookSource,
analyzeUrl: AnalyzeUrl baseUrl: String
) { ) {
val baseUrl = analyzeUrl.ruleUrl
body ?: throw Exception( body ?: throw Exception(
App.INSTANCE.getString( App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
R.string.error_get_web_content,
analyzeUrl.ruleUrl
) )
) SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
val infoRule = bookSource.getBookInfoRule() val infoRule = bookSource.getBookInfoRule()
val analyzeRule = AnalyzeRule(book) val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
infoRule.init?.let { infoRule.init?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "执行详情页初始化规则") SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it)) analyzeRule.setContent(analyzeRule.getElement(it))
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名") SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
analyzeRule.getString(infoRule.name ?: "")?.let { analyzeRule.getString(infoRule.name ?: "")?.let {
if (it.isNotEmpty()) book.name = it if (it.isNotEmpty()) book.name = it
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.name) SourceDebug.printLog(bookSource.bookSourceUrl, book.name)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者") SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
analyzeRule.getString(infoRule.author ?: "")?.let { analyzeRule.getString(infoRule.author ?: "")?.let {
if (it.isNotEmpty()) book.author = it if (it.isNotEmpty()) book.author = it
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.author) SourceDebug.printLog(bookSource.bookSourceUrl, book.author)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类") SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
analyzeRule.getString(infoRule.kind ?: "")?.let { analyzeRule.getString(infoRule.kind ?: "")?.let {
if (it.isNotEmpty()) book.kind = it if (it.isNotEmpty()) book.kind = it
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.kind ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, book.kind)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介") SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介")
analyzeRule.getString(infoRule.intro ?: "")?.let { analyzeRule.getString(infoRule.intro ?: "")?.let {
if (it.isNotEmpty()) book.intro = it.htmlFormat() if (it.isNotEmpty()) book.intro = it.htmlFormat()
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.intro ?: "", isHtml = true) SourceDebug.printLog(bookSource.bookSourceUrl, book.intro, isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数") SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数")
analyzeRule.getString(infoRule.wordCount ?: "")?.let { analyzeRule.getString(infoRule.wordCount ?: "")?.let {
if (it.isNotEmpty()) book.wordCount = it if (it.isNotEmpty()) book.wordCount = it
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.wordCount ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, book.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节") SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
analyzeRule.getString(infoRule.lastChapter ?: "")?.let { analyzeRule.getString(infoRule.lastChapter ?: "")?.let {
if (it.isNotEmpty()) book.latestChapterTitle = it if (it.isNotEmpty()) book.latestChapterTitle = it
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.latestChapterTitle ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, book.latestChapterTitle)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录Url") SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录Url")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl ?: "", true) ?: baseUrl book.tocUrl = analyzeRule.getString(infoRule.tocUrl ?: "", true) ?: baseUrl
if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.tocUrl) if (book.tocUrl == baseUrl) {
book.tocHtml = body
}
SourceDebug.printLog(bookSource.bookSourceUrl, book.tocUrl)
} }
} }

@ -28,14 +28,14 @@ object BookList {
analyzeUrl.ruleUrl analyzeUrl.ruleUrl
) )
) )
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}") SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${analyzeUrl.ruleUrl}")
val analyzeRule = AnalyzeRule(null) val analyzeRule = AnalyzeRule(null)
analyzeRule.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let { bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) { if (baseUrl.matches(it.toRegex())) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "url为详情页") SourceDebug.printLog(bookSource.bookSourceUrl, "url为详情页")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body searchBook.infoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
return bookList return bookList
@ -56,12 +56,12 @@ object BookList {
if (ruleList.startsWith("+")) { if (ruleList.startsWith("+")) {
ruleList = ruleList.substring(1) ruleList = ruleList.substring(1)
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析书籍列表") SourceDebug.printLog(bookSource.bookSourceUrl, "解析书籍列表")
collections = analyzeRule.getElements(ruleList) collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表为空,按详情页解析") SourceDebug.printLog(bookSource.bookSourceUrl, "列表为空,按详情页解析")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body searchBook.infoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
} else { } else {
@ -73,7 +73,7 @@ object BookList {
val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind ?: "") val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind ?: "")
val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter ?: "") val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter ?: "")
val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount ?: "") val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表数为${collections.size}") SourceDebug.printLog(bookSource.bookSourceUrl, "列表数为${collections.size}")
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
getSearchItem( getSearchItem(
item, item,
@ -91,7 +91,7 @@ object BookList {
ruleWordCount = ruleWordCount ruleWordCount = ruleWordCount
)?.let { searchBook -> )?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) { if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body searchBook.infoHtml = body
} }
bookList.add(searchBook) bookList.add(searchBook)
} }
@ -117,38 +117,36 @@ object BookList {
with(bookSource.getBookInfoRule()) { with(bookSource.getBookInfoRule()) {
init?.let { init?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "执行详情页初始化规则") SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it)) analyzeRule.setContent(analyzeRule.getElement(it))
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名") SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
searchBook.name = analyzeRule.getString(name ?: "") ?: "" searchBook.name = analyzeRule.getString(name ?: "") ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name)
if (searchBook.name.isNotEmpty()) { if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者") SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: "")) searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: ""))
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.author) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类") SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
searchBook.kind = analyzeRule.getString(kind ?: "") searchBook.kind = analyzeRule.getString(kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介") SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "") searchBook.intro = analyzeRule.getString(intro ?: "")
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.intro bookSource.bookSourceUrl,
?: "", isHtml = true msg = searchBook.intro,
isHtml = true
) )
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数") SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount ?: "") searchBook.wordCount = analyzeRule.getString(wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取封面Url") SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true) searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节") SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "") searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "")
SourceDebug.printLog( SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.latestChapterTitle)
bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle
?: ""
)
return searchBook return searchBook
} }
} }
@ -176,36 +174,42 @@ object BookList {
searchBook.originOrder = bookSource.customOrder searchBook.originOrder = bookSource.customOrder
analyzeRule.setBook(searchBook) analyzeRule.setBook(searchBook)
analyzeRule.setContent(item) analyzeRule.setContent(item)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名", print = printLog)
searchBook.name = analyzeRule.getString(ruleName) searchBook.name = analyzeRule.getString(ruleName)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name, printLog) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name, print = printLog)
if (searchBook.name.isNotEmpty()) { if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书籍Url", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取书籍Url", print = printLog)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.bookUrl, printLog) if (searchBook.bookUrl.isEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者", printLog) searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.bookUrl, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者", print = printLog)
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor)) searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor))
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.author, printLog) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类", print = printLog)
searchBook.kind = analyzeRule.getString(ruleKind) searchBook.kind = analyzeRule.getString(ruleKind)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介", print = printLog)
searchBook.intro = analyzeRule.getString(ruleIntro) searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.intro bookSource.bookSourceUrl,
?: "", printLog, true searchBook.intro,
print = printLog,
isHtml = true
) )
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数", print = printLog)
searchBook.wordCount = analyzeRule.getString(ruleWordCount) searchBook.wordCount = analyzeRule.getString(ruleWordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取封面Url", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url", print = printLog)
searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl, true) searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节", print = printLog)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
SourceDebug.printLog( SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle bookSource.bookSourceUrl,
?: "", printLog searchBook.latestChapterTitle,
print = printLog
) )
return searchBook return searchBook
} }

@ -24,19 +24,20 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
@Synchronized @Synchronized
fun printLog( fun printLog(
sourceUrl: String?, sourceUrl: String?,
state: Int, msg: String?,
msg: String, state: Int = 1,
print: Boolean = true, print: Boolean = true,
isHtml: Boolean = false, isHtml: Boolean = false,
showTime: Boolean = true showTime: Boolean = true
) { ) {
if (debugSource != sourceUrl || callback == null || !print) return if (debugSource != sourceUrl || callback == null || !print) return
var printMsg = msg var printMsg = msg ?: ""
if (isHtml) { if (isHtml) {
printMsg = printMsg.htmlFormat() printMsg = printMsg.htmlFormat()
} }
if (showTime) { if (showTime) {
printMsg = "${DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime))} $printMsg" printMsg =
"${DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime))} $printMsg"
} }
callback?.printLog(state, printMsg) callback?.printLog(state, printMsg)
} }
@ -64,10 +65,10 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
val book = Book() val book = Book()
book.origin = webBook.sourceUrl book.origin = webBook.sourceUrl
book.bookUrl = key book.bookUrl = key
printLog(webBook.sourceUrl, 1, "开始访问$key") printLog(webBook.sourceUrl, "开始访问$key")
infoDebug(book) infoDebug(book)
} else { } else {
printLog(webBook.sourceUrl, 1, "开始搜索关键字$key") printLog(webBook.sourceUrl, "开始搜索关键字$key")
searchDebug(key) searchDebug(key)
} }
} }
@ -77,65 +78,65 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
.onSuccess { searchBooks -> .onSuccess { searchBooks ->
searchBooks?.let { searchBooks?.let {
if (searchBooks.isNotEmpty()) { if (searchBooks.isNotEmpty()) {
printLog(debugSource, 1, "搜索完成") printLog(debugSource, "搜索完成")
printLog(debugSource, 1, "", showTime = false) printLog(debugSource, "", showTime = false)
infoDebug(searchBooks[0].toBook()) infoDebug(searchBooks[0].toBook())
} else { } else {
printLog(debugSource, -1, "未获取到书籍") printLog(debugSource, "未获取到书籍", -1)
} }
} }
} }
.onError { .onError {
printLog(debugSource, -1, it.localizedMessage) printLog(debugSource, it.localizedMessage, -1)
} }
tasks.add(search) tasks.add(search)
} }
private fun infoDebug(book: Book) { private fun infoDebug(book: Book) {
printLog(debugSource, 1, "开始获取详情页") printLog(debugSource, "开始获取详情页")
val info = webBook.getBookInfo(book) val info = webBook.getBookInfo(book)
.onSuccess { .onSuccess {
printLog(debugSource, 1, "详情页完成") printLog(debugSource, "详情页完成")
printLog(debugSource, 1, "", showTime = false) printLog(debugSource, "", showTime = false)
tocDebug(book) tocDebug(book)
} }
.onError { .onError {
printLog(debugSource, -1, it.localizedMessage) printLog(debugSource, it.localizedMessage, -1)
} }
tasks.add(info) tasks.add(info)
} }
private fun tocDebug(book: Book) { private fun tocDebug(book: Book) {
printLog(debugSource, 1, "开始获取目录页") printLog(debugSource, "开始获取目录页")
val chapterList = webBook.getChapterList(book) val chapterList = webBook.getChapterList(book)
.onSuccess { chapterList -> .onSuccess { chapterList ->
chapterList?.let { chapterList?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
printLog(debugSource, 1, "目录完成") printLog(debugSource, "目录完成")
printLog(debugSource, 1, "", showTime = false) printLog(debugSource, "", showTime = false)
val nextChapterUrl = if (it.size > 1) it[1].url else null val nextChapterUrl = if (it.size > 1) it[1].url else null
contentDebug(book, it[0], nextChapterUrl) contentDebug(book, it[0], nextChapterUrl)
} else { } else {
printLog(debugSource, -1, "目录列表为空") printLog(debugSource, "目录列表为空", -1)
} }
} }
} }
.onError { .onError {
printLog(debugSource, -1, it.localizedMessage) printLog(debugSource, it.localizedMessage, -1)
} }
tasks.add(chapterList) tasks.add(chapterList)
} }
private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) { private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) {
printLog(debugSource, 1, "开始获取内容") printLog(debugSource, "开始获取内容")
val content = webBook.getContent(book, bookChapter, nextChapterUrl) val content = webBook.getContent(book, bookChapter, nextChapterUrl)
.onSuccess { content -> .onSuccess { content ->
content?.let { content?.let {
printLog(debugSource, 1000, it) printLog(debugSource, it, 1000)
} }
} }
.onError { .onError {
printLog(debugSource, -1, it.localizedMessage) printLog(debugSource, it.localizedMessage, -1)
} }
tasks.add(content) tasks.add(content)
} }

Loading…
Cancel
Save