|
|
@ -3,6 +3,7 @@ package io.legado.app.model |
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.annotation.SuppressLint |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
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.RssSource |
|
|
|
import io.legado.app.help.coroutine.CompositeCoroutine |
|
|
|
import io.legado.app.help.coroutine.CompositeCoroutine |
|
|
|
import io.legado.app.utils.htmlFormat |
|
|
|
import io.legado.app.utils.htmlFormat |
|
|
|
import io.legado.app.utils.isAbsUrl |
|
|
|
import io.legado.app.utils.isAbsUrl |
|
|
@ -21,7 +22,7 @@ object SourceDebug { |
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
fun printLog( |
|
|
|
fun printLog( |
|
|
|
sourceUrl: String?, |
|
|
|
sourceUrl: String?, |
|
|
|
msg: String?, |
|
|
|
msg: String? = "", |
|
|
|
print: Boolean = true, |
|
|
|
print: Boolean = true, |
|
|
|
isHtml: Boolean = false, |
|
|
|
isHtml: Boolean = false, |
|
|
|
showTime: Boolean = true, |
|
|
|
showTime: Boolean = true, |
|
|
@ -48,6 +49,16 @@ object SourceDebug { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun startDebug(rssSource: RssSource) { |
|
|
|
|
|
|
|
Rss.getArticles(rssSource) |
|
|
|
|
|
|
|
.onSuccess { |
|
|
|
|
|
|
|
printLog(debugSource, "︽正文页解析完成", state = 1000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.onError { |
|
|
|
|
|
|
|
printLog(debugSource, it.localizedMessage, state = -1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun startDebug(webBook: WebBook, key: String) { |
|
|
|
fun startDebug(webBook: WebBook, key: String) { |
|
|
|
cancelDebug() |
|
|
|
cancelDebug() |
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
startTime = System.currentTimeMillis() |
|
|
@ -56,58 +67,32 @@ object SourceDebug { |
|
|
|
val book = Book() |
|
|
|
val book = Book() |
|
|
|
book.origin = webBook.sourceUrl |
|
|
|
book.origin = webBook.sourceUrl |
|
|
|
book.bookUrl = key |
|
|
|
book.bookUrl = key |
|
|
|
printLog( |
|
|
|
printLog(webBook.sourceUrl, "⇒开始访问详情页:$key") |
|
|
|
webBook.sourceUrl, |
|
|
|
|
|
|
|
"⇒开始访问详情页:$key" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
infoDebug(webBook, book) |
|
|
|
infoDebug(webBook, book) |
|
|
|
} |
|
|
|
} |
|
|
|
key.contains("::") -> { |
|
|
|
key.contains("::") -> { |
|
|
|
val url = key.substring(key.indexOf("::") + 2) |
|
|
|
val url = key.substring(key.indexOf("::") + 2) |
|
|
|
printLog( |
|
|
|
printLog(webBook.sourceUrl, "⇒开始访问发现页:$url") |
|
|
|
webBook.sourceUrl, |
|
|
|
|
|
|
|
"⇒开始访问发现页:$url" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
exploreDebug(webBook, url) |
|
|
|
exploreDebug(webBook, url) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
printLog( |
|
|
|
printLog(webBook.sourceUrl, "⇒开始搜索关键字:$key") |
|
|
|
webBook.sourceUrl, |
|
|
|
|
|
|
|
"⇒开始搜索关键字:$key" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
searchDebug(webBook, key) |
|
|
|
searchDebug(webBook, key) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun exploreDebug(webBook: WebBook, url: String) { |
|
|
|
private fun exploreDebug(webBook: WebBook, url: String) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︾开始解析发现页") |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︾开始解析发现页" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
val explore = webBook.exploreBook(url, 1) |
|
|
|
val explore = webBook.exploreBook(url, 1) |
|
|
|
.onSuccess { exploreBooks -> |
|
|
|
.onSuccess { exploreBooks -> |
|
|
|
exploreBooks?.let { |
|
|
|
exploreBooks?.let { |
|
|
|
if (exploreBooks.isNotEmpty()) { |
|
|
|
if (exploreBooks.isNotEmpty()) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽发现页解析完成") |
|
|
|
debugSource, |
|
|
|
printLog(debugSource, showTime = false) |
|
|
|
"︽发现页解析完成" |
|
|
|
infoDebug(webBook, exploreBooks[0].toBook()) |
|
|
|
) |
|
|
|
|
|
|
|
printLog( |
|
|
|
|
|
|
|
debugSource, |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
showTime = false |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
infoDebug( |
|
|
|
|
|
|
|
webBook, |
|
|
|
|
|
|
|
exploreBooks[0].toBook() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽未获取到书籍", state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︽未获取到书籍", |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -122,114 +107,56 @@ object SourceDebug { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun searchDebug(webBook: WebBook, key: String) { |
|
|
|
private fun searchDebug(webBook: WebBook, key: String) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︾开始解析搜索页") |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︾开始解析搜索页" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
val search = webBook.searchBook(key, 1) |
|
|
|
val search = webBook.searchBook(key, 1) |
|
|
|
.onSuccess { searchBooks -> |
|
|
|
.onSuccess { searchBooks -> |
|
|
|
searchBooks?.let { |
|
|
|
searchBooks?.let { |
|
|
|
if (searchBooks.isNotEmpty()) { |
|
|
|
if (searchBooks.isNotEmpty()) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽搜索页解析完成") |
|
|
|
debugSource, |
|
|
|
printLog(debugSource, showTime = false) |
|
|
|
"︽搜索页解析完成" |
|
|
|
infoDebug(webBook, searchBooks[0].toBook()) |
|
|
|
) |
|
|
|
|
|
|
|
printLog( |
|
|
|
|
|
|
|
debugSource, |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
showTime = false |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
infoDebug( |
|
|
|
|
|
|
|
webBook, |
|
|
|
|
|
|
|
searchBooks[0].toBook() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽未获取到书籍", state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︽未获取到书籍", |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, it.localizedMessage, state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
it.localizedMessage, |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tasks.add(search) |
|
|
|
tasks.add(search) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun infoDebug(webBook: WebBook, book: Book) { |
|
|
|
private fun infoDebug(webBook: WebBook, book: Book) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︾开始解析详情页") |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︾开始解析详情页" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
val info = webBook.getBookInfo(book) |
|
|
|
val info = webBook.getBookInfo(book) |
|
|
|
.onSuccess { |
|
|
|
.onSuccess { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽详情页解析完成") |
|
|
|
debugSource, |
|
|
|
printLog(debugSource, showTime = false) |
|
|
|
"︽详情页解析完成" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
printLog( |
|
|
|
|
|
|
|
debugSource, |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
showTime = false |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
tocDebug(webBook, book) |
|
|
|
tocDebug(webBook, book) |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, it.localizedMessage, state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
it.localizedMessage, |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tasks.add(info) |
|
|
|
tasks.add(info) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun tocDebug(webBook: WebBook, book: Book) { |
|
|
|
private fun tocDebug(webBook: WebBook, book: Book) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︾开始解析目录页") |
|
|
|
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( |
|
|
|
printLog(debugSource, "︽目录页解析完成") |
|
|
|
debugSource, |
|
|
|
printLog(debugSource, 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( |
|
|
|
contentDebug(webBook, book, it[0], nextChapterUrl) |
|
|
|
webBook, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
it[0], |
|
|
|
|
|
|
|
nextChapterUrl |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽目录列表为空", state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︽目录列表为空", |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, it.localizedMessage, state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
it.localizedMessage, |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tasks.add(chapterList) |
|
|
|
tasks.add(chapterList) |
|
|
|
} |
|
|
|
} |
|
|
@ -240,24 +167,13 @@ object SourceDebug { |
|
|
|
bookChapter: BookChapter, |
|
|
|
bookChapter: BookChapter, |
|
|
|
nextChapterUrl: String? |
|
|
|
nextChapterUrl: String? |
|
|
|
) { |
|
|
|
) { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︾开始解析正文页") |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︾开始解析正文页" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
val content = webBook.getContent(book, bookChapter, nextChapterUrl) |
|
|
|
val content = webBook.getContent(book, bookChapter, nextChapterUrl) |
|
|
|
.onSuccess { |
|
|
|
.onSuccess { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, "︽正文页解析完成", state = 1000) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
"︽正文页解析完成", |
|
|
|
|
|
|
|
state = 1000 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
printLog( |
|
|
|
printLog(debugSource, it.localizedMessage, state = -1) |
|
|
|
debugSource, |
|
|
|
|
|
|
|
it.localizedMessage, |
|
|
|
|
|
|
|
state = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tasks.add(content) |
|
|
|
tasks.add(content) |
|
|
|
} |
|
|
|
} |
|
|
|