pull/32/head
kunfei 5 years ago
parent a692416bbf
commit 4a34a78816
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 39
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 43
      app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
  4. 1
      app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
  5. 7
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  6. 2
      app/src/main/java/io/legado/app/model/WebBook.kt
  7. 2
      app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt
  8. 20
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt

@ -14,7 +14,7 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") @Query("select * from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey order by customOrder asc")
fun observeSearch(searchKey: String = ""): DataSource.Factory<Int, BookSource> fun observeSearch(searchKey: String = ""): DataSource.Factory<Int, BookSource>
@Query("select * from book_sources where enabledExplore = 1 order by customOrder asc") @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null order by customOrder asc")
fun liveExplore(): LiveData<List<BookSource>> fun liveExplore(): LiveData<List<BookSource>>
@Query("select bookSourceGroup from book_sources") @Query("select bookSourceGroup from book_sources")

@ -6,14 +6,17 @@ import androidx.room.Ignore
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.userAgent import io.legado.app.constant.AppConst.userAgent
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.help.JsExtensions
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import java.util.* import java.util.*
import javax.script.SimpleBindings
@Parcelize @Parcelize
@Entity( @Entity(
@ -34,7 +37,9 @@ data class BookSource(
var loginUrl: String? = null, // 登录地址 var loginUrl: String? = null, // 登录地址
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重 var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, //发现url
var ruleExplore: String? = null, // 发现规则 var ruleExplore: String? = null, // 发现规则
var searchUrl: String? = null, //搜索url
var ruleSearch: String? = null, // 搜索规则 var ruleSearch: String? = null, // 搜索规则
var ruleBookInfo: String? = null, // 书籍信息页规则 var ruleBookInfo: String? = null, // 书籍信息页规则
var ruleToc: String? = null, // 目录页规则 var ruleToc: String? = null, // 目录页规则
@ -112,4 +117,38 @@ data class BookSource(
return contentRuleV!! return contentRuleV!!
} }
fun getExploreKinds(): ArrayList<ExploreKind>? {
exploreUrl?.let {
var a = it
if (a.isNotBlank()) {
try {
if (it.startsWith("<js>", false)) {
val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl
bindings["java"] = JsExtensions()
a = AppConst.SCRIPT_ENGINE.eval(
a.substring(4, a.lastIndexOf("<")),
bindings
).toString()
}
val exploreKinds = arrayListOf<ExploreKind>()
val b = a.split("(&&|\n)+".toRegex())
b.map { c ->
val d = c.split("::")
if (d.size > 1)
exploreKinds.add(ExploreKind(d[0], d[1]))
}
return exploreKinds
} catch (e: Exception) {
e.printStackTrace()
}
}
}
return null
}
data class ExploreKind(
var title: String,
var url: String
)
} }

@ -1,11 +1,6 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import io.legado.app.constant.AppConst
import io.legado.app.help.JsExtensions
import javax.script.SimpleBindings
data class ExploreRule( data class ExploreRule(
var exploreUrl: String? = null,
override var bookList: String? = null, override var bookList: String? = null,
override var name: String? = null, override var name: String? = null,
override var author: String? = null, override var author: String? = null,
@ -16,40 +11,4 @@ data class ExploreRule(
override var bookUrl: String? = null, override var bookUrl: String? = null,
override var coverUrl: String? = null, override var coverUrl: String? = null,
override var wordCount: String? = null override var wordCount: String? = null
) : BookListRule { ) : BookListRule
fun getExploreKinds(baseUrl: String): ArrayList<ExploreKind>? {
exploreUrl?.let {
var a = it
if (a.isNotBlank()) {
try {
if (it.startsWith("<js>", false)) {
val bindings = SimpleBindings()
bindings["baseUrl"] = baseUrl
bindings["java"] = JsExtensions()
a = AppConst.SCRIPT_ENGINE.eval(
a.substring(4, a.lastIndexOf("<")),
bindings
).toString()
}
val exploreKinds = arrayListOf<ExploreKind>()
val b = a.split("(&&|\n)+".toRegex())
b.map { c ->
val d = c.split("::")
if (d.size > 1)
exploreKinds.add(ExploreKind(d[0], d[1]))
}
return exploreKinds
} catch (e: Exception) {
e.printStackTrace()
}
}
}
return null
}
data class ExploreKind(
var title: String,
var url: String
)
}

@ -1,7 +1,6 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
data class SearchRule( data class SearchRule(
var searchUrl: String? = null,
override var bookList: String? = null, override var bookList: String? = null,
override var name: String? = null, override var name: String? = null,
override var author: String? = null, override var author: String? = null,

@ -110,8 +110,12 @@ object Restore {
source.bookUrlPattern = jsonItem.readString("ruleBookUrlPattern") source.bookUrlPattern = jsonItem.readString("ruleBookUrlPattern")
source.customOrder = jsonItem.readInt("serialNumber") ?: 0 source.customOrder = jsonItem.readInt("serialNumber") ?: 0
source.header = OldRule.uaToHeader(jsonItem.readString("httpUserAgent")) source.header = OldRule.uaToHeader(jsonItem.readString("httpUserAgent"))
source.searchUrl = OldRule.toNewUrl(jsonItem.readString("ruleSearchUrl"))
source.exploreUrl = OldRule.toNewUrl(jsonItem.readString("ruleFindUrl"))
if (source.exploreUrl.isNullOrBlank()) {
source.enabledExplore = false
}
val searchRule = SearchRule( val searchRule = SearchRule(
searchUrl = OldRule.toNewUrl(jsonItem.readString("ruleSearchUrl")),
bookList = jsonItem.readString("ruleSearchList"), bookList = jsonItem.readString("ruleSearchList"),
name = jsonItem.readString("ruleSearchName"), name = jsonItem.readString("ruleSearchName"),
author = jsonItem.readString("ruleSearchAuthor"), author = jsonItem.readString("ruleSearchAuthor"),
@ -123,7 +127,6 @@ object Restore {
) )
source.ruleSearch = GSON.toJson(searchRule) source.ruleSearch = GSON.toJson(searchRule)
val exploreRule = ExploreRule( val exploreRule = ExploreRule(
exploreUrl = OldRule.toNewUrl(jsonItem.readString("ruleFindUrl")),
bookList = jsonItem.readString("ruleFindList"), bookList = jsonItem.readString("ruleFindList"),
name = jsonItem.readString("ruleFindName"), name = jsonItem.readString("ruleFindName"),
author = jsonItem.readString("ruleFindAuthor"), author = jsonItem.readString("ruleFindAuthor"),

@ -23,7 +23,7 @@ class WebBook(val bookSource: BookSource) {
fun searchBook(key: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT) fun searchBook(key: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT)
: Coroutine<List<SearchBook>> { : Coroutine<List<SearchBook>> {
return Coroutine.async(scope) { return Coroutine.async(scope) {
bookSource.getSearchRule().searchUrl?.let { searchUrl -> bookSource.searchUrl?.let { searchUrl ->
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = searchUrl, ruleUrl = searchUrl,
key = key, key = key,

@ -43,7 +43,7 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c
rotate_loading.loadingColor = context.accentColor rotate_loading.loadingColor = context.accentColor
rotate_loading.show() rotate_loading.show()
Coroutine.async(scope) { Coroutine.async(scope) {
item.getExploreRule().getExploreKinds(item.bookSourceUrl) item.getExploreKinds()
}.onSuccess { }.onSuccess {
it?.let { it?.let {
gl_child.visible() gl_child.visible()

@ -140,7 +140,13 @@ class SourceEditActivity : VMBaseActivity<SourceEditViewModel>(R.layout.activity
//搜索 //搜索
with(bookSource?.getSearchRule()) { with(bookSource?.getSearchRule()) {
searchEditList.clear() searchEditList.clear()
searchEditList.add(EditEntity("searchUrl", this?.searchUrl, R.string.rule_search_url)) searchEditList.add(
EditEntity(
"searchUrl",
bookSource?.searchUrl,
R.string.rule_search_url
)
)
searchEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list)) searchEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list))
searchEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) searchEditList.add(EditEntity("name", this?.name, R.string.rule_book_name))
searchEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) searchEditList.add(EditEntity("author", this?.author, R.string.rule_book_author))
@ -182,7 +188,13 @@ class SourceEditActivity : VMBaseActivity<SourceEditViewModel>(R.layout.activity
//发现 //发现
with(bookSource?.getExploreRule()) { with(bookSource?.getExploreRule()) {
findEditList.clear() findEditList.clear()
findEditList.add(EditEntity("exploreUrl", this?.exploreUrl, R.string.rule_find_url)) findEditList.add(
EditEntity(
"exploreUrl",
bookSource?.exploreUrl,
R.string.rule_find_url
)
)
findEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list)) findEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list))
findEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) findEditList.add(EditEntity("name", this?.name, R.string.rule_book_name))
findEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) findEditList.add(EditEntity("author", this?.author, R.string.rule_book_author))
@ -224,7 +236,7 @@ class SourceEditActivity : VMBaseActivity<SourceEditViewModel>(R.layout.activity
for (entity in searchEditList) { for (entity in searchEditList) {
with(entity) { with(entity) {
when (key) { when (key) {
"searchUrl" -> searchRule.searchUrl = value "searchUrl" -> source.searchUrl = value
"bookList" -> searchRule.bookList = value "bookList" -> searchRule.bookList = value
"name" -> searchRule.name = value "name" -> searchRule.name = value
"author" -> searchRule.author = value "author" -> searchRule.author = value
@ -241,7 +253,7 @@ class SourceEditActivity : VMBaseActivity<SourceEditViewModel>(R.layout.activity
for (entity in findEditList) { for (entity in findEditList) {
with(entity) { with(entity) {
when (key) { when (key) {
"exploreUrl" -> exploreRule.exploreUrl = value "exploreUrl" -> source.exploreUrl = value
"bookList" -> exploreRule.bookList = value "bookList" -> exploreRule.bookList = value
"name" -> exploreRule.name = value "name" -> exploreRule.name = value
"author" -> exploreRule.author = value "author" -> exploreRule.author = value

Loading…
Cancel
Save