pull/49/head
kunfei 5 years ago
parent 3275404818
commit 516ba657e5
  1. 60
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 12
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 22
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  4. 18
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  5. 40
      app/src/main/java/io/legado/app/model/webbook/BookInfo.kt
  6. 76
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  7. 10
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt
  8. 10
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt
  9. 14
      app/src/main/java/io/legado/app/web/controller/SourceDebugWebSocket.kt

@ -10,7 +10,7 @@ import io.legado.app.utils.isAbsUrl
import java.text.SimpleDateFormat
import java.util.*
object SourceDebug {
object Debug {
private var debugSource: String? = null
var callback: Callback? = null
private val tasks: CompositeCoroutine = CompositeCoroutine()
@ -20,7 +20,7 @@ object SourceDebug {
private var startTime: Long = System.currentTimeMillis()
@Synchronized
fun printLog(
fun log(
sourceUrl: String?,
msg: String? = "",
print: Boolean = true,
@ -52,13 +52,13 @@ object SourceDebug {
fun startDebug(rssSource: RssSource) {
cancelDebug()
debugSource = rssSource.sourceUrl
printLog(debugSource, "︾开始解析RSS")
log(debugSource, "︾开始解析RSS")
Rss.getArticles(rssSource)
.onSuccess {
printLog(debugSource, "︽正文页解析完成", state = 1000)
log(debugSource, "︽正文页解析完成", state = 1000)
}
.onError {
printLog(debugSource, it.localizedMessage, state = -1)
log(debugSource, it.localizedMessage, state = -1)
}
}
@ -71,37 +71,37 @@ object SourceDebug {
val book = Book()
book.origin = webBook.sourceUrl
book.bookUrl = key
printLog(webBook.sourceUrl, "⇒开始访问详情页:$key")
log(webBook.sourceUrl, "⇒开始访问详情页:$key")
infoDebug(webBook, book)
}
key.contains("::") -> {
val url = key.substring(key.indexOf("::") + 2)
printLog(webBook.sourceUrl, "⇒开始访问发现页:$url")
log(webBook.sourceUrl, "⇒开始访问发现页:$url")
exploreDebug(webBook, url)
}
else -> {
printLog(webBook.sourceUrl, "⇒开始搜索关键字:$key")
log(webBook.sourceUrl, "⇒开始搜索关键字:$key")
searchDebug(webBook, key)
}
}
}
private fun exploreDebug(webBook: WebBook, url: String) {
printLog(debugSource, "︾开始解析发现页")
log(debugSource, "︾开始解析发现页")
val explore = webBook.exploreBook(url, 1)
.onSuccess { exploreBooks ->
exploreBooks?.let {
if (exploreBooks.isNotEmpty()) {
printLog(debugSource, "︽发现页解析完成")
printLog(debugSource, showTime = false)
log(debugSource, "︽发现页解析完成")
log(debugSource, showTime = false)
infoDebug(webBook, exploreBooks[0].toBook())
} else {
printLog(debugSource, "︽未获取到书籍", state = -1)
log(debugSource, "︽未获取到书籍", state = -1)
}
}
}
.onError {
printLog(
log(
debugSource,
it.localizedMessage,
state = -1
@ -111,56 +111,56 @@ object SourceDebug {
}
private fun searchDebug(webBook: WebBook, key: String) {
printLog(debugSource, "︾开始解析搜索页")
log(debugSource, "︾开始解析搜索页")
val search = webBook.searchBook(key, 1)
.onSuccess { searchBooks ->
searchBooks?.let {
if (searchBooks.isNotEmpty()) {
printLog(debugSource, "︽搜索页解析完成")
printLog(debugSource, showTime = false)
log(debugSource, "︽搜索页解析完成")
log(debugSource, showTime = false)
infoDebug(webBook, searchBooks[0].toBook())
} else {
printLog(debugSource, "︽未获取到书籍", state = -1)
log(debugSource, "︽未获取到书籍", state = -1)
}
}
}
.onError {
printLog(debugSource, it.localizedMessage, state = -1)
log(debugSource, it.localizedMessage, state = -1)
}
tasks.add(search)
}
private fun infoDebug(webBook: WebBook, book: Book) {
printLog(debugSource, "︾开始解析详情页")
log(debugSource, "︾开始解析详情页")
val info = webBook.getBookInfo(book)
.onSuccess {
printLog(debugSource, "︽详情页解析完成")
printLog(debugSource, showTime = false)
log(debugSource, "︽详情页解析完成")
log(debugSource, showTime = false)
tocDebug(webBook, book)
}
.onError {
printLog(debugSource, it.localizedMessage, state = -1)
log(debugSource, it.localizedMessage, state = -1)
}
tasks.add(info)
}
private fun tocDebug(webBook: WebBook, book: Book) {
printLog(debugSource, "︾开始解析目录页")
log(debugSource, "︾开始解析目录页")
val chapterList = webBook.getChapterList(book)
.onSuccess { chapterList ->
chapterList?.let {
if (it.isNotEmpty()) {
printLog(debugSource, "︽目录页解析完成")
printLog(debugSource, showTime = false)
log(debugSource, "︽目录页解析完成")
log(debugSource, showTime = false)
val nextChapterUrl = if (it.size > 1) it[1].url else null
contentDebug(webBook, book, it[0], nextChapterUrl)
} else {
printLog(debugSource, "︽目录列表为空", state = -1)
log(debugSource, "︽目录列表为空", state = -1)
}
}
}
.onError {
printLog(debugSource, it.localizedMessage, state = -1)
log(debugSource, it.localizedMessage, state = -1)
}
tasks.add(chapterList)
}
@ -171,13 +171,13 @@ object SourceDebug {
bookChapter: BookChapter,
nextChapterUrl: String?
) {
printLog(debugSource, "︾开始解析正文页")
log(debugSource, "︾开始解析正文页")
val content = webBook.getContent(book, bookChapter, nextChapterUrl)
.onSuccess {
printLog(debugSource, "︽正文页解析完成", state = 1000)
log(debugSource, "︽正文页解析完成", state = 1000)
}
.onError {
printLog(debugSource, it.localizedMessage, state = -1)
log(debugSource, it.localizedMessage, state = -1)
}
tasks.add(content)
}

@ -4,12 +4,14 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
object RssParserByRule {
@Throws(Exception::class)
fun parseXML(body: String?, rssSource: RssSource): MutableList<RssArticle> {
val sourceUrl = rssSource.sourceUrl
if (body.isNullOrBlank()) {
throw Exception(
App.INSTANCE.getString(
@ -18,8 +20,10 @@ object RssParserByRule {
)
)
}
Debug.log(sourceUrl, "≡获取成功:$sourceUrl")
var ruleArticles = rssSource.ruleArticles
if (ruleArticles.isNullOrBlank()) {
Debug.log(sourceUrl, "列表规则为空, 使用默认规则解析")
return RssParser.parseXML(body, rssSource.sourceUrl)
} else {
val articleList = mutableListOf<RssArticle>()
@ -30,7 +34,9 @@ object RssParserByRule {
reverse = false
ruleArticles = ruleArticles.substring(1)
}
Debug.log(sourceUrl, "┌获取列表")
val collections = analyzeRule.getElements(ruleArticles)
Debug.log(sourceUrl, "└列表大小:${collections.size}")
val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "")
val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "")
val ruleCategories = analyzeRule.splitSourceRule(rssSource.ruleCategories ?: "")
@ -39,6 +45,7 @@ object RssParserByRule {
val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink ?: "")
for ((index, item) in collections.withIndex()) {
getItem(
sourceUrl,
item,
analyzeRule,
index == 0,
@ -64,9 +71,10 @@ object RssParserByRule {
}
private fun getItem(
sourceUrl: String,
item: Any,
analyzeRule: AnalyzeRule,
printLog: Boolean,
log: Boolean,
ruleTitle: List<AnalyzeRule.SourceRule>,
rulePubDate: List<AnalyzeRule.SourceRule>,
ruleCategories: List<AnalyzeRule.SourceRule>,
@ -76,7 +84,9 @@ object RssParserByRule {
): RssArticle? {
val rssArticle = RssArticle()
analyzeRule.setContent(item)
Debug.log(sourceUrl, "┌获取标题", log)
rssArticle.title = analyzeRule.getString(ruleTitle)
Debug.log(sourceUrl, "${rssArticle.title}", log)
rssArticle.pubDate = analyzeRule.getString(rulePubDate)
rssArticle.categories = analyzeRule.getString(ruleCategories)
rssArticle.description = analyzeRule.getString(ruleDescription)

@ -7,7 +7,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.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope
@ -26,7 +26,7 @@ object BookChapterList {
body ?: throw Exception(
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
val tocRule = bookSource.getTocRule()
val nextUrlList = arrayListOf(baseUrl)
var reverse = false
@ -70,7 +70,7 @@ object BookChapterList {
}
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "◇目录总页数:${nextUrlList.size}")
Debug.log(bookSource.bookSourceUrl, "◇目录总页数:${nextUrlList.size}")
} else if (chapterData.nextUrl.size > 1) {
val chapterDataList = arrayListOf<ChapterData<String>>()
for (item in chapterData.nextUrl) {
@ -136,7 +136,7 @@ object BookChapterList {
analyzeRule.setContent(body, baseUrl)
val nextTocRule = tocRule.nextTocUrl
if (getNextUrl && !nextTocRule.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录下一页列表", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", printLog)
analyzeRule.getStringList(nextTocRule, true)?.let {
for (item in it) {
if (item != baseUrl) {
@ -144,17 +144,17 @@ object BookChapterList {
}
}
}
SourceDebug.printLog(
Debug.log(
bookSource.bookSourceUrl,
"" + TextUtils.join("\n", nextUrlList),
printLog
)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录列表", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取目录列表", printLog)
val elements = analyzeRule.getElements(listRule)
SourceDebug.printLog(bookSource.bookSourceUrl, "└列表大小:${elements.size}", printLog)
Debug.log(bookSource.bookSourceUrl, "└列表大小:${elements.size}", printLog)
if (elements.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取首章名称", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取首章名称", printLog)
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName)
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl)
val vipRule = analyzeRule.splitSourceRule(tocRule.isVip)
@ -176,9 +176,9 @@ object BookChapterList {
chapterList.add(bookChapter)
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${chapterList[0].title}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取首章链接", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${chapterList[0].url}", printLog)
Debug.log(bookSource.bookSourceUrl, "${chapterList[0].title}", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取首章链接", printLog)
Debug.log(bookSource.bookSourceUrl, "${chapterList[0].url}", printLog)
}
return ChapterData(chapterList, nextUrlList)
}

@ -6,7 +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.ContentRule
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
@ -32,7 +32,7 @@ object BookContent {
baseUrl
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
@ -71,7 +71,7 @@ object BookContent {
content.append(contentData.content)
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
} else if (contentData.nextUrl.size > 1) {
val contentDataList = arrayListOf<ContentData<String>>()
for (item in contentData.nextUrl) {
@ -104,10 +104,10 @@ object BookContent {
content.append(item.content)
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取章节名称")
SourceDebug.printLog(bookSource.bookSourceUrl, "${bookChapter.title}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取正文内容")
SourceDebug.printLog(bookSource.bookSourceUrl, "\n$content")
Debug.log(bookSource.bookSourceUrl, "┌获取章节名称")
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")
Debug.log(bookSource.bookSourceUrl, "┌获取正文内容")
Debug.log(bookSource.bookSourceUrl, "\n$content")
return content.toString()
}
@ -127,11 +127,11 @@ object BookContent {
analyzeRule.chapter = chapter
val nextUrlRule = contentRule.nextContentUrl
if (!nextUrlRule.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog)
analyzeRule.getStringList(nextUrlRule, true)?.let {
nextUrlList.addAll(it)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog)
Debug.log(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog)
}
val content = analyzeRule.getString(contentRule.content).htmlFormat()
return ContentData(content, nextUrlList)

@ -4,7 +4,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.htmlFormat
@ -21,59 +21,59 @@ object BookInfo {
body ?: throw Exception(
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
Debug.log(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, "≡执行详情页初始化规则")
Debug.log(bookSource.bookSourceUrl, "≡执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名")
Debug.log(bookSource.bookSourceUrl, "┌获取书名")
analyzeRule.getString(infoRule.name).let {
if (it.isNotEmpty()) book.name = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.name}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者")
Debug.log(bookSource.bookSourceUrl, "${book.name}")
Debug.log(bookSource.bookSourceUrl, "┌获取作者")
analyzeRule.getString(infoRule.author).let {
if (it.isNotEmpty()) book.author = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.author}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类")
Debug.log(bookSource.bookSourceUrl, "${book.author}")
Debug.log(bookSource.bookSourceUrl, "┌获取分类")
analyzeRule.getString(infoRule.kind).let {
if (it.isNotEmpty()) book.kind = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数")
Debug.log(bookSource.bookSourceUrl, "${book.kind}")
Debug.log(bookSource.bookSourceUrl, "┌获取字数")
analyzeRule.getString(infoRule.wordCount).let {
if (it.isNotEmpty()) book.wordCount = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.wordCount}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节")
Debug.log(bookSource.bookSourceUrl, "${book.wordCount}")
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
analyzeRule.getString(infoRule.lastChapter).let {
if (it.isNotEmpty()) book.latestChapterTitle = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介")
Debug.log(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
Debug.log(bookSource.bookSourceUrl, "┌获取简介")
analyzeRule.getString(infoRule.intro).let {
if (it.isNotEmpty()) book.intro = it.htmlFormat()
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.intro}", isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接")
Debug.log(bookSource.bookSourceUrl, "${book.intro}", isHtml = true)
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.coverUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录链接")
Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}")
Debug.log(bookSource.bookSourceUrl, "┌获取目录链接")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) ?: baseUrl
if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl
if (book.tocUrl == baseUrl) {
book.tocHtml = body
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.tocUrl}")
Debug.log(bookSource.bookSourceUrl, "${book.tocUrl}")
}
}

@ -5,7 +5,7 @@ import io.legado.app.R
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.BookHelp
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
@ -27,12 +27,12 @@ object BookList {
analyzeUrl.ruleUrl
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
val analyzeRule = AnalyzeRule(null)
analyzeRule.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) {
SourceDebug.printLog(bookSource.bookSourceUrl, "≡链接为详情页")
Debug.log(bookSource.bookSourceUrl, "≡链接为详情页")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.infoHtml = body
bookList.add(searchBook)
@ -55,10 +55,10 @@ object BookList {
if (ruleList.startsWith("+")) {
ruleList = ruleList.substring(1)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书籍列表")
Debug.log(bookSource.bookSourceUrl, "┌获取书籍列表")
collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "└列表为空,按详情页解析")
Debug.log(bookSource.bookSourceUrl, "└列表为空,按详情页解析")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.infoHtml = body
bookList.add(searchBook)
@ -72,7 +72,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, "└列表大小:${collections.size}")
Debug.log(bookSource.bookSourceUrl, "└列表大小:${collections.size}")
for ((index, item) in collections.withIndex()) {
getSearchItem(
item,
@ -117,32 +117,32 @@ object BookList {
with(bookSource.getBookInfoRule()) {
init?.let {
if (it.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "≡执行详情页初始化规则")
Debug.log(bookSource.bookSourceUrl, "≡执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名")
Debug.log(bookSource.bookSourceUrl, "┌获取书名")
searchBook.name = analyzeRule.getString(name)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}")
Debug.log(bookSource.bookSourceUrl, "${searchBook.name}")
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者")
Debug.log(bookSource.bookSourceUrl, "┌获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author))
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类")
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}")
Debug.log(bookSource.bookSourceUrl, "┌获取分类")
searchBook.kind = analyzeRule.getString(kind)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数")
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}")
Debug.log(bookSource.bookSourceUrl, "┌获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节")
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}")
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介")
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}")
Debug.log(bookSource.bookSourceUrl, "┌获取简介")
searchBook.intro = analyzeRule.getString(intro)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接")
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}", true)
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
searchBook.coverUrl = analyzeRule.getString(coverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}")
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}")
return searchBook
}
}
@ -154,7 +154,7 @@ object BookList {
analyzeRule: AnalyzeRule,
bookSource: BookSource,
baseUrl: String,
printLog: Boolean,
log: Boolean,
ruleName: List<AnalyzeRule.SourceRule>,
ruleBookUrl: List<AnalyzeRule.SourceRule>,
ruleAuthor: List<AnalyzeRule.SourceRule>,
@ -171,36 +171,36 @@ object BookList {
searchBook.originOrder = bookSource.customOrder
analyzeRule.book = searchBook
analyzeRule.setContent(item)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取书名", log)
searchBook.name = analyzeRule.getString(ruleName)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.name}", log)
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者", printLog)
Debug.log(bookSource.bookSourceUrl, "┌获取作者", log)
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor))
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}", log)
Debug.log(bookSource.bookSourceUrl, "┌获取分类", log)
searchBook.kind = analyzeRule.getString(ruleKind)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}", log)
Debug.log(bookSource.bookSourceUrl, "┌获取字数", log)
searchBook.wordCount = analyzeRule.getString(ruleWordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}", log)
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", log)
Debug.log(bookSource.bookSourceUrl, "┌获取简介", log)
searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", printLog, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}", log, true)
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
analyzeRule.getString(ruleCoverUrl).let {
if (it.isNotEmpty()) searchBook.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取详情页链接", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", log)
Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)
if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.bookUrl}", printLog)
Debug.log(bookSource.bookSourceUrl, "${searchBook.bookUrl}", log)
return searchBook
}
return null

@ -3,11 +3,11 @@ package io.legado.app.ui.book.source.debug
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.WebBook
class BookSourceDebugModel(application: Application) : BaseViewModel(application),
SourceDebug.Callback {
Debug.Callback {
private var webBook: WebBook? = null
@ -30,8 +30,8 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application
fun startDebug(key: String, start: (() -> Unit)? = null, error: (() -> Unit)? = null) {
webBook?.let {
start?.invoke()
SourceDebug.callback = this
SourceDebug.startDebug(it, key)
Debug.callback = this
Debug.startDebug(it, key)
} ?: error?.invoke()
}
@ -41,7 +41,7 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application
override fun onCleared() {
super.onCleared()
SourceDebug.cancelDebug(true)
Debug.cancelDebug(true)
}
}

@ -4,10 +4,10 @@ import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
class RssSourceDebugModel(application: Application) : BaseViewModel(application),
SourceDebug.Callback {
Debug.Callback {
private var rssSource: RssSource? = null
@ -30,8 +30,8 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
fun startDebug(start: (() -> Unit)? = null, error: (() -> Unit)? = null) {
rssSource?.let {
start?.invoke()
SourceDebug.callback = this
SourceDebug.startDebug(it)
Debug.callback = this
Debug.startDebug(it)
} ?: error?.invoke()
}
@ -41,7 +41,7 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
override fun onCleared() {
super.onCleared()
SourceDebug.cancelDebug(true)
Debug.cancelDebug(true)
}
}

@ -5,7 +5,7 @@ import fi.iki.elonen.NanoHTTPD
import fi.iki.elonen.NanoWSD
import io.legado.app.App
import io.legado.app.R
import io.legado.app.model.SourceDebug
import io.legado.app.model.Debug
import io.legado.app.model.WebBook
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
@ -18,7 +18,7 @@ import java.io.IOException
class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
NanoWSD.WebSocket(handshakeRequest),
CoroutineScope by MainScope(),
SourceDebug.Callback {
Debug.Callback {
override fun onOpen() {
@ -38,7 +38,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
initiatedByRemote: Boolean
) {
cancel()
SourceDebug.cancelDebug(true)
Debug.cancelDebug(true)
}
override fun onMessage(message: NanoWSD.WebSocketFrame) {
@ -56,8 +56,8 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
return
}
App.db.bookSourceDao().getBookSource(tag)?.let {
SourceDebug.callback = this
SourceDebug.startDebug(WebBook(it), key)
Debug.callback = this
Debug.startDebug(WebBook(it), key)
}
}
}
@ -68,14 +68,14 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
}
override fun onException(exception: IOException) {
SourceDebug.cancelDebug(true)
Debug.cancelDebug(true)
}
override fun printLog(state: Int, msg: String) {
kotlin.runCatching {
send(msg)
if (state == -1 || state == 1000) {
SourceDebug.cancelDebug(true)
Debug.cancelDebug(true)
}
}
}

Loading…
Cancel
Save