|
|
|
@ -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,7 +19,6 @@ 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 jsonItem = jsonPath.parse(item) |
|
|
|
@ -26,10 +26,31 @@ object SourceAnalyzer { |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun jsonToBookSource(json: String): BookSource? { |
|
|
|
|
val source = BookSource() |
|
|
|
|
val sourceAny = GSON.fromJsonObject<BookSourceAny>(json.trim()) |
|
|
|
|