Merge pull request #43 from Celeter/master

优化书源调试log
pull/44/head
kunfei 5 years ago committed by GitHub
commit 55fa2a5688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  2. 11
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  3. 44
      app/src/main/java/io/legado/app/model/webbook/BookInfo.kt
  4. 88
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  5. 20
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt

@ -25,7 +25,7 @@ object BookChapterList {
body ?: throw Exception(
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
val tocRule = bookSource.getTocRule()
val nextUrlList = arrayListOf(baseUrl)
var reverse = false
@ -69,7 +69,7 @@ object BookChapterList {
}
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "总页数${nextUrlList.size}")
SourceDebug.printLog(bookSource.bookSourceUrl, "≡目录总页数:${nextUrlList.size}")
} else if (chapterData.nextUrl.size > 1) {
val chapterDataList = arrayListOf<ChapterData<String>>()
for (item in chapterData.nextUrl) {
@ -135,7 +135,7 @@ object BookChapterList {
analyzeRule.setContent(body, baseUrl)
val nextTocRule = tocRule.nextTocUrl
if (getNextUrl && !nextTocRule.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录下一页列表", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录下一页列表", printLog)
analyzeRule.getStringList(nextTocRule, true)?.let {
for (item in it) {
if (item != baseUrl) {
@ -145,15 +145,15 @@ object BookChapterList {
}
SourceDebug.printLog(
bookSource.bookSourceUrl,
TextUtils.join(",", nextUrlList),
"" + TextUtils.join(",\n", nextUrlList),
printLog
)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "解析目录列表", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录列表", printLog)
val elements = analyzeRule.getElements(listRule)
SourceDebug.printLog(bookSource.bookSourceUrl, "目录数${elements.size}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "└列表大小:${elements.size}", printLog)
if (elements.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取首章名称", printLog)
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "")
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "")
for (item in elements) {
@ -167,11 +167,9 @@ object BookChapterList {
chapterList.add(bookChapter)
}
}
SourceDebug.printLog(
bookSource.bookSourceUrl,
"${chapterList[0].title}${chapterList[0].url}",
printLog
)
SourceDebug.printLog(bookSource.bookSourceUrl, "${chapterList[0].title}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取首章链接", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${chapterList[0].url}", printLog)
}
return ChapterData(chapterList, nextUrlList)
}

@ -31,7 +31,7 @@ object BookContent {
baseUrl
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
@ -62,7 +62,7 @@ object BookContent {
content.append(contentData.content)
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "总页数${nextUrlList.size}")
SourceDebug.printLog(bookSource.bookSourceUrl, "≡本章总页数:${nextUrlList.size}")
} else if (contentData.nextUrl.size > 1) {
val contentDataList = arrayListOf<ContentData<String>>()
for (item in contentData.nextUrl) {
@ -98,7 +98,8 @@ object BookContent {
if (!content[0].toString().startsWith(bookChapter.title)) {
content
.insert(0, "\n")
.insert(0, bookChapter.title)
.insert(0, "\n》正文内容:")
.insert(0, "》章节名称:${bookChapter.title}")
}
}
return content.toString()
@ -118,11 +119,11 @@ object BookContent {
analyzeRule.setContent(body, baseUrl)
val nextUrlRule = contentRule.nextContentUrl
if (!nextUrlRule.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取下一页URL", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog)
analyzeRule.getStringList(nextUrlRule, true)?.let {
nextUrlList.addAll(it)
}
SourceDebug.printLog(bookSource.bookSourceUrl, nextUrlList.joinToString(","), printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(","), printLog)
}
val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: ""
return ContentData(content, nextUrlList)

@ -19,53 +19,59 @@ object BookInfo {
body ?: throw Exception(
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}")
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, "执行详情页初始化规则")
SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
analyzeRule.getString(infoRule.name ?: "")?.let {
if (it.isNotEmpty()) book.name = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, book.name)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
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, book.author)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
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, book.kind)
SourceDebug.printLog(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, "获取字数")
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数")
analyzeRule.getString(infoRule.wordCount ?: "")?.let {
if (it.isNotEmpty()) book.wordCount = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, book.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
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, book.latestChapterTitle)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取目录Url")
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
SourceDebug.printLog(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, "┌获取封面链接")
analyzeRule.getString(infoRule.coverUrl ?: "")?.let {
if (it.isNotEmpty()) book.coverUrl = it
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.coverUrl}")
SourceDebug.printLog(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)
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.tocUrl}")
}
}

@ -28,12 +28,12 @@ object BookList {
analyzeUrl.ruleUrl
)
)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${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, "url为详情页")
SourceDebug.printLog(bookSource.bookSourceUrl, "≡链接为详情页")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.infoHtml = body
bookList.add(searchBook)
@ -56,10 +56,10 @@ object BookList {
if (ruleList.startsWith("+")) {
ruleList = ruleList.substring(1)
}
SourceDebug.printLog(bookSource.bookSourceUrl, "解析书籍列表")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书籍列表")
collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "列表为空,按详情页解析")
SourceDebug.printLog(bookSource.bookSourceUrl, "列表为空,按详情页解析")
getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.infoHtml = body
bookList.add(searchBook)
@ -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, "列表数为${collections.size}")
SourceDebug.printLog(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, "执行详情页初始化规则")
SourceDebug.printLog(bookSource.bookSourceUrl, "执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名")
searchBook.name = analyzeRule.getString(name ?: "") ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}")
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: ""))
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}")
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类")
searchBook.kind = analyzeRule.getString(kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.intro, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数")
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节")
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.latestChapterTitle)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}")
return searchBook
}
}
@ -170,34 +170,34 @@ object BookList {
searchBook.originOrder = bookSource.customOrder
analyzeRule.setBook(searchBook)
analyzeRule.setContent(item)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名", printLog)
searchBook.name = analyzeRule.getString(ruleName)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}", printLog)
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书籍Url", printLog)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)
if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.bookUrl, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者", printLog)
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor))
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类", printLog)
searchBook.kind = analyzeRule.getString(ruleKind)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介", printLog)
searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.intro, printLog, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数", printLog)
searchBook.wordCount = analyzeRule.getString(ruleWordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url", printLog)
searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节", printLog)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.latestChapterTitle, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介", printLog)
searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", printLog, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接", printLog)
searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取详情页链接", printLog)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true)
if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.bookUrl}", printLog)
return searchBook
}
return null

