diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt index 12792f7b7..2e4e61a4a 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt @@ -1,15 +1,22 @@ package io.legado.app.data.entities.rule data class ExploreRule( - var exploreUrl: String? = null, - override var bookList: String? = null, - override var name: String? = null, - override var author: String? = null, - override var intro: String? = null, - override var kind: String? = null, - override var lastChapter: String? = null, - override var updateTime: String? = null, - override var bookUrl: String? = null, - override var coverUrl: String? = null, - override var wordCount: String? = null -) : BookListRule \ No newline at end of file + var exploreUrl: String? = null, + override var bookList: String? = null, + override var name: String? = null, + override var author: String? = null, + override var intro: String? = null, + override var kind: String? = null, + override var lastChapter: String? = null, + override var updateTime: String? = null, + override var bookUrl: String? = null, + override var coverUrl: String? = null, + override var wordCount: String? = null +) : BookListRule { + + + data class ExploreUrl( + var title: String, + var url: String + ) +} \ No newline at end of file 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 bcd2e8b83..3557ea844 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 @@ -17,11 +17,11 @@ import retrofit2.Response object BookChapterList { suspend fun analyzeChapterList( - coroutineScope: CoroutineScope, - book: Book, - response: Response, - bookSource: BookSource, - analyzeUrl: AnalyzeUrl + coroutineScope: CoroutineScope, + book: Book, + response: Response, + bookSource: BookSource, + analyzeUrl: AnalyzeUrl ): List { var chapterList = arrayListOf() val baseUrl: String = NetworkUtils.getUrl(response) @@ -40,7 +40,7 @@ object BookChapterList { listRule = listRule.substring(1) } var chapterData = - analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) + analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) chapterData.chapterList?.let { chapterList.addAll(it) } @@ -49,26 +49,26 @@ object BookChapterList { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { nextUrlList.add(nextUrl) AnalyzeUrl( - ruleUrl = nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() - .body()?.let { nextBody -> - chapterData = analyzeChapterList( - nextBody, - nextUrl, - tocRule, - listRule, - book, - bookSource - ) - nextUrl = if (chapterData.nextUrl.isNotEmpty()) - chapterData.nextUrl[0] - else "" - chapterData.chapterList?.let { - chapterList.addAll(it) - } + .body()?.let { nextBody -> + chapterData = analyzeChapterList( + nextBody, + nextUrl, + tocRule, + listRule, + book, + bookSource + ) + nextUrl = if (chapterData.nextUrl.isNotEmpty()) + chapterData.nextUrl[0] + else "" + chapterData.chapterList?.let { + chapterList.addAll(it) } + } } } else if (chapterData.nextUrl.size > 1) { val chapterDataList = arrayListOf>() @@ -79,18 +79,18 @@ object BookChapterList { for (item in chapterDataList) { withContext(coroutineScope.coroutineContext) { val nextResponse = AnalyzeUrl( - ruleUrl = item.nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = item.nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() val nextChapterData = analyzeChapterList( - nextResponse.body() ?: "", - item.nextUrl, - tocRule, - listRule, - book, - bookSource, - getNextUrl = false + nextResponse.body() ?: "", + item.nextUrl, + tocRule, + listRule, + book, + bookSource, + getNextUrl = false ) item.chapterList = nextChapterData.chapterList } @@ -121,14 +121,14 @@ object BookChapterList { private fun analyzeChapterList( - body: String, - baseUrl: String, - tocRule: TocRule, - listRule: String, - book: Book, - bookSource: BookSource, - getNextUrl: Boolean = true, - printLog: Boolean = false + body: String, + baseUrl: String, + tocRule: TocRule, + listRule: String, + book: Book, + bookSource: BookSource, + getNextUrl: Boolean = true, + printLog: Boolean = false ): ChapterData> { val chapterList = arrayListOf() val nextUrlList = arrayListOf() @@ -144,10 +144,10 @@ object BookChapterList { } } SourceDebug.printLog( - bookSource.bookSourceUrl, - 1, - TextUtils.join(",", nextUrlList), - printLog + bookSource.bookSourceUrl, + 1, + TextUtils.join(",", nextUrlList), + printLog ) } SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) @@ -169,10 +169,10 @@ object BookChapterList { } } SourceDebug.printLog( - bookSource.bookSourceUrl, - 1, - "${chapterList[0].title}${chapterList[0].url}", - printLog + bookSource.bookSourceUrl, + 1, + "${chapterList[0].title}${chapterList[0].url}", + printLog ) } return ChapterData(chapterList, nextUrlList) 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 654e61b02..0f78b9d4a 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 @@ -18,20 +18,20 @@ object BookContent { @Throws(Exception::class) suspend fun analyzeContent( - coroutineScope: CoroutineScope, - response: Response, - book: Book, - bookChapter: BookChapter, - bookSource: BookSource, - nextChapterUrlF: String? = null + coroutineScope: CoroutineScope, + response: Response, + book: Book, + bookChapter: BookChapter, + bookSource: BookSource, + nextChapterUrlF: String? = null ): String { val baseUrl: String = NetworkUtils.getUrl(response) val body: String? = response.body() body ?: throw Exception( - App.INSTANCE.getString( - R.string.error_get_web_content, - baseUrl - ) + App.INSTANCE.getString( + R.string.error_get_web_content, + baseUrl + ) ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") val content = StringBuilder() @@ -47,21 +47,21 @@ object BookContent { App.db.bookChapterDao().getChapter(book.bookUrl, bookChapter.index + 1)?.url while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { if (!nextChapterUrl.isNullOrEmpty() - && NetworkUtils.getAbsoluteURL(baseUrl, nextUrl) - == NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl) + && NetworkUtils.getAbsoluteURL(baseUrl, nextUrl) + == NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl) ) break nextUrlList.add(nextUrl) AnalyzeUrl( - ruleUrl = nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() - .body()?.let { nextBody -> - contentData = analyzeContent(nextBody, contentRule, book, baseUrl) - nextUrl = - if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" - content.append(contentData.content) - } + .body()?.let { nextBody -> + contentData = analyzeContent(nextBody, contentRule, book, baseUrl) + nextUrl = + if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" + content.append(contentData.content) + } } } else if (contentData.nextUrl.size > 1) { val contentDataList = arrayListOf>() @@ -72,15 +72,15 @@ object BookContent { for (item in contentDataList) { withContext(coroutineScope.coroutineContext) { val nextResponse = AnalyzeUrl( - ruleUrl = item.nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = item.nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() val nextContentData = analyzeContent( - nextResponse.body() ?: "", - contentRule, - book, - item.nextUrl + nextResponse.body() ?: "", + contentRule, + book, + item.nextUrl ) item.content = nextContentData.content } @@ -92,8 +92,8 @@ object BookContent { if (content.isNotEmpty()) { if (!content[0].toString().startsWith(bookChapter.title)) { content - .insert(0, "\n") - .insert(0, bookChapter.title) + .insert(0, "\n") + .insert(0, bookChapter.title) } } return content.toString() @@ -101,10 +101,10 @@ object BookContent { @Throws(Exception::class) private fun analyzeContent( - body: String, - contentRule: ContentRule, - book: Book, - baseUrl: String + body: String, + contentRule: ContentRule, + book: Book, + baseUrl: String ): ContentData> { val nextUrlList = arrayListOf() val analyzeRule = AnalyzeRule(book) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt index 533669207..1ad81cf11 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt @@ -11,17 +11,17 @@ object BookInfo { @Throws(Exception::class) fun analyzeBookInfo( - book: Book, - body: String?, - bookSource: BookSource, - analyzeUrl: AnalyzeUrl + book: Book, + body: String?, + bookSource: BookSource, + analyzeUrl: AnalyzeUrl ) { val baseUrl = analyzeUrl.url body ?: throw Exception( - App.INSTANCE.getString( - R.string.error_get_web_content, - baseUrl - ) + App.INSTANCE.getString( + R.string.error_get_web_content, + baseUrl + ) ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") val infoRule = bookSource.getBookInfoRule() diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webbook/BookList.kt index 607677e4d..517ee4ecb 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookList.kt @@ -14,19 +14,19 @@ object BookList { @Throws(Exception::class) fun analyzeBookList( - response: Response, - bookSource: BookSource, - analyzeUrl: AnalyzeUrl, - isSearch: Boolean = true + response: Response, + bookSource: BookSource, + analyzeUrl: AnalyzeUrl, + isSearch: Boolean = true ): ArrayList { val bookList = ArrayList() val baseUrl: String = NetworkUtils.getUrl(response) val body: String? = response.body() body ?: throw Exception( - App.INSTANCE.getString( - R.string.error_get_web_content, - baseUrl - ) + App.INSTANCE.getString( + R.string.error_get_web_content, + baseUrl + ) ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") val analyzeRule = AnalyzeRule(null) @@ -72,19 +72,19 @@ object BookList { SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表数为${collections.size}") for ((index, item) in collections.withIndex()) { getSearchItem( - item, - analyzeRule, - bookSource, - baseUrl, - index == 0, - ruleName = ruleName, - ruleBookUrl = ruleBookUrl, - ruleAuthor = ruleAuthor, - ruleCoverUrl = ruleCoverUrl, - ruleIntro = ruleIntro, - ruleKind = ruleKind, - ruleLastChapter = ruleLastChapter, - ruleWordCount = ruleWordCount + item, + analyzeRule, + bookSource, + baseUrl, + index == 0, + ruleName = ruleName, + ruleBookUrl = ruleBookUrl, + ruleAuthor = ruleAuthor, + ruleCoverUrl = ruleCoverUrl, + ruleIntro = ruleIntro, + ruleKind = ruleKind, + ruleLastChapter = ruleLastChapter, + ruleWordCount = ruleWordCount )?.let { searchBook -> if (baseUrl == searchBook.bookUrl) { searchBook.bookInfoHtml = body @@ -99,7 +99,11 @@ object BookList { return bookList } - private fun getInfoItem(analyzeRule: AnalyzeRule, bookSource: BookSource, baseUrl: String): SearchBook? { + private fun getInfoItem( + analyzeRule: AnalyzeRule, + bookSource: BookSource, + baseUrl: String + ): SearchBook? { val searchBook = SearchBook() searchBook.bookUrl = baseUrl searchBook.origin = bookSource.bookSourceUrl @@ -125,8 +129,10 @@ object BookList { SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介") searchBook.intro = analyzeRule.getString(intro ?: "") - SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro - ?: "", isHtml = true) + SourceDebug.printLog( + bookSource.bookSourceUrl, 1, searchBook.intro + ?: "", isHtml = true + ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数") searchBook.wordCount = analyzeRule.getString(wordCount ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "") @@ -135,8 +141,10 @@ object BookList { SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节") searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "") - SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle - ?: "") + SourceDebug.printLog( + bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle + ?: "" + ) return searchBook } } @@ -144,19 +152,19 @@ object BookList { } private fun getSearchItem( - item: Any, - analyzeRule: AnalyzeRule, - bookSource: BookSource, - baseUrl: String, - printLog: Boolean, - ruleName: List, - ruleBookUrl: List, - ruleAuthor: List, - ruleKind: List, - ruleCoverUrl: List, - ruleWordCount: List, - ruleIntro: List, - ruleLastChapter: List + item: Any, + analyzeRule: AnalyzeRule, + bookSource: BookSource, + baseUrl: String, + printLog: Boolean, + ruleName: List, + ruleBookUrl: List, + ruleAuthor: List, + ruleKind: List, + ruleCoverUrl: List, + ruleWordCount: List, + ruleIntro: List, + ruleLastChapter: List ): SearchBook? { val searchBook = SearchBook() searchBook.origin = bookSource.bookSourceUrl @@ -179,8 +187,10 @@ object BookList { SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介", printLog) searchBook.intro = analyzeRule.getString(ruleIntro) - SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro - ?: "", printLog, true) + SourceDebug.printLog( + bookSource.bookSourceUrl, 1, searchBook.intro + ?: "", printLog, true + ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数", printLog) searchBook.wordCount = analyzeRule.getString(ruleWordCount) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "", printLog) @@ -189,8 +199,10 @@ object BookList { SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节", printLog) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) - SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle - ?: "", printLog) + SourceDebug.printLog( + bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle + ?: "", printLog + ) return searchBook } return null