pull/1463/head
gedoor 3 years ago
parent 0f416b6d12
commit 48eed794e1
  1. 28
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 2
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 2
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  4. 4
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  5. 2
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  6. 2
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -129,16 +129,20 @@ class AnalyzeRule(
* 获取文本列表 * 获取文本列表
*/ */
@JvmOverloads @JvmOverloads
fun getStringList(rule: String?, isUrl: Boolean = false): List<String>? { fun getStringList(rule: String?, mContent: Any? = null, isUrl: Boolean = false): List<String>? {
if (rule.isNullOrEmpty()) return null if (rule.isNullOrEmpty()) return null
val ruleList = splitSourceRule(rule, false) val ruleList = splitSourceRule(rule, false)
return getStringList(ruleList, isUrl) return getStringList(ruleList, mContent, isUrl)
} }
@JvmOverloads @JvmOverloads
fun getStringList(ruleList: List<SourceRule>, isUrl: Boolean = false): List<String>? { fun getStringList(
ruleList: List<SourceRule>,
mContent: Any? = null,
isUrl: Boolean = false
): List<String>? {
var result: Any? = null var result: Any? = null
val content = this.content val content = mContent ?: this.content
if (content != null && ruleList.isNotEmpty()) { if (content != null && ruleList.isNotEmpty()) {
result = content result = content
if (content is NativeObject) { if (content is NativeObject) {
@ -194,22 +198,22 @@ class AnalyzeRule(
* 获取文本 * 获取文本
*/ */
@JvmOverloads @JvmOverloads
fun getString(ruleStr: String?, isUrl: Boolean = false, value: String? = null): String { fun getString(ruleStr: String?, mContent: Any? = null, isUrl: Boolean = false): String {
if (TextUtils.isEmpty(ruleStr)) return "" if (TextUtils.isEmpty(ruleStr)) return ""
val ruleList = splitSourceRule(ruleStr) val ruleList = splitSourceRule(ruleStr)
return getString(ruleList, isUrl, value) return getString(ruleList, mContent, isUrl)
} }
@JvmOverloads @JvmOverloads
fun getString( fun getString(
ruleList: List<SourceRule>, ruleList: List<SourceRule>,
isUrl: Boolean = false, mContent: Any? = null,
value: String? = null isUrl: Boolean = false
): String { ): String {
var result: Any? = value var result: Any? = null
val content = this.content val content = mContent ?: this.content
if ((content != null || result != null) && ruleList.isNotEmpty()) { if (content != null && ruleList.isNotEmpty()) {
if (result == null) result = content result = content
if (result is NativeObject) { if (result is NativeObject) {
result = result[ruleList[0].rule]?.toString() result = result[ruleList[0].rule]?.toString()
} else { } else {

@ -112,7 +112,7 @@ object RssParserByRule {
Debug.log(sourceUrl, "${rssArticle.description}", log) Debug.log(sourceUrl, "${rssArticle.description}", log)
} }
Debug.log(sourceUrl, "┌获取图片url", log) Debug.log(sourceUrl, "┌获取图片url", log)
rssArticle.image = analyzeRule.getString(ruleImage, true) rssArticle.image = analyzeRule.getString(ruleImage, isUrl = true)
Debug.log(sourceUrl, "${rssArticle.image}", log) Debug.log(sourceUrl, "${rssArticle.image}", log)
Debug.log(sourceUrl, "┌获取文章链接", log) Debug.log(sourceUrl, "┌获取文章链接", log)
rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink)) rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink))

@ -156,7 +156,7 @@ object BookChapterList {
val nextTocRule = tocRule.nextTocUrl val nextTocRule = tocRule.nextTocUrl
if (getNextUrl && !nextTocRule.isNullOrEmpty()) { if (getNextUrl && !nextTocRule.isNullOrEmpty()) {
Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log) Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log)
analyzeRule.getStringList(nextTocRule, true)?.let { analyzeRule.getStringList(nextTocRule, isUrl = true)?.let {
for (item in it) { for (item in it) {
if (item != baseUrl) { if (item != baseUrl) {
nextUrlList.add(item) nextUrlList.add(item)

@ -112,7 +112,7 @@ object BookContent {
var contentStr = content.toString() var contentStr = content.toString()
val replaceRegex = contentRule.replaceRegex val replaceRegex = contentRule.replaceRegex
if (!replaceRegex.isNullOrEmpty()) { if (!replaceRegex.isNullOrEmpty()) {
contentStr = analyzeRule.getString(replaceRegex, value = contentStr) contentStr = analyzeRule.getString(replaceRegex, contentStr)
} }
Debug.log(bookSource.bookSourceUrl, "┌获取章节名称") Debug.log(bookSource.bookSourceUrl, "┌获取章节名称")
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}") Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")
@ -150,7 +150,7 @@ object BookContent {
val nextUrlRule = contentRule.nextContentUrl val nextUrlRule = contentRule.nextContentUrl
if (!nextUrlRule.isNullOrEmpty()) { if (!nextUrlRule.isNullOrEmpty()) {
Debug.log(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog) Debug.log(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog)
analyzeRule.getStringList(nextUrlRule, true)?.let { analyzeRule.getStringList(nextUrlRule, isUrl = true)?.let {
nextUrlList.addAll(it) nextUrlList.addAll(it)
} }
Debug.log(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog) Debug.log(bookSource.bookSourceUrl, "" + nextUrlList.joinToString(""), printLog)

@ -129,7 +129,7 @@ object BookInfo {
} }
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") Debug.log(bookSource.bookSourceUrl, "┌获取目录链接")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) book.tocUrl = analyzeRule.getString(infoRule.tocUrl, isUrl = true)
if (book.tocUrl.isEmpty()) book.tocUrl = redirectUrl if (book.tocUrl.isEmpty()) book.tocUrl = redirectUrl
if (book.tocUrl == redirectUrl) { if (book.tocUrl == redirectUrl) {
book.tocHtml = body book.tocHtml = body

@ -231,7 +231,7 @@ object BookList {
} }
scope.ensureActive() scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log) Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log)
searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, isUrl = true)
if (searchBook.bookUrl.isEmpty()) { if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl searchBook.bookUrl = baseUrl
} }

Loading…
Cancel
Save