@ -65,10 +65,10 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
val book = Book()
book.origin = webBook.sourceUrl
book.bookUrl = key
printLog(webBook.sourceUrl, "开始访问$key")
printLog(webBook.sourceUrl, "开始访问:$key")
infoDebug(book)
} else {
printLog(webBook.sourceUrl, "开始搜索关键字$key")
printLog(webBook.sourceUrl, "开始搜索关键字:$key")
searchDebug(key)
}
}
@ -78,11 +78,11 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
.onSuccess { searchBooks ->
searchBooks?.let {
if (searchBooks.isNotEmpty()) {
printLog(debugSource, "搜索完成")
printLog(debugSource, "搜索页解析完成")
printLog(debugSource, "", showTime = false)
infoDebug(searchBooks[0].toBook())
} else {
printLog(debugSource, "未获取到书籍", state = -1)
printLog(debugSource, "未获取到书籍", state = -1)
}
}
}
@ -93,10 +93,10 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
}
private fun infoDebug(book: Book) {
printLog(debugSource, "开始获取详情页")
printLog(debugSource, "开始获取详情页")
val info = webBook.getBookInfo(book)
.onSuccess {
printLog(debugSource, "详情页完成")
printLog(debugSource, "详情页解析完成")
printLog(debugSource, "", showTime = false)
tocDebug(book)
}
@ -107,17 +107,17 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
}
private fun tocDebug(book: Book) {
printLog(debugSource, "开始获取目录页")
printLog(debugSource, "开始获取目录页")
val chapterList = webBook.getChapterList(book)
.onSuccess { chapterList ->
chapterList?.let {
if (it.isNotEmpty()) {
printLog(debugSource, "目录完成")
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, "目录列表为空", state = -1)
printLog(debugSource, "目录列表为空", state = -1)
}
}
}
@ -128,7 +128,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
}
private fun contentDebug(book: Book, bookChapter: BookChapter, nextChapterUrl: String?) {
printLog(debugSource, "开始获取内容")
printLog(debugSource, "︾开始获取正文")
val content = webBook.getContent(book, bookChapter, nextChapterUrl)
.onSuccess { content ->
content?.let {

Loading…
Cancel
Save