|
|
@@ -8,6 +8,7 @@ import io.legado.app.constant.BookType
|
|
|
import io.legado.app.data.entities.BookSource
|
|
|
import io.legado.app.data.entities.rule.*
|
|
|
import io.legado.app.utils.*
|
|
|
+import java.io.InputStream
|
|
|
|
|
|
import java.util.regex.Pattern
|
|
|
|
|
|
@@ -18,16 +19,36 @@ object SourceAnalyzer {
|
|
|
|
|
|
fun jsonToBookSources(json: String): List<BookSource> {
|
|
|
val bookSources = mutableListOf<BookSource>()
|
|
|
- if (json.isJsonArray()) {
|
|
|
- val items: List<Map<String, Any>> = jsonPath.parse(json).read("$")
|
|
|
- for (item in items) {
|
|
|
+ val items: List<Map<String, Any>> = jsonPath.parse(json).read("$")
|
|
|
+ for (item in items) {
|
|
|
+ val jsonItem = jsonPath.parse(item)
|
|
|
+ jsonToBookSource(jsonItem.jsonString())?.let {
|
|
|
+ bookSources.add(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bookSources
|
|
|
+ }
|
|
|
+
|
|
|
+ fun jsonToBookSources(inputStream: InputStream): Result<MutableList<BookSource>> {
|
|
|
+ return kotlin.runCatching {
|
|
|
+ val bookSources = mutableListOf<BookSource>()
|
|
|
+ kotlin.runCatching {
|
|
|
+ val items: List<Map<String, Any>> = jsonPath.parse(inputStream).read("$")
|
|
|
+ for (item in items) {
|
|
|
+ val jsonItem = jsonPath.parse(item)
|
|
|
+ jsonToBookSource(jsonItem.jsonString())?.let {
|
|
|
+ bookSources.add(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.onFailure {
|
|
|
+ val item: Map<String, Any> = jsonPath.parse(inputStream).read("$")
|
|
|
val jsonItem = jsonPath.parse(item)
|
|
|
jsonToBookSource(jsonItem.jsonString())?.let {
|
|
|
bookSources.add(it)
|
|
|
}
|
|
|
}
|
|
|
+ bookSources
|
|
|
}
|
|
|
- return bookSources
|
|
|
}
|
|
|
|
|
|
fun jsonToBookSource(json: String): BookSource? {
|