|
|
@ -46,14 +46,15 @@ data class BookSource( |
|
|
|
var ruleBookInfo: BookInfoRule? = null, // 书籍信息页规则 |
|
|
|
var ruleBookInfo: BookInfoRule? = null, // 书籍信息页规则 |
|
|
|
var ruleToc: TocRule? = null, // 目录页规则 |
|
|
|
var ruleToc: TocRule? = null, // 目录页规则 |
|
|
|
var ruleContent: ContentRule? = null // 正文页规则 |
|
|
|
var ruleContent: ContentRule? = null // 正文页规则 |
|
|
|
): Parcelable, JsExtensions { |
|
|
|
) : Parcelable, JsExtensions { |
|
|
|
|
|
|
|
|
|
|
|
override fun hashCode(): Int { |
|
|
|
override fun hashCode(): Int { |
|
|
|
return bookSourceUrl.hashCode() |
|
|
|
return bookSourceUrl.hashCode() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun equals(other: Any?) = if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false |
|
|
|
override fun equals(other: Any?) = |
|
|
|
|
|
|
|
if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
@Throws(Exception::class) |
|
|
|
fun getHeaderMap() = (HashMap<String, String>().apply { |
|
|
|
fun getHeaderMap() = (HashMap<String, String>().apply { |
|
|
|
this[AppConst.UA_NAME] = AppConfig.userAgent |
|
|
|
this[AppConst.UA_NAME] = AppConfig.userAgent |
|
|
@ -71,17 +72,17 @@ data class BookSource( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) as Map<String, String> |
|
|
|
}) as Map<String, String> |
|
|
|
|
|
|
|
|
|
|
|
fun getSearchRule() = ruleSearch ?: SearchRule() |
|
|
|
fun getSearchRule() = ruleSearch ?: SearchRule() |
|
|
|
|
|
|
|
|
|
|
|
fun getExploreRule() = ruleExplore ?: ExploreRule() |
|
|
|
fun getExploreRule() = ruleExplore ?: ExploreRule() |
|
|
|
|
|
|
|
|
|
|
|
fun getBookInfoRule() = ruleBookInfo ?: BookInfoRule() |
|
|
|
fun getBookInfoRule() = ruleBookInfo ?: BookInfoRule() |
|
|
|
|
|
|
|
|
|
|
|
fun getTocRule() = ruleToc ?: TocRule() |
|
|
|
fun getTocRule() = ruleToc ?: TocRule() |
|
|
|
|
|
|
|
|
|
|
|
fun getContentRule() = ruleContent ?: ContentRule() |
|
|
|
fun getContentRule() = ruleContent ?: ContentRule() |
|
|
|
|
|
|
|
|
|
|
|
fun addGroup(group: String) { |
|
|
|
fun addGroup(group: String) { |
|
|
|
bookSourceGroup?.let { |
|
|
|
bookSourceGroup?.let { |
|
|
|
if (!it.contains(group)) { |
|
|
|
if (!it.contains(group)) { |
|
|
@ -91,20 +92,20 @@ data class BookSource( |
|
|
|
bookSourceGroup = group |
|
|
|
bookSourceGroup = group |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun removeGroup(group: String) { |
|
|
|
fun removeGroup(group: String) { |
|
|
|
bookSourceGroup?.splitNotBlank("[,;,;]".toRegex())?.toHashSet()?.let { |
|
|
|
bookSourceGroup?.splitNotBlank("[,;,;]".toRegex())?.toHashSet()?.let { |
|
|
|
it.remove(group) |
|
|
|
it.remove(group) |
|
|
|
bookSourceGroup = TextUtils.join(",", it) |
|
|
|
bookSourceGroup = TextUtils.join(",", it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getExploreKinds() = arrayListOf<ExploreKind>().apply { |
|
|
|
fun getExploreKinds() = arrayListOf<ExploreKind>().apply { |
|
|
|
exploreUrl?.let { |
|
|
|
exploreUrl?.let { urlRule -> |
|
|
|
var a = it |
|
|
|
var a = urlRule |
|
|
|
if (a.isNotBlank()) { |
|
|
|
if (a.isNotBlank()) { |
|
|
|
try { |
|
|
|
kotlin.runCatching { |
|
|
|
if (it.startsWith("<js>", false)) { |
|
|
|
if (urlRule.startsWith("<js>", false)) { |
|
|
|
val aCache = ACache.get(App.INSTANCE, "explore") |
|
|
|
val aCache = ACache.get(App.INSTANCE, "explore") |
|
|
|
a = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
a = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
if (a.isBlank()) { |
|
|
|
if (a.isBlank()) { |
|
|
@ -114,7 +115,7 @@ data class BookSource( |
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
bindings["cache"] = CacheManager |
|
|
|
bindings["cache"] = CacheManager |
|
|
|
a = AppConst.SCRIPT_ENGINE.eval( |
|
|
|
a = AppConst.SCRIPT_ENGINE.eval( |
|
|
|
it.substring(4, it.lastIndexOf("<")), |
|
|
|
urlRule.substring(4, urlRule.lastIndexOf("<")), |
|
|
|
bindings |
|
|
|
bindings |
|
|
|
).toString() |
|
|
|
).toString() |
|
|
|
aCache.put(bookSourceUrl, a) |
|
|
|
aCache.put(bookSourceUrl, a) |
|
|
@ -126,13 +127,13 @@ data class BookSource( |
|
|
|
if (d.size > 1) |
|
|
|
if (d.size > 1) |
|
|
|
add(ExploreKind(d[0], d[1])) |
|
|
|
add(ExploreKind(d[0], d[1])) |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
}.onFailure { |
|
|
|
add(ExploreKind(e.localizedMessage ?: "")) |
|
|
|
add(ExploreKind(it.localizedMessage ?: "")) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 执行JS |
|
|
|
* 执行JS |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -147,60 +148,60 @@ data class BookSource( |
|
|
|
|
|
|
|
|
|
|
|
fun equal(source: BookSource) = |
|
|
|
fun equal(source: BookSource) = |
|
|
|
equal(bookSourceName, source.bookSourceName) |
|
|
|
equal(bookSourceName, source.bookSourceName) |
|
|
|
&& equal(bookSourceUrl, source.bookSourceUrl) |
|
|
|
&& equal(bookSourceUrl, source.bookSourceUrl) |
|
|
|
&& equal(bookSourceGroup, source.bookSourceGroup) |
|
|
|
&& equal(bookSourceGroup, source.bookSourceGroup) |
|
|
|
&& bookSourceType == source.bookSourceType |
|
|
|
&& bookSourceType == source.bookSourceType |
|
|
|
&& equal(bookUrlPattern, source.bookUrlPattern) |
|
|
|
&& equal(bookUrlPattern, source.bookUrlPattern) |
|
|
|
&& equal(bookSourceComment, source.bookSourceComment) |
|
|
|
&& equal(bookSourceComment, source.bookSourceComment) |
|
|
|
&& enabled == source.enabled |
|
|
|
&& enabled == source.enabled |
|
|
|
&& enabledExplore == source.enabledExplore |
|
|
|
&& enabledExplore == source.enabledExplore |
|
|
|
&& equal(header, source.header) |
|
|
|
&& equal(header, source.header) |
|
|
|
&& equal(loginUrl, source.loginUrl) |
|
|
|
&& equal(loginUrl, source.loginUrl) |
|
|
|
&& equal(exploreUrl, source.exploreUrl) |
|
|
|
&& equal(exploreUrl, source.exploreUrl) |
|
|
|
&& equal(searchUrl, source.searchUrl) |
|
|
|
&& equal(searchUrl, source.searchUrl) |
|
|
|
&& getSearchRule() == source.getSearchRule() |
|
|
|
&& getSearchRule() == source.getSearchRule() |
|
|
|
&& getExploreRule() == source.getExploreRule() |
|
|
|
&& getExploreRule() == source.getExploreRule() |
|
|
|
&& getBookInfoRule() == source.getBookInfoRule() |
|
|
|
&& getBookInfoRule() == source.getBookInfoRule() |
|
|
|
&& getTocRule() == source.getTocRule() |
|
|
|
&& getTocRule() == source.getTocRule() |
|
|
|
&& getContentRule() == source.getContentRule() |
|
|
|
&& getContentRule() == source.getContentRule() |
|
|
|
|
|
|
|
|
|
|
|
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) |
|
|
|
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) |
|
|
|
|
|
|
|
|
|
|
|
data class ExploreKind( |
|
|
|
data class ExploreKind( |
|
|
|
var title: String, |
|
|
|
var title: String, |
|
|
|
var url: String? = null |
|
|
|
var url: String? = null |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
class Converters { |
|
|
|
class Converters { |
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule) |
|
|
|
fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun stringToExploreRule(json: String?) = GSON.fromJsonObject<ExploreRule>(json) |
|
|
|
fun stringToExploreRule(json: String?) = GSON.fromJsonObject<ExploreRule>(json) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun searchRuleToString(searchRule: SearchRule?): String = GSON.toJson(searchRule) |
|
|
|
fun searchRuleToString(searchRule: SearchRule?): String = GSON.toJson(searchRule) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun stringToSearchRule(json: String?) = GSON.fromJsonObject<SearchRule>(json) |
|
|
|
fun stringToSearchRule(json: String?) = GSON.fromJsonObject<SearchRule>(json) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun bookInfoRuleToString(bookInfoRule: BookInfoRule?): String = GSON.toJson(bookInfoRule) |
|
|
|
fun bookInfoRuleToString(bookInfoRule: BookInfoRule?): String = GSON.toJson(bookInfoRule) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun stringToBookInfoRule(json: String?) = GSON.fromJsonObject<BookInfoRule>(json) |
|
|
|
fun stringToBookInfoRule(json: String?) = GSON.fromJsonObject<BookInfoRule>(json) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun tocRuleToString(tocRule: TocRule?): String = GSON.toJson(tocRule) |
|
|
|
fun tocRuleToString(tocRule: TocRule?): String = GSON.toJson(tocRule) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun stringToTocRule(json: String?) = GSON.fromJsonObject<TocRule>(json) |
|
|
|
fun stringToTocRule(json: String?) = GSON.fromJsonObject<TocRule>(json) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun contentRuleToString(contentRule: ContentRule?): String = GSON.toJson(contentRule) |
|
|
|
fun contentRuleToString(contentRule: ContentRule?): String = GSON.toJson(contentRule) |
|
|
|
|
|
|
|
|
|
|
|
@TypeConverter |
|
|
|
@TypeConverter |
|
|
|
fun stringToContentRule(json: String?) = GSON.fromJsonObject<ContentRule>(json) |
|
|
|
fun stringToContentRule(json: String?) = GSON.fromJsonObject<ContentRule>(json) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |