diff --git a/app/src/main/assets/defaultData/bookSources.json b/app/src/main/assets/defaultData/bookSources.json new file mode 100644 index 000000000..dedc163e0 --- /dev/null +++ b/app/src/main/assets/defaultData/bookSources.json @@ -0,0 +1,47 @@ +[ + { + "bookSourceComment": "", + "bookSourceGroup": "听书", + "bookSourceName": "消消乐听书", + "bookSourceType": 1, + "bookSourceUrl": "https://www.kaixin7days.com", + "customOrder": -31077, + "enabled": true, + "enabledExplore": true, + "exploreUrl": "@js:var header = source.getLoginHeader()\nvar json = \"\"\nvar j = null\nif (header != null) {\n json = java.connect('https://www.kaixin7days.com/book-service/bookMgt/getBookCategroy,{\"method\":\"POST\",\"body\":{}}', header).body()\n j = JSON.parse(json)\n}\nif (j == null || j.statusCode == 301) {\n json = java.connect('https://www.kaixin7days.com/visitorLogin,{\"method\":\"POST\", \"body\":{} }').body()\n j = JSON.parse(json)\n var accessToken = {\n Authorization: \"Bearer \" + j.content.accessToken\n }\n header = JSON.stringify(accessToken)\n source.putLoginHeader(header)\n json = java.connect('https://www.kaixin7days.com/book-service/bookMgt/getBookCategroy,{\"method\":\"POST\",\"body\":{} }', header).body()\n j = JSON.parse(json)\n}\nvar fls = j.content\nvar fx = []\nfor (var i = 0; i < fls.length; i++) {\n fx.push({\n title: fls[i].categoryName,\n url: '/book-service/bookMgt/getAllBookByCategroyId,{\"method\":\"POST\",\"body\":{\"categoryIds\": \"' + fls[i].associationCategoryIDs + '\",\"pageNum\": {{searchPage}},\"pageSize\": 100}}'\n })\n}\nfx", + "lastUpdateTime": 1630595885516, + "loginCheckJs": "var strRes = result\nvar c = JSON.parse(result.body())\nif (c.statusCode == 301) {\n var loginInfo = source.getLoginInfo()\n var dl = null\n if (loginInfo) {\n dl = java.connect('https://www.kaixin7days.com/login,{\"method\":\"POST\",\"body\":' + loginInfo + '}').body()\n } else {\n dl = java.connect('https://www.kaixin7days.com/visitorLogin,{\"method\":\"POST\",\"body\":{}}').body()\n }\n c = JSON.parse(dl)\n var accessToken = {\n Authorization: \"Bearer \" + c.content.accessToken\n }\n var header = JSON.stringify(accessToken)\n source.putLoginHeader(header)\n strRes = java.connect(url, header)\n}\nstrRes", + "loginUi": [ + { + "name": "telephone", + "type": "text" + }, + { + "name": "password", + "type": "password" + } + ], + "loginUrl": "var loginInfo = source.getLoginInfo()\nvar json = java.connect('https://www.kaixin7days.com/login,{\"method\":\"POST\",\"body\":' + loginInfo + '}').body()\nvar loginRes = JSON.parse(json)\nvar header = null\nif (loginRes.statusCode == 200) {\n var accessToken = {\n Authorization: \"Bearer \" + loginRes.content.accessToken\n }\n header = JSON.stringify(accessToken)\n source.putLoginHeader(header)\n}\nheader", + "respondTime": 180000, + "ruleBookInfo": {}, + "ruleContent": { + "content": "" + }, + "ruleExplore": { + "author": "$.author", + "bookList": "$.content.content", + "bookUrl": "$.id@js:'https://www.kaixin7days.com/book-service/bookMgt/getAllChapterByBookId,{\"bookId\": \"'+result+'\",\"pageNum\": 1,\"pageSize\": 100}'", + "coverUrl": "$.cover@js:var cover = JSON.parse(result);'https://www.shuidi.online:9021/fileMgt/getPicture?filePath='+cover.storeFilePath", + "intro": "$.desc", + "lastChapter": "$.newestChapter", + "name": "$.title" + }, + "ruleSearch": {}, + "ruleToc": { + "chapterList": "$.content.content", + "chapterName": "$.chapterTitle", + "chapterUrl": "@js:\"https://www.shuidi.online:9021/fileMgt/getAudioByChapterId?bookId=\"\n + java.getString(\"$.bookId\") + \"&chapterId=\" + java.getString(\"$.id\")\n + \"&pageNum=1&pageSize=50&{{var header = JSON.parse(source.getLoginHeader());'Authorization=' + header.Authorization}}\"" + }, + "weight": 0 + } +] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 5257596fa..7b53c4cbd 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -17,6 +17,7 @@ object EventBus { const val AUDIO_PROGRESS = "audioProgress" const val AUDIO_SIZE = "audioSize" const val AUDIO_SPEED = "audioSpeed" + const val AUDIO_ERROR = "audioError" const val NOTIFY_MAIN = "notifyMain" const val WEB_SERVICE = "webService" const val UP_DOWNLOAD = "upDownload" diff --git a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt similarity index 95% rename from app/src/main/java/io/legado/app/data/entities/ExploreKind.kt rename to app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt index 5a44bd419..49fe4937a 100644 --- a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt @@ -1,4 +1,4 @@ -package io.legado.app.data.entities +package io.legado.app.data.entities.rule data class ExploreKind( val title: String, diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index ee5efb4b8..a2fd4e3b2 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -84,6 +84,20 @@ interface JsExtensions { } } + fun connect(urlStr: String, header: String?): StrResponse { + return runBlocking { + val headerMap = GSON.fromJsonObject>(header) + val analyzeUrl = AnalyzeUrl(urlStr, headerMapF = headerMap) + kotlin.runCatching { + analyzeUrl.getStrResponse(urlStr) + }.onFailure { + it.printStackTrace() + }.getOrElse { + StrResponse(analyzeUrl.url, it.localizedMessage) + } + } + } + /** * 实现16进制字符串转文件 * @param content 需要转成文件的16进制字符串 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 a614e89c0..db298b12a 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -222,7 +222,12 @@ class AudioPlayService : BaseService(), super.onPlayerError(error) AudioPlay.status = Status.STOP postEvent(EventBus.AUDIO_STATE, Status.STOP) - toastOnUi("error: ${error.errorCode} ${error.errorCodeName} $url") + error.printStackTrace() + } + + override fun onPlayerErrorChanged(error: PlaybackException?) { + super.onPlayerErrorChanged(error) + postEvent(EventBus.AUDIO_ERROR, error?.localizedMessage) } private fun setTimer(minute: Int) { diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 5474bc1ed..03924dc28 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -193,6 +193,9 @@ class AudioPlayActivity : playButton() } } + observeEventSticky(EventBus.AUDIO_ERROR) { + binding.tvErrorMessage.text = it + } observeEventSticky(EventBus.AUDIO_STATE) { AudioPlay.status = it if (it == Status.PLAY) { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index b923e984a..baa991268 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -12,7 +12,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource -import io.legado.app.data.entities.ExploreKind +import io.legado.app.data.entities.rule.ExploreKind import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFindBookBinding import io.legado.app.help.coroutine.Coroutine diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index 20c64aba6..b7e232627 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -54,6 +54,18 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/title_bar" /> + +