Merge pull request #47 from Celeter/master

修复书源URL转换的bug
pull/48/head
kunfei 5 years ago committed by GitHub
commit 4313b7fc39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      app/src/main/java/io/legado/app/help/storage/OldRule.kt
  2. 5
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt

@ -31,7 +31,7 @@ object OldRule {
customOrder = jsonItem.readInt("serialNumber") ?: 0 customOrder = jsonItem.readInt("serialNumber") ?: 0
header = uaToHeader(jsonItem.readString("httpUserAgent")) header = uaToHeader(jsonItem.readString("httpUserAgent"))
searchUrl = toNewUrl(jsonItem.readString("ruleSearchUrl")) searchUrl = toNewUrl(jsonItem.readString("ruleSearchUrl"))
exploreUrl = toNewUrl(jsonItem.readString("ruleFindUrl")) exploreUrl = toNewUrls(jsonItem.readString("ruleFindUrl"))
if (exploreUrl.isNullOrBlank()) { if (exploreUrl.isNullOrBlank()) {
enabledExplore = false enabledExplore = false
} }
@ -86,6 +86,19 @@ object OldRule {
return source return source
} }
private fun toNewUrls(oldUrl: String?): String? {
if (oldUrl == null) return null
if (!oldUrl.contains("\n") && !oldUrl.contains("&&"))
return toNewUrl(oldUrl)
val urls = oldUrl.split("(&&|\n)+".toRegex())
var newUrl = ""
for (url in urls) {
newUrl += toNewUrl(url)?.replace("\\n\\s*".toRegex(),"") + "\n"
}
return newUrl
}
private fun toNewUrl(oldUrl: String?): String? { private fun toNewUrl(oldUrl: String?): String? {
if (oldUrl == null) return null if (oldUrl == null) return null
var url: String = oldUrl var url: String = oldUrl
@ -114,7 +127,9 @@ object OldRule {
} }
url = url.replace("{", "<").replace("}", ">") url = url.replace("{", "<").replace("}", ">")
url = url.replace("searchKey", "{{key}}") url = url.replace("searchKey", "{{key}}")
url = url.replace("searchPage", "{{page}}") url = url.replace("<searchPage([-+]1)>".toRegex(), "{{page$1}}")
.replace("searchPage([-+]1)".toRegex(), "{{page$1}}")
.replace("searchPage", "{{page}}")
for ((index, item) in jsList.withIndex()) { for ((index, item) in jsList.withIndex()) {
url = url.replace("$$index", item.replace("searchKey", "key").replace("searchPage", "page")) url = url.replace("$$index", item.replace("searchKey", "key").replace("searchPage", "page"))
} }

@ -94,7 +94,10 @@ object BookContent {
content.append(item.content) content.append(item.content)
} }
} }
return content.toString() SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取章节名称")
SourceDebug.printLog(bookSource.bookSourceUrl, "${bookChapter.title}")
SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取正文内容")
return "\n" + content.toString()
} }
@Throws(Exception::class) @Throws(Exception::class)

Loading…
Cancel
Save