Kotlinx.serialization migration for several sources (#7723)
* en.MangaPark: kotlinx.serialization migration * Bato.to: Kotlinx.serialization migration * Dynasty: Kotlinx.serialization * ReadM: kotlinx.serialization migration * Bato.to: Comment out code that was untested
This commit is contained in:
parent
8a7122a2fc
commit
759a2123c1
@ -1,11 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
|
||||
ext {
|
||||
extName = 'Bato.to'
|
||||
pkgNameSuffix = 'all.batoto'
|
||||
extClass = '.BatoToFactory'
|
||||
extVersionCode = 12
|
||||
extVersionCode = 13
|
||||
libVersion = '1.2'
|
||||
containsNsfw = true
|
||||
}
|
||||
|
@ -11,17 +11,20 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Calendar
|
||||
import java.util.concurrent.TimeUnit
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
|
||||
open class BatoTo(
|
||||
override val lang: String,
|
||||
@ -32,7 +35,7 @@ open class BatoTo(
|
||||
override val baseUrl: String = "https://bato.to"
|
||||
|
||||
override val supportsLatest = true
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
@ -110,7 +113,8 @@ open class BatoTo(
|
||||
}
|
||||
|
||||
with(genreFilter) {
|
||||
url.addQueryParameter("genres", included.joinToString(",") + "|" + excluded.joinToString(",")
|
||||
url.addQueryParameter(
|
||||
"genres", included.joinToString(",") + "|" + excluded.joinToString(",")
|
||||
)
|
||||
}
|
||||
|
||||
@ -294,16 +298,14 @@ open class BatoTo(
|
||||
val script = document.select("script").html()
|
||||
|
||||
if (script.contains("var images =")) {
|
||||
val imgJson = JSONObject(script.substringAfter("var images = ").substringBefore(";"))
|
||||
val imgNames = imgJson.names()
|
||||
/*
|
||||
* During kotlinx.serialization migration, the pre-existing code seemed to not work
|
||||
* Could not find a case where code would run in practice, so it was commented out.
|
||||
*/
|
||||
throw RuntimeException("Unexpected Branch: Please File A Bug Report describing this issue")
|
||||
// val imgJson = json.parseToJsonElement(script.substringAfter("var images = ").substringBefore(";")).jsonObject
|
||||
// imgJson.keys.forEachIndexed { i, s -> pages.add(Page(i, imageUrl = imgJson[s]!!.jsonPrimitive.content)) }
|
||||
|
||||
if (imgNames != null) {
|
||||
for (i in 0 until imgNames.length()) {
|
||||
val imgKey = imgNames.getString(i)
|
||||
val imgUrl = imgJson.getString(imgKey)
|
||||
pages.add(Page(i, "", imgUrl))
|
||||
}
|
||||
}
|
||||
} else if (script.contains("const server =")) { // bato.to
|
||||
val duktape = Duktape.create()
|
||||
val encryptedServer = script.substringAfter("const server = ").substringBefore(";")
|
||||
@ -312,21 +314,13 @@ open class BatoTo(
|
||||
val server = duktape.evaluate(decryptScript).toString().replace("\"", "")
|
||||
duktape.close()
|
||||
|
||||
val imgArray = JSONArray(script.substringAfter("const images = ").substringBefore(";"))
|
||||
if (imgArray != null) {
|
||||
json.parseToJsonElement(script.substringAfter("const images = ").substringBefore(";")).jsonArray
|
||||
.forEachIndexed { i, it ->
|
||||
val imgUrl = it.jsonPrimitive.content
|
||||
if (script.contains("bato.to/images")) {
|
||||
for (i in 0 until imgArray.length()) {
|
||||
val imgUrl = imgArray.get(i)
|
||||
pages.add(Page(i, "", "$imgUrl"))
|
||||
}
|
||||
pages.add(Page(i, imageUrl = imgUrl))
|
||||
} else {
|
||||
for (i in 0 until imgArray.length()) {
|
||||
val imgUrl = imgArray.get(i)
|
||||
if (server.startsWith("http"))
|
||||
pages.add(Page(i, "", "${server}$imgUrl"))
|
||||
else
|
||||
pages.add(Page(i, "", "https:${server}$imgUrl"))
|
||||
}
|
||||
pages.add(Page(i, imageUrl = if (server.startsWith("http")) "${server}$imgUrl" else "https:${server}$imgUrl"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -367,10 +361,12 @@ open class BatoTo(
|
||||
val selected: String
|
||||
get() = options[state].value
|
||||
}
|
||||
|
||||
abstract class CheckboxGroupFilter(name: String, options: List<CheckboxFilterOption>) : Filter.Group<CheckboxFilterOption>(name, options) {
|
||||
val selected: List<String>
|
||||
get() = state.filter { it.state }.map { it.value }
|
||||
}
|
||||
|
||||
abstract class TriStateGroupFilter(name: String, options: List<TriStateFilterOption>) : Filter.Group<TriStateFilterOption>(name, options) {
|
||||
val included: List<String>
|
||||
get() = state.filter { it.isIncluded() }.map { it.value }
|
||||
@ -378,6 +374,7 @@ open class BatoTo(
|
||||
val excluded: List<String>
|
||||
get() = state.filter { it.isExcluded() }.map { it.value }
|
||||
}
|
||||
|
||||
abstract class TextFilter(name: String) : Filter.Text(name)
|
||||
|
||||
class SortFilter(options: List<SelectFilterOption>, default: Int) : SelectFilter("Sort By", options, default)
|
||||
|
@ -1,11 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
|
||||
ext {
|
||||
extName = 'Dynasty'
|
||||
pkgNameSuffix = 'en.dynasty'
|
||||
extClass = '.DynastyFactory'
|
||||
extVersionCode = 13
|
||||
extVersionCode = 14
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
@ -10,15 +10,19 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.json.JSONArray
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import org.jsoup.nodes.Node
|
||||
import org.jsoup.nodes.TextNode
|
||||
import org.jsoup.select.Elements
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.ArrayList
|
||||
import java.util.Locale
|
||||
@ -43,6 +47,8 @@ abstract class DynastyScans : ParsedHttpSource() {
|
||||
|
||||
private var _valid: Validate = Validate(false, -1)
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
override fun popularMangaRequest(page: Int): Request {
|
||||
return GET(popularMangaInitialUrl(), headers)
|
||||
}
|
||||
@ -189,19 +195,16 @@ abstract class DynastyScans : ParsedHttpSource() {
|
||||
}
|
||||
|
||||
override fun pageListParse(document: Document): List<Page> {
|
||||
val pages = mutableListOf<Page>()
|
||||
try {
|
||||
return try {
|
||||
val imageUrl = document.select("script").last().html().substringAfter("var pages = [").substringBefore("];")
|
||||
val imageUrls = JSONArray("[$imageUrl]")
|
||||
|
||||
(0 until imageUrls.length())
|
||||
.map { imageUrls.getJSONObject(it) }
|
||||
.map { baseUrl + it.get("image") }
|
||||
.forEach { pages.add(Page(pages.size, "", it)) }
|
||||
json.parseToJsonElement("[$imageUrl]").jsonArray.mapIndexed { index, it ->
|
||||
Page(index, imageUrl = "$baseUrl${it.jsonObject["image"]!!.jsonPrimitive.content}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
emptyList()
|
||||
}
|
||||
return pages
|
||||
}
|
||||
|
||||
class InternalList(nodes: List<Node>, type: String) : ArrayList<String>() {
|
||||
|
@ -1,11 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
|
||||
ext {
|
||||
extName = 'MangaPark'
|
||||
pkgNameSuffix = 'en.mangapark'
|
||||
extClass = '.MangaPark'
|
||||
extVersionCode = 20
|
||||
extVersionCode = 21
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
@ -13,14 +13,18 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.json.JSONArray
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
@ -36,7 +40,7 @@ class MangaPark : ConfigurableSource, ParsedHttpSource() {
|
||||
override val baseUrl = "https://v2.mangapark.net"
|
||||
|
||||
private val nextPageSelector = ".paging:not(.order) > li:last-child > a"
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
private val dateFormat = SimpleDateFormat("MMM d, yyyy, HH:mm a", Locale.ENGLISH)
|
||||
private val dateFormatTimeOnly = SimpleDateFormat("HH:mm a", Locale.ENGLISH)
|
||||
|
||||
@ -278,9 +282,11 @@ class MangaPark : ConfigurableSource, ParsedHttpSource() {
|
||||
override fun pageListParse(response: Response): List<Page> {
|
||||
val obj = objRegex.find(response.body!!.string())?.groupValues?.get(1)
|
||||
?: throw Exception("_load_pages not found - ${response.request.url}")
|
||||
val jsonArray = JSONArray(obj)
|
||||
return (0 until jsonArray.length()).map { i -> jsonArray.getJSONObject(i).getString("u") }
|
||||
.mapIndexed { i, url -> Page(i, "", if (url.startsWith("//")) "https://$url" else url) }
|
||||
|
||||
return json.parseToJsonElement(obj).jsonArray.mapIndexed { i, it ->
|
||||
val url = it.jsonObject["u"]!!.jsonPrimitive.content
|
||||
Page(i, imageUrl = if (url.startsWith("//")) "https://$url" else url)
|
||||
}
|
||||
}
|
||||
|
||||
override fun pageListParse(document: Document): List<Page> = throw UnsupportedOperationException("Not used")
|
||||
|
@ -1,11 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
|
||||
ext {
|
||||
extName = 'ReadM'
|
||||
pkgNameSuffix = 'en.readm'
|
||||
extClass = '.ReadM'
|
||||
extVersionCode = 5
|
||||
extVersionCode = 6
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
@ -8,13 +8,17 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.json.JSONObject
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Calendar
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@ -32,6 +36,7 @@ class ReadM : ParsedHttpSource() {
|
||||
.followRedirects(true)
|
||||
.build()
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
// Popular
|
||||
|
||||
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/popular-manga/$page", headers)
|
||||
@ -76,20 +81,14 @@ class ReadM : ParsedHttpSource() {
|
||||
override fun searchMangaSelector(): String = throw Exception("Not used")
|
||||
override fun searchMangaFromElement(element: Element): SManga = throw Exception("Not used")
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
val json = JSONObject(response.body!!.string()).getJSONArray("manga")
|
||||
|
||||
val manga = (0 until json.length()).asSequence().toList().map { it ->
|
||||
override fun searchMangaParse(response: Response) = json.parseToJsonElement(response.body!!.string()).jsonObject["manga"]?.jsonArray?.map {
|
||||
val obj = it.jsonObject
|
||||
SManga.create().apply {
|
||||
val jsonObject = json.getJSONObject(it)
|
||||
title = jsonObject.getString("title")
|
||||
url = jsonObject.getString("url")
|
||||
thumbnail_url = jsonObject.getString("image")
|
||||
}
|
||||
}
|
||||
|
||||
return MangasPage(manga, false)
|
||||
title = obj["title"]!!.jsonPrimitive.content
|
||||
url = obj["url"]!!.jsonPrimitive.content
|
||||
thumbnail_url = "$baseUrl${obj["image"]!!.jsonPrimitive.content}"
|
||||
}
|
||||
}.let { MangasPage(it ?: emptyList(), false) }
|
||||
|
||||
// Details
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user