|
|
@ -1,13 +1,92 @@ |
|
|
|
package io.legado.app.help.storage |
|
|
|
package io.legado.app.help.storage |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jayway.jsonpath.JsonPath |
|
|
|
|
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
|
|
|
import io.legado.app.data.entities.rule.* |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
|
|
|
|
import io.legado.app.utils.readInt |
|
|
|
|
|
|
|
import io.legado.app.utils.readString |
|
|
|
import java.util.regex.Pattern |
|
|
|
import java.util.regex.Pattern |
|
|
|
|
|
|
|
|
|
|
|
object OldRule { |
|
|
|
object OldRule { |
|
|
|
private val headerPattern = Pattern.compile("@Header:\\{.+?\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val headerPattern = Pattern.compile("@Header:\\{.+?\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE) |
|
|
|
|
|
|
|
|
|
|
|
fun toNewUrl(oldUrl: String?): String? { |
|
|
|
|
|
|
|
|
|
|
|
fun jsonToBookSource(json: String): BookSource? { |
|
|
|
|
|
|
|
var source: BookSource? = null |
|
|
|
|
|
|
|
runCatching { |
|
|
|
|
|
|
|
source = GSON.fromJsonObject<BookSource>(json) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
runCatching { |
|
|
|
|
|
|
|
source ?: let { |
|
|
|
|
|
|
|
source = BookSource().apply { |
|
|
|
|
|
|
|
val jsonItem = JsonPath.parse(json) |
|
|
|
|
|
|
|
bookSourceUrl = jsonItem.readString("bookSourceUrl") ?: "" |
|
|
|
|
|
|
|
bookSourceName = jsonItem.readString("bookSourceName") ?: "" |
|
|
|
|
|
|
|
bookSourceGroup = jsonItem.readString("bookSourceGroup") ?: "" |
|
|
|
|
|
|
|
loginUrl = jsonItem.readString("loginUrl") |
|
|
|
|
|
|
|
bookUrlPattern = jsonItem.readString("ruleBookUrlPattern") |
|
|
|
|
|
|
|
customOrder = jsonItem.readInt("serialNumber") ?: 0 |
|
|
|
|
|
|
|
header = uaToHeader(jsonItem.readString("httpUserAgent")) |
|
|
|
|
|
|
|
searchUrl = toNewUrl(jsonItem.readString("ruleSearchUrl")) |
|
|
|
|
|
|
|
exploreUrl = toNewUrl(jsonItem.readString("ruleFindUrl")) |
|
|
|
|
|
|
|
if (exploreUrl.isNullOrBlank()) { |
|
|
|
|
|
|
|
enabledExplore = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val searchRule = SearchRule( |
|
|
|
|
|
|
|
bookList = jsonItem.readString("ruleSearchList"), |
|
|
|
|
|
|
|
name = jsonItem.readString("ruleSearchName"), |
|
|
|
|
|
|
|
author = jsonItem.readString("ruleSearchAuthor"), |
|
|
|
|
|
|
|
intro = jsonItem.readString("ruleSearchIntroduce"), |
|
|
|
|
|
|
|
kind = jsonItem.readString("ruleSearchKind"), |
|
|
|
|
|
|
|
bookUrl = jsonItem.readString("ruleSearchNoteUrl"), |
|
|
|
|
|
|
|
coverUrl = jsonItem.readString("ruleSearchCoverUrl"), |
|
|
|
|
|
|
|
lastChapter = jsonItem.readString("ruleSearchLastChapter") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ruleSearch = GSON.toJson(searchRule) |
|
|
|
|
|
|
|
val exploreRule = ExploreRule( |
|
|
|
|
|
|
|
bookList = jsonItem.readString("ruleFindList"), |
|
|
|
|
|
|
|
name = jsonItem.readString("ruleFindName"), |
|
|
|
|
|
|
|
author = jsonItem.readString("ruleFindAuthor"), |
|
|
|
|
|
|
|
intro = jsonItem.readString("ruleFindIntroduce"), |
|
|
|
|
|
|
|
kind = jsonItem.readString("ruleFindKind"), |
|
|
|
|
|
|
|
bookUrl = jsonItem.readString("ruleFindNoteUrl"), |
|
|
|
|
|
|
|
coverUrl = jsonItem.readString("ruleFindCoverUrl"), |
|
|
|
|
|
|
|
lastChapter = jsonItem.readString("ruleFindLastChapter") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ruleExplore = GSON.toJson(exploreRule) |
|
|
|
|
|
|
|
val bookInfoRule = BookInfoRule( |
|
|
|
|
|
|
|
init = jsonItem.readString("ruleBookInfoInit"), |
|
|
|
|
|
|
|
name = jsonItem.readString("ruleBookName"), |
|
|
|
|
|
|
|
author = jsonItem.readString("ruleBookAuthor"), |
|
|
|
|
|
|
|
intro = jsonItem.readString("ruleIntroduce"), |
|
|
|
|
|
|
|
kind = jsonItem.readString("ruleBookKind"), |
|
|
|
|
|
|
|
coverUrl = jsonItem.readString("ruleCoverUrl"), |
|
|
|
|
|
|
|
lastChapter = jsonItem.readString("ruleBookLastChapter"), |
|
|
|
|
|
|
|
tocUrl = jsonItem.readString("ruleChapterUrl") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ruleBookInfo = GSON.toJson(bookInfoRule) |
|
|
|
|
|
|
|
val chapterRule = TocRule( |
|
|
|
|
|
|
|
chapterList = jsonItem.readString("ruleChapterList"), |
|
|
|
|
|
|
|
chapterName = jsonItem.readString("ruleChapterName"), |
|
|
|
|
|
|
|
chapterUrl = jsonItem.readString("ruleContentUrl"), |
|
|
|
|
|
|
|
nextTocUrl = jsonItem.readString("ruleChapterUrlNext") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ruleToc = GSON.toJson(chapterRule) |
|
|
|
|
|
|
|
val contentRule = ContentRule( |
|
|
|
|
|
|
|
content = jsonItem.readString("ruleBookContent"), |
|
|
|
|
|
|
|
nextContentUrl = jsonItem.readString("ruleContentUrlNext") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
ruleContent = GSON.toJson(contentRule) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return source |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun toNewUrl(oldUrl: String?): String? { |
|
|
|
if (oldUrl == null) return null |
|
|
|
if (oldUrl == null) return null |
|
|
|
val map = HashMap<String, String>() |
|
|
|
val map = HashMap<String, String>() |
|
|
|
var url: String = oldUrl |
|
|
|
var url: String = oldUrl |
|
|
@ -46,9 +125,10 @@ object OldRule { |
|
|
|
return url |
|
|
|
return url |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun uaToHeader(ua: String?): String? { |
|
|
|
private fun uaToHeader(ua: String?): String? { |
|
|
|
if (ua.isNullOrEmpty()) return null |
|
|
|
if (ua.isNullOrEmpty()) return null |
|
|
|
val map = mapOf(Pair("user_agent", ua)) |
|
|
|
val map = mapOf(Pair("user_agent", ua)) |
|
|
|
return GSON.toJson(map) |
|
|
|
return GSON.toJson(map) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |