From d8c1721a8d2ad0de4ed34c62510ed25720c8e09f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 19:15:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BaseBook.kt | 1 + .../java/io/legado/app/data/entities/Book.kt | 2 +- .../io/legado/app/data/entities/SearchBook.kt | 2 +- .../app/model/webBook/BookChapterList.kt | 22 +++++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt index 0c96c2123..62d322b6c 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt @@ -3,6 +3,7 @@ package io.legado.app.data.entities import io.legado.app.utils.splitNotBlank interface BaseBook { + var bookUrl: String var variableMap: HashMap? var kind: String? var wordCount: String? diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index d01919a94..d29ce696e 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -17,7 +17,7 @@ import kotlin.math.max @Entity(tableName = "books", indices = [(Index(value = ["bookUrl"], unique = true))]) data class Book( @PrimaryKey - var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径) + override var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径) var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) var originName: String = "", //书源名称 or 本地书籍文件名 diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index 2baf259e4..edd6f6e56 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -21,7 +21,7 @@ import kotlinx.android.parcel.Parcelize ) data class SearchBook( @PrimaryKey - var bookUrl: String = "", + override var bookUrl: String = "", var origin: String = "", // 书源规则 var originName: String = "", var type: Int = 0, // @BookType diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index ff3467a8a..aa0b7de74 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -31,6 +31,7 @@ object BookChapterList { App.INSTANCE.getString(R.string.error_get_web_content, baseUrl) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") + val analyzeRule = AnalyzeRule(book) val tocRule = bookSource.getTocRule() val nextUrlList = arrayListOf(baseUrl) var reverse = false @@ -43,7 +44,10 @@ object BookChapterList { listRule = listRule.substring(1) } var chapterData = - analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, log = true) + analyzeChapterList( + analyzeRule.setContent(body, baseUrl), + book.bookUrl, baseUrl, tocRule, listRule, bookSource, log = true + ) chapterData.chapterList?.let { chapterList.addAll(it) } @@ -63,8 +67,8 @@ object BookChapterList { ).getResponseAwait() .body?.let { nextBody -> chapterData = analyzeChapterList( - nextBody, nextUrl, tocRule, listRule, - book, bookSource, log = false + analyzeRule.setContent(nextBody, nextUrl), + book.bookUrl, nextUrl, tocRule, listRule, bookSource ) nextUrl = if (chapterData.nextUrl.isNotEmpty()) { chapterData.nextUrl[0] @@ -98,7 +102,9 @@ object BookChapterList { headerMapF = bookSource.getHeaderMap() ).getResponseAwait().body val nextChapterData = analyzeChapterList( - nextBody, item.nextUrl, tocRule, listRule, book, bookSource + analyzeRule.setContent(nextBody, item.nextUrl), + book.bookUrl, item.nextUrl, tocRule, listRule, bookSource, + false ) synchronized(chapterDataList) { val isFinished = addChapterListIsFinish( @@ -167,19 +173,17 @@ object BookChapterList { } private fun analyzeChapterList( - body: String?, + analyzeRule: AnalyzeRule, + bookUrl: String, baseUrl: String, tocRule: TocRule, listRule: String, - book: Book, bookSource: BookSource, getNextUrl: Boolean = true, log: Boolean = false ): ChapterData> { val chapterList = arrayListOf() val nextUrlList = arrayListOf() - val analyzeRule = AnalyzeRule(book) - analyzeRule.setContent(body, baseUrl) val nextTocRule = tocRule.nextTocUrl if (getNextUrl && !nextTocRule.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log) @@ -208,7 +212,7 @@ object BookChapterList { var isVip: String? for (item in elements) { analyzeRule.setContent(item) - val bookChapter = BookChapter(bookUrl = book.bookUrl) + val bookChapter = BookChapter(bookUrl = bookUrl) analyzeRule.chapter = bookChapter bookChapter.title = analyzeRule.getString(nameRule) bookChapter.url = analyzeRule.getString(urlRule, true)