pull/48/head
kunfei 5 years ago
parent 7694e6f57c
commit 46bcd053db
  1. 4
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 2
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  3. 16
      app/src/main/java/io/legado/app/model/webbook/BookInfo.kt
  4. 32
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -170,8 +170,8 @@ class AnalyzeRule(var book: BaseBook? = null) {
* 获取文本 * 获取文本
*/ */
@Throws(Exception::class) @Throws(Exception::class)
fun getString(ruleStr: String, isUrl: Boolean = false): String? { fun getString(ruleStr: String?, isUrl: Boolean = false): String {
if (TextUtils.isEmpty(ruleStr)) return null if (TextUtils.isEmpty(ruleStr)) return ""
val ruleList = splitSourceRule(ruleStr) val ruleList = splitSourceRule(ruleStr)
return getString(ruleList, isUrl) return getString(ruleList, isUrl)
} }

@ -132,7 +132,7 @@ object BookContent {
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog) SourceDebug.printLog(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog)
} }
val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" val content = analyzeRule.getString(contentRule.content).htmlFormat()
return ContentData(content, nextUrlList) return ContentData(content, nextUrlList)
} }
} }

@ -31,43 +31,43 @@ object BookInfo {
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名") 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, "${book.name}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.name}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者") 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, "${book.author}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.author}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类") 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, "${book.kind}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数") 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, "${book.wordCount}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.wordCount}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节") 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, "${book.latestChapterTitle}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.latestChapterTitle}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介") 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, "${book.intro}", isHtml = true) SourceDebug.printLog(bookSource.bookSourceUrl, "${book.intro}", isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接")
analyzeRule.getString(infoRule.coverUrl ?: "")?.let { analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it) if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it)
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "${book.coverUrl}") SourceDebug.printLog(bookSource.bookSourceUrl, "${book.coverUrl}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录链接") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录链接")
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
if (book.tocUrl == baseUrl) { if (book.tocUrl == baseUrl) {
book.tocHtml = body book.tocHtml = body

@ -46,7 +46,7 @@ object BookList {
bookSource.getExploreRule().bookList.isNullOrBlank() -> bookSource.getSearchRule() bookSource.getExploreRule().bookList.isNullOrBlank() -> bookSource.getSearchRule()
else -> bookSource.getExploreRule() else -> bookSource.getExploreRule()
} }
var ruleList = bookListRule.bookList ?: "" var ruleList: String = bookListRule.bookList ?: ""
if (ruleList.startsWith("-")) { if (ruleList.startsWith("-")) {
reverse = true reverse = true
ruleList = ruleList.substring(1) ruleList = ruleList.substring(1)
@ -63,14 +63,14 @@ object BookList {
bookList.add(searchBook) bookList.add(searchBook)
} }
} else { } else {
val ruleName = analyzeRule.splitSourceRule(bookListRule.name ?: "") val ruleName = analyzeRule.splitSourceRule(bookListRule.name)
val ruleBookUrl = analyzeRule.splitSourceRule(bookListRule.bookUrl ?: "") val ruleBookUrl = analyzeRule.splitSourceRule(bookListRule.bookUrl)
val ruleAuthor = analyzeRule.splitSourceRule(bookListRule.author ?: "") val ruleAuthor = analyzeRule.splitSourceRule(bookListRule.author)
val ruleCoverUrl = analyzeRule.splitSourceRule(bookListRule.coverUrl ?: "") val ruleCoverUrl = analyzeRule.splitSourceRule(bookListRule.coverUrl)
val ruleIntro = analyzeRule.splitSourceRule(bookListRule.intro ?: "") val ruleIntro = analyzeRule.splitSourceRule(bookListRule.intro)
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, "└列表大小:${collections.size}") SourceDebug.printLog(bookSource.bookSourceUrl, "└列表大小:${collections.size}")
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
getSearchItem( getSearchItem(
@ -121,26 +121,26 @@ object BookList {
} }
} }
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名")
searchBook.name = analyzeRule.getString(name ?: "") ?: "" searchBook.name = analyzeRule.getString(name)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.name}")
if (searchBook.name.isNotEmpty()) { if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者")
searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: "")) searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author))
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.author}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类")
searchBook.kind = analyzeRule.getString(kind ?: "") searchBook.kind = analyzeRule.getString(kind)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.kind}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount ?: "") searchBook.wordCount = analyzeRule.getString(wordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.wordCount}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "") searchBook.latestChapterTitle = analyzeRule.getString(lastChapter)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "") searchBook.intro = analyzeRule.getString(intro)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", true) SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.intro}", true)
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true) searchBook.coverUrl = analyzeRule.getString(coverUrl, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}") SourceDebug.printLog(bookSource.bookSourceUrl, "${searchBook.coverUrl}")
return searchBook return searchBook
} }

Loading…
Cancel
Save