pull/1295/head
gedoor 3 years ago
parent 21a3fb70f9
commit e5f871ac57
  1. 47
      app/src/main/assets/defaultData/bookSources.json
  2. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  3. 2
      app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt
  4. 14
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  5. 7
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  8. 12
      app/src/main/res/layout/activity_audio_play.xml

@ -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
}
]

@ -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"

@ -1,4 +1,4 @@
package io.legado.app.data.entities
package io.legado.app.data.entities.rule
data class ExploreKind(
val title: String,

@ -84,6 +84,20 @@ interface JsExtensions {
}
}
fun connect(urlStr: String, header: String?): StrResponse {
return runBlocking {
val headerMap = GSON.fromJsonObject<Map<String, String>>(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进制字符串

@ -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) {

@ -193,6 +193,9 @@ class AudioPlayActivity :
playButton()
}
}
observeEventSticky<String>(EventBus.AUDIO_ERROR) {
binding.tvErrorMessage.text = it
}
observeEventSticky<Int>(EventBus.AUDIO_STATE) {
AudioPlay.status = it
if (it == Status.PLAY) {

@ -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

@ -54,6 +54,18 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
<TextView
android:id="@+id/tv_error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:textColor="@color/md_white_1000"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/tv_sub_title" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="match_parent"

Loading…
Cancel
Save