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

@ -112,7 +112,7 @@ object RssParserByRule {
Debug.log(sourceUrl, "${rssArticle.description}", 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, "┌获取文章链接", log)
rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink))

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

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

@ -129,7 +129,7 @@ object BookInfo {
}
scope.ensureActive()
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 == redirectUrl) {
book.tocHtml = body

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

Loading…
Cancel
Save