From 6c6c84c7f300bfe7c79d733afd6bac476f4a2879 Mon Sep 17 00:00:00 2001 From: Celeter Date: Mon, 4 Nov 2019 23:39:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2URL?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/OldRule.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 343a54087..73bf9b720 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -114,6 +114,7 @@ object OldRule { } url = url.replace("{", "<").replace("}", ">") url = url.replace("searchKey", "{{key}}") + url = url.replace("?".toRegex(), "{{page$1}}") url = url.replace("searchPage", "{{page}}") for ((index, item) in jsList.withIndex()) { url = url.replace("$$index", item.replace("searchKey", "key").replace("searchPage", "page")) From 561586ed6314e4cb0bcef47cb05001c8364dabcb Mon Sep 17 00:00:00 2001 From: Celeter Date: Tue, 5 Nov 2019 21:05:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=A6=E6=BA=90URL?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/OldRule.kt | 20 ++++++++++++++++--- .../legado/app/model/webbook/BookContent.kt | 5 ++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 73bf9b720..4f1afddac 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -31,7 +31,7 @@ object OldRule { customOrder = jsonItem.readInt("serialNumber") ?: 0 header = uaToHeader(jsonItem.readString("httpUserAgent")) searchUrl = toNewUrl(jsonItem.readString("ruleSearchUrl")) - exploreUrl = toNewUrl(jsonItem.readString("ruleFindUrl")) + exploreUrl = toNewUrls(jsonItem.readString("ruleFindUrl")) if (exploreUrl.isNullOrBlank()) { enabledExplore = false } @@ -86,6 +86,19 @@ object OldRule { 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? { if (oldUrl == null) return null var url: String = oldUrl @@ -114,8 +127,9 @@ object OldRule { } url = url.replace("{", "<").replace("}", ">") url = url.replace("searchKey", "{{key}}") - url = url.replace("?".toRegex(), "{{page$1}}") - url = url.replace("searchPage", "{{page}}") + url = url.replace("".toRegex(), "{{page$1}}") + .replace("searchPage([-+]1)".toRegex(), "{{page$1}}") + .replace("searchPage", "{{page}}") for ((index, item) in jsList.withIndex()) { url = url.replace("$$index", item.replace("searchKey", "key").replace("searchPage", "page")) } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt index c6a520aa7..c0d530d80 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt @@ -94,7 +94,10 @@ object BookContent { 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)