pull/38/head
kunfei 5 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. 40
      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 wordCount: String?
var infoHtml: String?
var tocHtml: String?
fun putVariable(key: String, value: String)
fun getKindList(): List<String> {

@ -47,10 +47,18 @@ data class Book(
var useReplaceRule: Boolean = true, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable, BaseBook {
@IgnoredOnParcel
@Ignore
@IgnoredOnParcel
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 getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl
@ -77,6 +85,9 @@ data class Book(
tocUrl = tocUrl,
originOrder = originOrder,
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 time: Long = System.currentTimeMillis(),
var variable: String? = null,
var bookInfoHtml: String? = null,
var originOrder: Int = 0
) : Parcelable, BaseBook, Comparable<SearchBook> {
@Ignore
@IgnoredOnParcel
override var infoHtml: String? = null
@Ignore
@IgnoredOnParcel
override var tocHtml: String? = null
override fun equals(other: Any?): Boolean {
if (other is SearchBook) {
if (other.bookUrl == bookUrl) {
@ -72,6 +79,9 @@ data class SearchBook(
tocUrl = tocUrl,
originOrder = originOrder,
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
): Coroutine<Book> {
return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.bookUrl,
baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl)
val body = if (book.infoHtml.isNullOrEmpty()) {
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.bookUrl,
baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap()
)
analyzeUrl.getResponseAsync().await().body()
} else {
book.infoHtml
}
BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl)
book
}
}
@ -94,14 +98,18 @@ class WebBook(val bookSource: BookSource) {
context: CoroutineContext = Dispatchers.IO
): Coroutine<List<BookChapter>> {
return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.tocUrl,
baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl)
val body = if (book.bookUrl == book.tocUrl && book.tocHtml.isNullOrEmpty()) {
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.tocUrl,
baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap()
)
analyzeUrl.getResponseAsync().await().body()
} 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.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext
import retrofit2.Response
object BookChapterList {
suspend fun analyzeChapterList(
coroutineScope: CoroutineScope,
book: Book,
response: Response<String>,
body: String?,
bookSource: BookSource,
analyzeUrl: AnalyzeUrl
baseUrl: String
): List<BookChapter> {
var chapterList = arrayListOf<BookChapter>()
val baseUrl: String = NetworkUtils.getUrl(response)
val body: String? = response.body()
body ?: throw Exception(
App.INSTANCE.getString(
R.string.error_get_web_content,
analyzeUrl.ruleUrl
)
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
val tocRule = bookSource.getTocRule()
val nextUrlList = arrayListOf(baseUrl)
var reverse = false
@ -140,7 +133,7 @@ object BookChapterList {
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl)
if (getNextUrl) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录下一页列表", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录下一页列表", print = printLog)
analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let {
for (item in it) {
if (item != baseUrl) {
@ -150,16 +143,15 @@ object BookChapterList {
}
SourceDebug.printLog(
bookSource.bookSourceUrl,
1,
TextUtils.join(",", nextUrlList),
printLog
print = printLog
)
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "解析目录列表", print = printLog)
val elements = analyzeRule.getElements(listRule)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "目录数${elements.size}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "目录数${elements.size}", print = printLog)
if (elements.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录", print = printLog)
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "")
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "")
for (item in elements) {
@ -175,9 +167,8 @@ object BookChapterList {
}
SourceDebug.printLog(
bookSource.bookSourceUrl,
1,
"${chapterList[0].title}${chapterList[0].url}",
printLog
print = printLog
)
}
return ChapterData(chapterList, nextUrlList)

@ -34,7 +34,7 @@ object BookContent {
analyzeUrl.ruleUrl
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${analyzeUrl.ruleUrl}")
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl)
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.BookSource
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.htmlFormat
object BookInfo {
@ -15,59 +14,58 @@ object BookInfo {
book: Book,
body: String?,
bookSource: BookSource,
analyzeUrl: AnalyzeUrl
baseUrl: String
) {
val baseUrl = analyzeUrl.ruleUrl
body ?: throw Exception(
App.INSTANCE.getString(
R.string.error_get_web_content,
analyzeUrl.ruleUrl
)
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
val infoRule = bookSource.getBookInfoRule()
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl)
infoRule.init?.let {
if (it.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "执行详情页初始化规则")
SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
analyzeRule.getString(infoRule.name ?: "")?.let {
if (it.isNotEmpty()) book.name = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.name)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者")
SourceDebug.printLog(bookSource.bookSourceUrl, book.name)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
analyzeRule.getString(infoRule.author ?: "")?.let {
if (it.isNotEmpty()) book.author = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.author)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类")
SourceDebug.printLog(bookSource.bookSourceUrl, book.author)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
analyzeRule.getString(infoRule.kind ?: "")?.let {
if (it.isNotEmpty()) book.kind = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介")
SourceDebug.printLog(bookSource.bookSourceUrl, book.kind)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介")
analyzeRule.getString(infoRule.intro ?: "")?.let {
if (it.isNotEmpty()) book.intro = it.htmlFormat()
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.intro ?: "", isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数")
SourceDebug.printLog(bookSource.bookSourceUrl, book.intro, isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数")
analyzeRule.getString(infoRule.wordCount ?: "")?.let {
if (it.isNotEmpty()) book.wordCount = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节")
SourceDebug.printLog(bookSource.bookSourceUrl, book.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
analyzeRule.getString(infoRule.lastChapter ?: "")?.let {
if (it.isNotEmpty()) book.latestChapterTitle = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, book.latestChapterTitle ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录Url")
SourceDebug.printLog(bookSource.bookSourceUrl, book.latestChapterTitle)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录Url")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl ?: "", true) ?: 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
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:${analyzeUrl.ruleUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${analyzeUrl.ruleUrl}")
val analyzeRule = AnalyzeRule(null)
analyzeRule.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "url为详情页")
SourceDebug.printLog(bookSource.bookSourceUrl, "url为详情页")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body
searchBook.infoHtml = body
bookList.add(searchBook)
}
return bookList
@ -56,12 +56,12 @@ object BookList {
if (ruleList.startsWith("+")) {
ruleList = ruleList.substring(1)
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析书籍列表")
SourceDebug.printLog(bookSource.bookSourceUrl, "解析书籍列表")
collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表为空,按详情页解析")
SourceDebug.printLog(bookSource.bookSourceUrl, "列表为空,按详情页解析")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body
searchBook.infoHtml = body
bookList.add(searchBook)
}
} else {
@ -73,7 +73,7 @@ object BookList {
val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind ?: "")
val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter ?: "")
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()) {
getSearchItem(
item,
@ -91,7 +91,7 @@ object BookList {
ruleWordCount = ruleWordCount
)?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body
searchBook.infoHtml = body
}
bookList.add(searchBook)
}
@ -117,38 +117,36 @@ object BookList {
with(bookSource.getBookInfoRule()) {
init?.let {
if (it.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "执行详情页初始化规则")
SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
searchBook.name = analyzeRule.getString(name ?: "") ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.name)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name)
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: ""))
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.author)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
searchBook.kind = analyzeRule.getString(kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "")
SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.intro
?: "", isHtml = true
bookSource.bookSourceUrl,
msg = searchBook.intro,
isHtml = true
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取封面Url")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "")
SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle
?: ""
)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.latestChapterTitle)
return searchBook
}
}
@ -176,36 +174,42 @@ object BookList {
searchBook.originOrder = bookSource.customOrder
analyzeRule.setBook(searchBook)
analyzeRule.setContent(item)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书名", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名", print = printLog)
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()) {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取书籍Url", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书籍Url", print = printLog)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.bookUrl, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取作者", printLog)
if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.bookUrl, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者", print = printLog)
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor))
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.author, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取分类", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类", print = printLog)
searchBook.kind = analyzeRule.getString(ruleKind)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介", print = printLog)
searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.intro
?: "", printLog, true
bookSource.bookSourceUrl,
searchBook.intro,
print = printLog,
isHtml = true
)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数", print = printLog)
searchBook.wordCount = analyzeRule.getString(ruleWordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取封面Url", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url", print = printLog)
searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl, print = printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节", print = printLog)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
SourceDebug.printLog(
bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle
?: "", printLog
bookSource.bookSourceUrl,
searchBook.latestChapterTitle,
print = printLog
)
return searchBook
}

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

Loading…
Cancel
Save