From cfbc72cbd3d1dab1171fa16e8cec612e2f13e02e Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 26 Aug 2019 09:59:40 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/model/WebBook.kt | 44 ++++++++++++++++--- .../app/model/webbook/BookChapterList.kt | 41 ++++++++++++++--- .../legado/app/model/webbook/BookContent.kt | 15 +++++-- 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index 972ec4b87..8ed3f812b 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -25,7 +25,13 @@ class WebBook(private val bookSource: BookSource) { ): Coroutine> { return Coroutine.async(scope) { bookSource.getSearchRule().searchUrl?.let { searchUrl -> - val analyzeUrl = AnalyzeUrl(searchUrl, key, page, baseUrl = sourceUrl) + val analyzeUrl = AnalyzeUrl( + ruleUrl = searchUrl, + key = key, + page = page, + baseUrl = sourceUrl, + headerMapF = bookSource.getHeaderMap() + ) val response = analyzeUrl.getResponseAsync().await() BookList.analyzeBookList(response, bookSource, analyzeUrl, isSearch) } ?: arrayListOf() @@ -34,16 +40,29 @@ class WebBook(private val bookSource: BookSource) { fun getBookInfo(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine { return Coroutine.async(scope) { - val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.bookUrl, baseUrl = sourceUrl) + val analyzeUrl = AnalyzeUrl( + book = book, + ruleUrl = book.bookUrl, + baseUrl = sourceUrl, + headerMapF = bookSource.getHeaderMap() + ) val response = analyzeUrl.getResponseAsync().await() BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl) book } } - fun getChapterList(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine> { + fun getChapterList( + book: Book, + scope: CoroutineScope = Coroutine.DEFAULT + ): Coroutine> { return Coroutine.async(scope) { - val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl, baseUrl = book.bookUrl) + val analyzeUrl = AnalyzeUrl( + book = book, + ruleUrl = book.tocUrl, + baseUrl = book.bookUrl, + headerMapF = bookSource.getHeaderMap() + ) val response = analyzeUrl.getResponseAsync().await() BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl) } @@ -56,9 +75,22 @@ class WebBook(private val bookSource: BookSource) { scope: CoroutineScope = Coroutine.DEFAULT ): Coroutine { return Coroutine.async(scope) { - val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = bookChapter.url, baseUrl = book.tocUrl) + val analyzeUrl = + AnalyzeUrl( + book = book, + ruleUrl = bookChapter.url, + baseUrl = book.tocUrl, + headerMapF = bookSource.getHeaderMap() + ) val response = analyzeUrl.getResponseAsync().await() - BookContent.analyzeContent(this, response, book, bookChapter, bookSource, nextChapterUrl) + BookContent.analyzeContent( + this, + response, + book, + bookChapter, + bookSource, + nextChapterUrl + ) } } } \ 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 57c8635ba..56adb8278 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 @@ -44,7 +44,8 @@ object BookChapterList { if (listRule.startsWith("+")) { listRule = listRule.substring(1) } - var chapterData = analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) + var chapterData = + analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) chapterData.chapterList?.let { chapterList.addAll(it) } @@ -52,10 +53,22 @@ object BookChapterList { var nextUrl = chapterData.nextUrl[0] while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { nextUrlList.add(nextUrl) - AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponseAsync().await() + AnalyzeUrl( + 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 = analyzeChapterList( + nextBody, + nextUrl, + tocRule, + listRule, + book, + bookSource + ) + nextUrl = + if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" chapterData.chapterList?.let { chapterList.addAll(it) } @@ -69,7 +82,11 @@ object BookChapterList { } for (item in chapterDataList) { withContext(coroutineScope.coroutineContext) { - val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await() + val nextResponse = AnalyzeUrl( + ruleUrl = item.nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() + ).getResponseAsync().await() val nextChapterData = analyzeChapterList( nextResponse.body() ?: "", item.nextUrl, @@ -126,7 +143,12 @@ object BookChapterList { } } } - SourceDebug.printLog(bookSource.bookSourceUrl, 1, TextUtils.join(",", nextUrlList), printLog) + SourceDebug.printLog( + bookSource.bookSourceUrl, + 1, + TextUtils.join(",", nextUrlList), + printLog + ) } SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) val elements = analyzeRule.getElements(listRule) @@ -146,7 +168,12 @@ object BookChapterList { chapterList.add(bookChapter) } } - SourceDebug.printLog(bookSource.bookSourceUrl, 1, "${chapterList[0].title}${chapterList[0].url}", printLog) + SourceDebug.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 77fb14ebc..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 @@ -51,10 +51,15 @@ object BookContent { == NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl) ) break nextUrlList.add(nextUrl) - AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponseAsync().await() + AnalyzeUrl( + 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 "" + nextUrl = + if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" content.append(contentData.content) } } @@ -66,7 +71,11 @@ object BookContent { } for (item in contentDataList) { withContext(coroutineScope.coroutineContext) { - val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await() + val nextResponse = AnalyzeUrl( + ruleUrl = item.nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() + ).getResponseAsync().await() val nextContentData = analyzeContent( nextResponse.body() ?: "", contentRule,