From 9e1ed46a22eb40d3774c87c9a1a420cb09a84cb1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 30 Sep 2021 14:12:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 13 +++++-------- app/src/main/java/io/legado/app/model/rss/Rss.kt | 4 ++-- .../io/legado/app/model/webBook/BookChapterList.kt | 4 ++-- .../java/io/legado/app/model/webBook/BookContent.kt | 4 ++-- .../java/io/legado/app/model/webBook/WebBook.kt | 12 ++++++------ .../java/io/legado/app/service/AudioPlayService.kt | 4 +++- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index df8a6984e..d95b950fc 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -654,7 +654,7 @@ class AnalyzeRule( override fun ajax(urlStr: String): String? { return runBlocking { kotlin.runCatching { - val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source) + val analyzeUrl = AnalyzeUrl(urlStr, source = source, ruleData = book) analyzeUrl.getStrResponse().body }.onFailure { log("ajax(${urlStr}) error\n${it.stackTraceToString()}") diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 22ca6b687..c90c20715 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -7,8 +7,8 @@ import com.bumptech.glide.load.model.LazyHeaders import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppConst.UA_NAME import io.legado.app.constant.AppPattern.JS_PATTERN -import io.legado.app.data.entities.BaseBook import io.legado.app.data.entities.BaseSource +import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.AppConfig import io.legado.app.help.CacheManager @@ -36,10 +36,9 @@ class AnalyzeUrl( val speakText: String? = null, val speakSpeed: Int? = null, var baseUrl: String = "", - val book: BaseBook? = null, - val chapter: BookChapter? = null, - private val ruleData: RuleDataInterface? = null, private val source: BaseSource? = null, + private val ruleData: RuleDataInterface? = null, + private val chapter: BookChapter? = null, headerMapF: Map? = null, ) : JsExtensions { companion object { @@ -239,7 +238,7 @@ class AnalyzeUrl( bindings["key"] = key bindings["speakText"] = speakText bindings["speakSpeed"] = speakSpeed - bindings["book"] = book + bindings["book"] = ruleData as? Book bindings["source"] = source bindings["result"] = result return SCRIPT_ENGINE.eval(jsStr, bindings) @@ -247,14 +246,13 @@ class AnalyzeUrl( fun put(key: String, value: String): String { chapter?.putVariable(key, value) - ?: book?.putVariable(key, value) ?: ruleData?.putVariable(key, value) return value } fun get(key: String): String { when (key) { - "bookName" -> book?.let { + "bookName" -> (ruleData as? Book)?.let { return it.name } "title" -> chapter?.let { @@ -262,7 +260,6 @@ class AnalyzeUrl( } } return chapter?.variableMap?.get(key) - ?: book?.variableMap?.get(key) ?: ruleData?.variableMap?.get(key) ?: "" } diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index e36eb9fcc..72e353009 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -38,8 +38,8 @@ object Rss { val analyzeUrl = AnalyzeUrl( sortUrl, page = page, - ruleData = ruleData, source = rssSource, + ruleData = ruleData, headerMapF = rssSource.getHeaderMap() ) val body = analyzeUrl.getStrResponse().body @@ -66,8 +66,8 @@ object Rss { val analyzeUrl = AnalyzeUrl( rssArticle.link, baseUrl = rssArticle.origin, - ruleData = rssArticle, source = rssSource, + ruleData = rssArticle, headerMapF = rssSource.getHeaderMap() ) val body = analyzeUrl.getStrResponse().body 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 2a4217c15..42671fe54 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 @@ -64,8 +64,8 @@ object BookChapterList { nextUrlList.add(nextUrl) AnalyzeUrl( ruleUrl = nextUrl, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap() ).getStrResponse().body?.let { nextBody -> chapterData = analyzeChapterList( @@ -86,8 +86,8 @@ object BookChapterList { val urlStr = chapterData.second[it] val analyzeUrl = AnalyzeUrl( ruleUrl = urlStr, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap() ) val res = analyzeUrl.getStrResponse() 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 c4b3d87eb..d570aa27d 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 @@ -69,8 +69,8 @@ object BookContent { scope.ensureActive() val res = AnalyzeUrl( ruleUrl = nextUrl, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap() ).getStrResponse() res.body?.let { nextBody -> @@ -92,8 +92,8 @@ object BookContent { val urlStr = contentData.second[it] val analyzeUrl = AnalyzeUrl( ruleUrl = urlStr, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap() ) val res = analyzeUrl.getStrResponse() diff --git a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt index 1c155f649..a662fb210 100644 --- a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt @@ -71,8 +71,8 @@ object WebBook { page = page, baseUrl = bookSource.bookSourceUrl, headerMapF = bookSource.getHeaderMap(true), - book = variableBook, - source = bookSource + source = bookSource, + ruleData = variableBook, ) var res = analyzeUrl.getStrResponse() //检测书源是否已登录 @@ -120,8 +120,8 @@ object WebBook { ruleUrl = url, page = page, baseUrl = bookSource.bookSourceUrl, - book = variableBook, source = bookSource, + ruleData = variableBook, headerMapF = bookSource.getHeaderMap(true) ) var res = analyzeUrl.getStrResponse() @@ -178,8 +178,8 @@ object WebBook { val analyzeUrl = AnalyzeUrl( ruleUrl = book.bookUrl, baseUrl = bookSource.bookSourceUrl, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap(true) ) var res = analyzeUrl.getStrResponse() @@ -235,8 +235,8 @@ object WebBook { val analyzeUrl = AnalyzeUrl( ruleUrl = book.tocUrl, baseUrl = book.bookUrl, - book = book, source = bookSource, + ruleData = book, headerMapF = bookSource.getHeaderMap(true) ) var res = analyzeUrl.getStrResponse() @@ -299,8 +299,8 @@ object WebBook { val analyzeUrl = AnalyzeUrl( ruleUrl = bookChapter.getAbsoluteURL(), baseUrl = book.tocUrl, - book = book, source = bookSource, + ruleData = book, chapter = bookChapter, headerMapF = bookSource.getHeaderMap(true) ) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 027efdbe4..d3a6ecc0a 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -130,8 +130,10 @@ class AudioPlayService : BaseService(), upPlayProgressJob?.cancel() val analyzeUrl = AnalyzeUrl( url, + source = AudioPlay.bookSource, + ruleData = AudioPlay.book, + chapter = AudioPlay.durChapter, headerMapF = AudioPlay.headers(true), - source = AudioPlay.bookSource ) val uri = Uri.parse(analyzeUrl.url) val mediaSource = ExoPlayerHelper