diff --git a/src/all/mango/build.gradle b/src/all/mango/build.gradle index 2970d5089..f1da8de87 100644 --- a/src/all/mango/build.gradle +++ b/src/all/mango/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Mango' diff --git a/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt b/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt index 81286964a..1fbbe78ce 100644 --- a/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt +++ b/src/all/mango/src/eu/kanade/tachiyomi/extension/all/mango/Mango.kt @@ -4,11 +4,6 @@ import android.app.Application import android.content.SharedPreferences import android.text.InputType import android.widget.Toast -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.google.gson.Gson -import com.google.gson.JsonObject -import com.google.gson.JsonSyntaxException import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST @@ -22,6 +17,13 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import info.debatty.java.stringsimilarity.JaroWinkler import info.debatty.java.stringsimilarity.Levenshtein +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.long import okhttp3.Dns import okhttp3.FormBody import okhttp3.Headers @@ -33,6 +35,7 @@ import okhttp3.Response import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy import java.io.IOException class Mango : ConfigurableSource, HttpSource() { @@ -43,18 +46,18 @@ class Mango : ConfigurableSource, HttpSource() { // Our popular manga are just our library of manga override fun popularMangaParse(response: Response): MangasPage { val result = try { - gson.fromJson(response.body!!.string()) - } catch (e: JsonSyntaxException) { + json.decodeFromString(response.body!!.string()) + } catch (e: Exception) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") } - val mangas = result["titles"].asJsonArray + val mangas = result["titles"]!!.jsonArray return MangasPage( - mangas.asJsonArray.map { + mangas.jsonArray.map { SManga.create().apply { - url = "/book/" + it["id"].asString - title = it["display_name"].asString - thumbnail_url = baseUrl + it["cover_url"].asString + url = "/book/" + it.jsonObject["id"]!!.jsonPrimitive.content + title = it.jsonObject["display_name"]!!.jsonPrimitive.content + thumbnail_url = baseUrl + it.jsonObject["cover_url"]!!.jsonPrimitive.content } }, false @@ -119,15 +122,15 @@ class Mango : ConfigurableSource, HttpSource() { // This will just return the same thing as the main library endpoint override fun mangaDetailsParse(response: Response): SManga { val result = try { - gson.fromJson(response.body!!.string()) - } catch (e: JsonSyntaxException) { + json.decodeFromString(response.body!!.string()) + } catch (e: Exception) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") } return SManga.create().apply { - url = "/book/" + result["id"].asString - title = result["display_name"].asString - thumbnail_url = baseUrl + result["cover_url"].asString + url = "/book/" + result.jsonObject["id"]!!.jsonPrimitive.content + title = result.jsonObject["display_name"]!!.jsonPrimitive.content + thumbnail_url = baseUrl + result.jsonObject["cover_url"]!!.jsonPrimitive.content } } @@ -137,8 +140,8 @@ class Mango : ConfigurableSource, HttpSource() { // The chapter url will contain how many pages the chapter contains for our page list endpoint override fun chapterListParse(response: Response): List { val result = try { - gson.fromJson(response.body!!.string()) - } catch (e: JsonSyntaxException) { + json.decodeFromString(response.body!!.string()) + } catch (e: Exception) { apiCookies = "" throw Exception("Login Likely Failed. Try Refreshing.") } @@ -148,17 +151,17 @@ class Mango : ConfigurableSource, HttpSource() { // Helper function for listing chapters and chapters in nested titles recursively private fun listChapters(titleObj: JsonObject): List { val chapters = mutableListOf() - val topChapters = titleObj.getAsJsonArray("entries")?.map { obj -> + val topChapters = titleObj["entries"]?.jsonArray?.map { obj -> SChapter.create().apply { - name = obj["display_name"].asString + name = obj.jsonObject["display_name"]!!.jsonPrimitive.content url = - "/page/${obj["title_id"].asString}/${obj["id"].asString}/${obj["pages"].asString}/" - date_upload = 1000L * obj["mtime"].asLong + "/page/${obj.jsonObject["title_id"]!!.jsonPrimitive.content}/${obj.jsonObject["id"]!!.jsonPrimitive.content}/${obj.jsonObject["pages"]!!.jsonPrimitive.content}/" + date_upload = 1000L * obj.jsonObject["mtime"]!!.jsonPrimitive.long } } - val subChapters = titleObj.getAsJsonArray("titles")?.map { obj -> - val name = obj["display_name"].asString - listChapters(obj.asJsonObject).map { chp -> + val subChapters = titleObj["titles"]?.jsonArray?.map { obj -> + val name = obj.jsonObject["display_name"]!!.jsonPrimitive.content + listChapters(obj.jsonObject).map { chp -> chp.name = "$name / ${chp.name}" chp } @@ -200,11 +203,11 @@ class Mango : ConfigurableSource, HttpSource() { override val lang = "en" override val supportsLatest = false + private val json: Json by injectLazy() override val baseUrl by lazy { getPrefBaseUrl() } private val port by lazy { getPrefPort() } private val username by lazy { getPrefUsername() } private val password by lazy { getPrefPassword() } - private val gson by lazy { Gson() } private var apiCookies: String = "" override fun headersBuilder(): Headers.Builder = diff --git a/src/ca/fansubscat/build.gradle b/src/ca/fansubscat/build.gradle index b6c338fae..62b432f62 100644 --- a/src/ca/fansubscat/build.gradle +++ b/src/ca/fansubscat/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Fansubs.cat' diff --git a/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt b/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt index 7cec89e66..658580c9a 100644 --- a/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt +++ b/src/ca/fansubscat/src/eu/kanade/tachiyomi/extension/ca/fansubscat/FansubsCat.kt @@ -1,13 +1,5 @@ package eu.kanade.tachiyomi.extension.ca.fansubscat -import com.github.salomonbrys.kotson.float -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.github.salomonbrys.kotson.long -import com.github.salomonbrys.kotson.nullString -import com.github.salomonbrys.kotson.string -import com.google.gson.Gson -import com.google.gson.JsonObject import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess @@ -17,12 +9,22 @@ 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.HttpSource +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.contentOrNull +import kotlinx.serialization.json.float +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.long import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import rx.Observable +import uy.kohesive.injekt.injectLazy class FansubsCat : HttpSource() { @@ -39,22 +41,22 @@ class FansubsCat : HttpSource() { override val client: OkHttpClient = network.client - private val gson = Gson() + private val json: Json by injectLazy() private val apiBaseUrl = "https://api.fansubs.cat" private fun parseMangaFromJson(response: Response): MangasPage { - val jsonObject = gson.fromJson(response.body!!.string()) + val jsonObject = json.decodeFromString(response.body!!.string()) - val mangas = jsonObject["result"].asJsonArray.map { json -> + val mangas = jsonObject["result"]!!.jsonArray.map { json -> SManga.create().apply { - url = json["slug"].string - title = json["name"].string - thumbnail_url = json["thumbnail_url"].string - author = json["author"].nullString - description = json["synopsis"].nullString - status = json["status"].string.toStatus() - genre = json["genres"].nullString + url = json.jsonObject["slug"]!!.jsonPrimitive.content + title = json.jsonObject["name"]!!.jsonPrimitive.content + thumbnail_url = json.jsonObject["thumbnail_url"]!!.jsonPrimitive.content + author = json.jsonObject["author"]!!.jsonPrimitive.contentOrNull + description = json.jsonObject["synopsis"]!!.jsonPrimitive.contentOrNull + status = json.jsonObject["status"]!!.jsonPrimitive.content.toStatus() + genre = json.jsonObject["genres"]!!.jsonPrimitive.contentOrNull } } @@ -62,24 +64,24 @@ class FansubsCat : HttpSource() { } private fun parseChapterListFromJson(response: Response): List { - val jsonObject = gson.fromJson(response.body!!.string()) + val jsonObject = json.decodeFromString(response.body!!.string()) - return jsonObject["result"].asJsonArray.map { json -> + return jsonObject["result"]!!.jsonArray.map { json -> SChapter.create().apply { - url = json["id"].string - name = json["title"].string - chapter_number = json["number"].float - scanlator = json["fansub"].string - date_upload = json["created"].long + url = json.jsonObject["id"]!!.jsonPrimitive.content + name = json.jsonObject["title"]!!.jsonPrimitive.content + chapter_number = json.jsonObject["number"]!!.jsonPrimitive.float + scanlator = json.jsonObject["fansub"]!!.jsonPrimitive.content + date_upload = json.jsonObject["created"]!!.jsonPrimitive.long } } } private fun parsePageListFromJson(response: Response): List { - val jsonObject = gson.fromJson(response.body!!.string()) + val jsonObject = json.decodeFromString(response.body!!.string()) - return jsonObject["result"].asJsonArray.mapIndexed { i, it -> - Page(i, it["url"].asString, it["url"].asString) + return jsonObject["result"]!!.jsonArray.mapIndexed { i, it -> + Page(i, it.jsonObject["url"]!!.jsonPrimitive.content, it.jsonObject["url"]!!.jsonPrimitive.content) } } @@ -124,16 +126,17 @@ class FansubsCat : HttpSource() { } override fun mangaDetailsParse(response: Response): SManga { - val jsonObject = gson.fromJson(response.body!!.string()) + val jsonObject = json.decodeFromString(response.body!!.string()) + val resultObject = jsonObject.jsonObject["result"]!!.jsonObject return SManga.create().apply { - url = jsonObject["result"]["slug"].string - title = jsonObject["result"]["name"].string - thumbnail_url = jsonObject["result"]["thumbnail_url"].string - author = jsonObject["result"]["author"].nullString - description = jsonObject["result"]["synopsis"].nullString - status = jsonObject["result"]["status"].string.toStatus() - genre = jsonObject["result"]["genres"].nullString + url = resultObject["slug"]!!.jsonPrimitive.content + title = resultObject["name"]!!.jsonPrimitive.content + thumbnail_url = resultObject["thumbnail_url"]!!.jsonPrimitive.content + author = resultObject["author"]!!.jsonPrimitive.contentOrNull + description = resultObject["synopsis"]!!.jsonPrimitive.contentOrNull + status = resultObject["status"]!!.jsonPrimitive.content.toStatus() + genre = resultObject["genres"]!!.jsonPrimitive.contentOrNull } } diff --git a/src/en/doujins/build.gradle b/src/en/doujins/build.gradle index 423ceffde..b7b0d2ed2 100644 --- a/src/en/doujins/build.gradle +++ b/src/en/doujins/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Doujins' diff --git a/src/en/doujins/src/eu/kanade/tachiyomi/extension/en/doujins/Doujins.kt b/src/en/doujins/src/eu/kanade/tachiyomi/extension/en/doujins/Doujins.kt index 5ae43cf43..007359086 100644 --- a/src/en/doujins/src/eu/kanade/tachiyomi/extension/en/doujins/Doujins.kt +++ b/src/en/doujins/src/eu/kanade/tachiyomi/extension/en/doujins/Doujins.kt @@ -1,11 +1,5 @@ package eu.kanade.tachiyomi.extension.en.doujins -import android.app.Application -import android.content.SharedPreferences -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.google.gson.Gson -import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList @@ -15,11 +9,16 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy import java.text.ParseException import java.text.SimpleDateFormat import java.util.Calendar @@ -37,16 +36,12 @@ class Doujins : HttpSource() { override val supportsLatest: Boolean = true - private val gson = Gson() - - private val preferences: SharedPreferences by lazy { - Injekt.get().getSharedPreferences("source_$id", 0x0000) - } + private val json: Json by injectLazy() override fun chapterListParse(response: Response): List { return listOf( SChapter.create().apply { - var element = response.asJsoup() + val element = response.asJsoup() name = "Chapter" scanlator = element.select("div.folder-message:contains(Translated)").text().substringAfter("by:").trim() setUrlWithoutDomain(response.request.url.toString()) @@ -68,14 +63,14 @@ class Doujins : HttpSource() { override fun latestUpdatesParse(response: Response): MangasPage { return MangasPage( - gson.fromJson(response.body!!.string())["folders"].asJsonArray.map { + json.decodeFromString(response.body!!.string())["folders"]!!.jsonArray.map { SManga.create().apply { - setUrlWithoutDomain(it["link"].asString) - title = it["name"].asString - artist = it["artistList"].asString + setUrlWithoutDomain(it.jsonObject["link"]!!.jsonPrimitive.content) + title = it.jsonObject["name"]!!.jsonPrimitive.content + artist = it.jsonObject["artistList"]!!.jsonPrimitive.content author = artist - genre = it["tags"].asJsonArray.joinToString(", ") { it["tag"].asString } - thumbnail_url = it["thumbnail2"].asString + genre = it.jsonObject["tags"]!!.jsonArray.joinToString(", ") { it.jsonObject["tag"]!!.jsonPrimitive.content } + thumbnail_url = it.jsonObject["thumbnail2"]!!.jsonPrimitive.content } }, true diff --git a/src/en/madokami/build.gradle b/src/en/madokami/build.gradle index 466d1b9e2..33995172a 100644 --- a/src/en/madokami/build.gradle +++ b/src/en/madokami/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Madokami' diff --git a/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt b/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt index 2f2a6ad8c..0b6ad2930 100644 --- a/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt +++ b/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt @@ -3,9 +3,6 @@ package eu.kanade.tachiyomi.extension.en.madokami import android.app.Application import android.content.SharedPreferences import android.text.InputType -import com.github.salomonbrys.kotson.fromJson -import com.google.gson.Gson -import com.google.gson.JsonArray import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.FilterList @@ -13,6 +10,10 @@ 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.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.jsonPrimitive import okhttp3.Credentials import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull @@ -23,6 +24,7 @@ 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.io.IOException import java.net.URLDecoder import java.net.URLEncoder @@ -36,7 +38,7 @@ class Madokami : ConfigurableSource, ParsedHttpSource() { override val lang = "en" override val supportsLatest = false - private val gson = Gson() + private val json: Json by injectLazy() private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH) @@ -154,7 +156,7 @@ class Madokami : ConfigurableSource, ParsedHttpSource() { override fun pageListParse(document: Document): List { val element = document.select("div#reader") val path = element.attr("data-path") - val files = gson.fromJson(element.attr("data-files")) + val files = json.decodeFromString(element.attr("data-files")) val pages = mutableListOf() for ((index, file) in files.withIndex()) { val url = HttpUrl.Builder() @@ -162,7 +164,7 @@ class Madokami : ConfigurableSource, ParsedHttpSource() { .host("manga.madokami.al") .addPathSegments("reader/image") .addEncodedQueryParameter("path", URLEncoder.encode(path, "UTF-8")) - .addEncodedQueryParameter("file", URLEncoder.encode(file.asString, "UTF-8")) + .addEncodedQueryParameter("file", URLEncoder.encode(file.jsonPrimitive.content, "UTF-8")) .build() .toUrl() pages.add(Page(index, url.toExternalForm(), url.toExternalForm())) diff --git a/src/en/mangalinkz/build.gradle b/src/en/mangalinkz/build.gradle index bd8a3eaa0..69d58c194 100644 --- a/src/en/mangalinkz/build.gradle +++ b/src/en/mangalinkz/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Manga Linkz' diff --git a/src/en/mangalinkz/src/eu/kanade/tachiyomi/extension/en/mangalinkz/MangaLinkz.kt b/src/en/mangalinkz/src/eu/kanade/tachiyomi/extension/en/mangalinkz/MangaLinkz.kt index 205f36718..a020fb12e 100644 --- a/src/en/mangalinkz/src/eu/kanade/tachiyomi/extension/en/mangalinkz/MangaLinkz.kt +++ b/src/en/mangalinkz/src/eu/kanade/tachiyomi/extension/en/mangalinkz/MangaLinkz.kt @@ -1,20 +1,22 @@ package eu.kanade.tachiyomi.extension.en.mangalinkz import android.util.Base64 -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.string -import com.google.gson.Gson -import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList 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.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale @@ -137,14 +139,14 @@ class MangaLinkz : ParsedHttpSource() { // Pages - private val gson by lazy { Gson() } + private val json: Json by injectLazy() override fun pageListParse(document: Document): List { val encoded = document.select("script:containsData(atob)").first().data() .substringAfter("atob(\"").substringBefore("\"") val decoded = Base64.decode(encoded, Base64.DEFAULT).toString(Charsets.UTF_8).removeSurrounding("[", "]") - return gson.fromJson(decoded)["pages"].asJsonArray.mapIndexed { i, jsonElement -> Page(i, "", jsonElement.string) } + return json.decodeFromString(decoded)["pages"]!!.jsonArray.mapIndexed { i, jsonElement -> Page(i, "", jsonElement.jsonPrimitive.content) } } override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") diff --git a/src/en/multporn/build.gradle b/src/en/multporn/build.gradle index 152b9c401..a5749cf42 100644 --- a/src/en/multporn/build.gradle +++ b/src/en/multporn/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Multporn' diff --git a/src/en/multporn/src/eu/kanade/tachiyomi/extension/en/multporn/Multporn.kt b/src/en/multporn/src/eu/kanade/tachiyomi/extension/en/multporn/Multporn.kt index 1c3f328c7..24f07df48 100644 --- a/src/en/multporn/src/eu/kanade/tachiyomi/extension/en/multporn/Multporn.kt +++ b/src/en/multporn/src/eu/kanade/tachiyomi/extension/en/multporn/Multporn.kt @@ -1,9 +1,5 @@ package eu.kanade.tachiyomi.extension.en.multporn -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.google.gson.Gson -import com.google.gson.JsonArray import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.asObservable @@ -16,6 +12,11 @@ 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.decodeFromString +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.Headers import okhttp3.HttpUrl.Companion.toHttpUrlOrNull @@ -27,6 +28,7 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable import rx.schedulers.Schedulers +import uy.kohesive.injekt.injectLazy import java.util.Locale class Multporn : ParsedHttpSource() { @@ -36,7 +38,7 @@ class Multporn : ParsedHttpSource() { override val baseUrl = "https://multporn.net" override val supportsLatest = true - private val gson = Gson() + private val json: Json by injectLazy() override fun headersBuilder(): Headers.Builder = Headers.Builder() .add("User-Agent", HEADER_USER_AGENT) @@ -65,8 +67,8 @@ class Multporn : ParsedHttpSource() { override fun popularMangaRequest(page: Int) = buildPopularMangaRequest(page - 1) override fun popularMangaParse(response: Response): MangasPage { - val html = gson.fromJson(response.body!!.string()) - .last { it["command"].asString == "insert" }.asJsonObject["data"].asString + val html = json.decodeFromString(response.body!!.string()) + .last { it.jsonObject["command"]!!.jsonPrimitive.content == "insert" }.jsonObject["data"]!!.jsonPrimitive.content return super.popularMangaParse( response.newBuilder() diff --git a/src/ru/henchan/build.gradle b/src/ru/henchan/build.gradle index cf5c6db7d..bc8a51722 100644 --- a/src/ru/henchan/build.gradle +++ b/src/ru/henchan/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Henchan' diff --git a/src/ru/henchan/src/eu/kanade/tachiyomi/extension/ru/henchan/Henchan.kt b/src/ru/henchan/src/eu/kanade/tachiyomi/extension/ru/henchan/Henchan.kt index 9b1e504b0..8d2e3d71b 100644 --- a/src/ru/henchan/src/eu/kanade/tachiyomi/extension/ru/henchan/Henchan.kt +++ b/src/ru/henchan/src/eu/kanade/tachiyomi/extension/ru/henchan/Henchan.kt @@ -1,12 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.henchan import android.annotation.SuppressLint -import com.github.salomonbrys.kotson.array -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.string -import com.google.gson.Gson -import com.google.gson.JsonArray -import com.google.gson.JsonObject import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservable @@ -17,6 +11,12 @@ 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.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonPrimitive import okhttp3.Headers import okhttp3.OkHttpClient import okhttp3.Request @@ -24,6 +24,7 @@ import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable +import uy.kohesive.injekt.injectLazy import java.net.URL import java.text.SimpleDateFormat import java.util.Date @@ -254,17 +255,17 @@ class Henchan : ParsedHttpSource() { override fun imageUrlParse(document: Document) = throw Exception("Not Used") - private val gson = Gson() + private val json: Json by injectLazy() private fun Document.parseJsonArray(): JsonArray { val imgScript = this.select("script:containsData(fullimg)").first().toString() val imgString = imgScript.substring(imgScript.indexOf('{'), imgScript.lastIndexOf('}') + 1).replace(""", "\"") - return gson.fromJson(imgString)["fullimg"].array + return json.decodeFromString(imgString)["fullimg"]!!.jsonArray } override fun pageListParse(document: Document): List { return document.parseJsonArray().mapIndexed { index, imageUrl -> - Page(index, imageUrl = imageUrl.string.replace(".gif.webp", ".gif")) + Page(index, imageUrl = imageUrl.jsonPrimitive.content.replace(".gif.webp", ".gif")) } } diff --git a/src/th/nekopost/build.gradle b/src/th/nekopost/build.gradle index e54a00bfd..81bbb1ba9 100644 --- a/src/th/nekopost/build.gradle +++ b/src/th/nekopost/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Nekopost' diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt index 84fc41ef0..af12433dd 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/Nekopost.kt @@ -1,9 +1,8 @@ package eu.kanade.tachiyomi.extension.th.nekopost -import com.google.gson.Gson import eu.kanade.tachiyomi.extension.th.nekopost.model.RawChapterInfo import eu.kanade.tachiyomi.extension.th.nekopost.model.RawProjectInfo -import eu.kanade.tachiyomi.extension.th.nekopost.model.RawProjectNameList +import eu.kanade.tachiyomi.extension.th.nekopost.model.RawProjectNameListItem import eu.kanade.tachiyomi.extension.th.nekopost.model.RawProjectSummaryList import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess @@ -13,6 +12,8 @@ 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.decodeFromString +import kotlinx.serialization.json.Json import okhttp3.Headers import okhttp3.OkHttpClient import okhttp3.Request @@ -20,11 +21,12 @@ import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable +import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale class Nekopost : ParsedHttpSource() { - private val gson: Gson = Gson() + private val json: Json by injectLazy() override val baseUrl: String = "https://www.nekopost.net/project" private val latestMangaEndpoint: String = @@ -81,10 +83,10 @@ class Nekopost : ParsedHttpSource() { .map { response -> val responseBody = response.body ?: throw Error("Unable to fetch manga detail of ${manga.title}") - val projectInfo = gson.fromJson(responseBody.string(), RawProjectInfo::class.java) + val projectInfo: RawProjectInfo = json.decodeFromString(responseBody.string()) manga.apply { - projectInfo.projectData.let { + projectInfo.projectInfo.let { url = it.npProjectId title = it.npName artist = it.artistName @@ -95,7 +97,7 @@ class Nekopost : ParsedHttpSource() { } genre = - projectInfo.projectCategoryUsed.map { it.npcName }.joinToString(", ") + projectInfo.projectCategoryUsed.joinToString(", ") { it.npcName } } } } @@ -108,8 +110,7 @@ class Nekopost : ParsedHttpSource() { val responseBody = response.body ?: throw Error("Unable to fetch manga detail of ${manga.title}") - val projectInfo = - gson.fromJson(responseBody.string(), RawProjectInfo::class.java) + val projectInfo: RawProjectInfo = json.decodeFromString(responseBody.string()) projectInfo.projectChapterList.map { chapter -> SChapter.create().apply { @@ -137,8 +138,7 @@ class Nekopost : ParsedHttpSource() { val responseBody = response.body ?: throw Error("Unable to fetch page list of chapter ${chapter.chapter_number}") - val chapterInfo = - gson.fromJson(responseBody.string(), RawChapterInfo::class.java) + val chapterInfo: RawChapterInfo = json.decodeFromString(responseBody.string()) chapterInfo.pageItem.map { page -> Page( @@ -159,7 +159,7 @@ class Nekopost : ParsedHttpSource() { override fun popularMangaParse(response: Response): MangasPage { val responseBody = response.body ?: throw Error("Unable to fetch mangas") - val projectList = gson.fromJson(responseBody.string(), RawProjectSummaryList::class.java) + val projectList: RawProjectSummaryList = json.decodeFromString(responseBody.string()) val mangaList: List = projectList.listItem @@ -200,8 +200,7 @@ class Nekopost : ParsedHttpSource() { .asObservableSuccess() .map { response -> val responseBody = response.body ?: throw Error("Unable to fetch title list") - val projectList = - gson.fromJson(responseBody.string(), RawProjectNameList::class.java) + val projectList: List = json.decodeFromString(responseBody.string()) val mangaList: List = projectList.filter { project -> Regex( diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt index 28a1b7047..64f2b54dd 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawChapterInfo.kt @@ -1,16 +1,12 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawChapterInfo( - @SerializedName("chapterId") val chapterId: Int, - @SerializedName("chapterNo") val chapterNo: String, - @SerializedName("pageCount") val pageCount: Int, - @SerializedName("pageItem") val pageItem: List, - @SerializedName("projectId") val projectId: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt index 23e88f13c..101060818 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawPageItem.kt @@ -1,14 +1,11 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawPageItem( - @SerializedName("fileName") val fileName: String, - @SerializedName("height") val height: Int, - @SerializedName("pageNo") val pageNo: Int, - @SerializedName("width") val width: Int ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt index 32eb138fa..ad228f5bb 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectCategory.kt @@ -1,10 +1,12 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectCategory( - @SerializedName("npc_name") + @SerialName("npc_name") val npcName: String, - @SerializedName("npc_name_link") + @SerialName("npc_name_link") val npcNameLink: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt index c05951984..0f9825608 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectChapter.kt @@ -1,7 +1,9 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectChapter( @SerializedName("cu_displayname") val cuDisplayname: String, diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt index 7dc4c393a..5649231e9 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfo.kt @@ -1,14 +1,11 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectInfo( - @SerializedName("code") val code: String, - @SerializedName("projectCategoryUsed") val projectCategoryUsed: List, - @SerializedName("projectChapterList") val projectChapterList: List, - @SerializedName("projectInfo") - val projectData: RawProjectInfoData + val projectInfo: RawProjectInfoData ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt index cd26f325b..55f19a8cf 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectInfoData.kt @@ -1,7 +1,9 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectInfoData( @SerializedName("artist_name") val artistName: String, diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameList.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameList.kt deleted file mode 100644 index 705547f9c..000000000 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameList.kt +++ /dev/null @@ -1,3 +0,0 @@ -package eu.kanade.tachiyomi.extension.th.nekopost.model - -class RawProjectNameList : ArrayList() diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameListItem.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameListItem.kt index 773dd01bc..65e00a82a 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameListItem.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectNameListItem.kt @@ -1,18 +1,20 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectNameListItem( - @SerializedName("np_name") + @SerialName("np_name") val npName: String, - @SerializedName("np_name_link") + @SerialName("np_name_link") val npNameLink: String, - @SerializedName("np_no_chapter") + @SerialName("np_no_chapter") val npNoChapter: String, - @SerializedName("np_project_id") + @SerialName("np_project_id") val npProjectId: String, - @SerializedName("np_status") + @SerialName("np_status") val npStatus: String, - @SerializedName("np_type") + @SerialName("np_type") val npType: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt index a297e65bb..d69feaa88 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummary.kt @@ -1,28 +1,30 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectSummary( - @SerializedName("nc_chapter_cover") + @SerialName("nc_chapter_cover") val ncChapterCover: String, - @SerializedName("nc_chapter_id") + @SerialName("nc_chapter_id") val ncChapterId: String, - @SerializedName("nc_chapter_name") + @SerialName("nc_chapter_name") val ncChapterName: String, - @SerializedName("nc_chapter_no") + @SerialName("nc_chapter_no") val ncChapterNo: String, - @SerializedName("nc_created_date") + @SerialName("nc_created_date") val ncCreatedDate: String, - @SerializedName("nc_provider") + @SerialName("nc_provider") val ncProvider: String, - @SerializedName("no_new_chapter") + @SerialName("no_new_chapter") val noNewChapter: String, - @SerializedName("np_group_dir") + @SerialName("np_group_dir") val npGroupDir: String, - @SerializedName("np_name") + @SerialName("np_name") val npName: String, - @SerializedName("np_name_link") + @SerialName("np_name_link") val npNameLink: String, - @SerializedName("np_project_id") + @SerialName("np_project_id") val npProjectId: String ) diff --git a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt index 9348714fc..eb4d58d4f 100644 --- a/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt +++ b/src/th/nekopost/src/eu/kanade/tachiyomi/extension/th/nekopost/model/RawProjectSummaryList.kt @@ -1,10 +1,9 @@ package eu.kanade.tachiyomi.extension.th.nekopost.model -import com.google.gson.annotations.SerializedName +import kotlinx.serialization.Serializable +@Serializable data class RawProjectSummaryList( - @SerializedName("code") val code: String, - @SerializedName("listItem") val listItem: List? ) diff --git a/src/zh/comico/build.gradle b/src/zh/comico/build.gradle index 9d4318756..b401d6e4d 100644 --- a/src/zh/comico/build.gradle +++ b/src/zh/comico/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Comico' diff --git a/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/Comico.kt b/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/Comico.kt index 381d0f0d9..58d117cf2 100644 --- a/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/Comico.kt +++ b/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/Comico.kt @@ -1,10 +1,5 @@ package eu.kanade.tachiyomi.extension.zh.comico -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.google.gson.Gson -import com.google.gson.JsonElement -import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.FilterList @@ -12,12 +7,19 @@ 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.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +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.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale @@ -33,7 +35,7 @@ abstract class Comico( override val client: OkHttpClient = network.cloudflareClient - val gson = Gson() + val json: Json by injectLazy() // Popular @@ -122,12 +124,12 @@ abstract class Comico( return POST("$baseUrl/api/getArticleList.nhn", chapterListHeaders, body) } - fun chapterFromJson(jsonElement: JsonElement): SChapter { + fun chapterFromJson(jsonObject: JsonObject): SChapter { val chapter = SChapter.create() - chapter.name = jsonElement["subtitle"].asString - chapter.setUrlWithoutDomain(jsonElement["articleDetailUrl"].asString) - chapter.date_upload = parseDate(jsonElement["date"].asString) + chapter.name = jsonObject["subtitle"]!!.jsonPrimitive.content + chapter.setUrlWithoutDomain(jsonObject["articleDetailUrl"]!!.jsonPrimitive.content) + chapter.date_upload = parseDate(jsonObject["date"]!!.jsonPrimitive.content) return chapter } @@ -135,9 +137,14 @@ abstract class Comico( override fun chapterListParse(response: Response): List { val chapters = mutableListOf() - gson.fromJson(response.body!!.string())["result"]["list"].asJsonArray.forEach { - if (it["freeFlg"].asString == "Y") chapters.add(chapterFromJson(it)) - } + json.decodeFromString(response.body!!.string())["result"]!! + .jsonObject["list"]!! + .jsonArray + .forEach { + if (it.jsonObject["freeFlg"]!!.jsonPrimitive.content == "Y") { + chapters.add(chapterFromJson(it.jsonObject)) + } + } return chapters.reversed() } diff --git a/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/ComicoFactory.kt b/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/ComicoFactory.kt index f3716777f..61200d0d4 100644 --- a/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/ComicoFactory.kt +++ b/src/zh/comico/src/eu/kanade/tachiyomi/extension/zh/comico/ComicoFactory.kt @@ -1,8 +1,5 @@ package eu.kanade.tachiyomi.extension.zh.comico -import com.github.salomonbrys.kotson.fromJson -import com.github.salomonbrys.kotson.get -import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory @@ -10,6 +7,11 @@ import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive import okhttp3.FormBody import okhttp3.Request import okhttp3.Response @@ -36,21 +38,24 @@ class ComicoChallenge : Comico("Comico Challenge", "/challenge", true) { val mangas = mutableListOf() val body = response.body!!.string() - gson.fromJson(body)["result"]["list"].asJsonArray.forEach { - val manga = SManga.create() + json.decodeFromString(body)["result"]!! + .jsonObject["list"]!! + .jsonArray + .forEach { + val manga = SManga.create() - manga.thumbnail_url = it["img_url"].asString - manga.title = it["article_title"].asString - manga.author = it["author"].asString - manga.description = it["description"].asString - manga.url = it["article_url"].asString.substringAfter(urlModifier) - manga.status = if (it["is_end"].asString == "false") SManga.ONGOING else SManga.COMPLETED + manga.thumbnail_url = it.jsonObject["img_url"]!!.jsonPrimitive.content + manga.title = it.jsonObject["article_title"]!!.jsonPrimitive.content + manga.author = it.jsonObject["author"]!!.jsonPrimitive.content + manga.description = it.jsonObject["description"]!!.jsonPrimitive.content + manga.url = it.jsonObject["article_url"]!!.jsonPrimitive.content.substringAfter(urlModifier) + manga.status = if (it.jsonObject["is_end"]!!.jsonPrimitive.content == "false") SManga.ONGOING else SManga.COMPLETED - mangas.add(manga) - } + mangas.add(manga) + } - val lastPage = gson.fromJson(body)["result"]["totalPageCnt"].asString - val currentPage = gson.fromJson(body)["result"]["currentPageNo"].asString + val lastPage = json.decodeFromString(body)["result"]!!.jsonObject["totalPageCnt"]!!.jsonPrimitive.content + val currentPage = json.decodeFromString(body)["result"]!!.jsonObject["currentPageNo"]!!.jsonPrimitive.content return MangasPage(mangas, currentPage < lastPage) } @@ -82,8 +87,12 @@ class ComicoChallenge : Comico("Comico Challenge", "/challenge", true) { override fun chapterListParse(response: Response): List { val chapters = mutableListOf() - gson.fromJson(response.body!!.string())["result"]["list"].asJsonArray - .forEach { chapters.add(chapterFromJson(it)) } + json.decodeFromString(response.body!!.string())["result"]!! + .jsonObject["list"]!! + .jsonArray + .forEach { + chapters.add(chapterFromJson(it.jsonObject)) + } return chapters.reversed() } diff --git a/src/zh/manhuagui/build.gradle b/src/zh/manhuagui/build.gradle index 17539c914..168c85abd 100644 --- a/src/zh/manhuagui/build.gradle +++ b/src/zh/manhuagui/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'ManHuaGui' diff --git a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Comic.kt b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Comic.kt index 63718c67f..7fc186471 100644 --- a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Comic.kt +++ b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Comic.kt @@ -1,5 +1,8 @@ package eu.kanade.tachiyomi.extension.zh.manhuagui +import kotlinx.serialization.Serializable + +@Serializable data class Comic( val bid: Int? = 0, val block_cc: String? = "", diff --git a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt index 8ceb1ea04..58523bce2 100644 --- a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt +++ b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.extension.zh.manhuagui import android.app.Application import android.content.SharedPreferences -import com.google.gson.Gson import com.squareup.duktape.Duktape import eu.kanade.tachiyomi.lib.ratelimit.SpecificHostRateLimitInterceptor import eu.kanade.tachiyomi.network.GET @@ -22,6 +21,8 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json import okhttp3.Call import okhttp3.Callback import okhttp3.Headers @@ -37,6 +38,7 @@ import org.jsoup.nodes.Element import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy import java.io.IOException import java.text.SimpleDateFormat import java.util.Locale @@ -65,7 +67,7 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() { private val imageServer = arrayOf("https://i.hamreus.com", "https://cf.hamreus.com") private val mobileWebsiteUrl = "https://m.$baseHost" - private val gson = Gson() + private val json: Json by injectLazy() private val baseHttpUrl: HttpUrl = baseUrl.toHttpUrlOrNull()!! // Add rate limit to fix manga thumbnail load failure @@ -388,7 +390,7 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() { } val imgJsonStr = re2.find(imgDecode)?.groups?.get(0)?.value - val imageJson: Comic = gson.fromJson(imgJsonStr, Comic::class.java) + val imageJson: Comic = json.decodeFromString(imgJsonStr!!) return imageJson.files!!.mapIndexed { i, imgStr -> val imgurl = "${imageServer[0]}${imageJson.path}$imgStr?cid=${imageJson.cid}&md5=${imageJson.sl?.md5}" diff --git a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Sl.kt b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Sl.kt index 60c67d5f8..a3237003d 100644 --- a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Sl.kt +++ b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Sl.kt @@ -1,5 +1,8 @@ package eu.kanade.tachiyomi.extension.zh.manhuagui +import kotlinx.serialization.Serializable + +@Serializable data class Sl( val md5: String? = "" ) diff --git a/src/zh/tohomh123/build.gradle b/src/zh/tohomh123/build.gradle index c4f147202..87990798f 100644 --- a/src/zh/tohomh123/build.gradle +++ b/src/zh/tohomh123/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'Tohomh123' diff --git a/src/zh/tohomh123/src/eu/kanade/tachiyomi/extension/zh/tohomh123/Tohomh.kt b/src/zh/tohomh123/src/eu/kanade/tachiyomi/extension/zh/tohomh123/Tohomh.kt index 3334b622b..6171c82ca 100644 --- a/src/zh/tohomh123/src/eu/kanade/tachiyomi/extension/zh/tohomh123/Tohomh.kt +++ b/src/zh/tohomh123/src/eu/kanade/tachiyomi/extension/zh/tohomh123/Tohomh.kt @@ -1,8 +1,5 @@ package eu.kanade.tachiyomi.extension.zh.tohomh123 -import com.github.salomonbrys.kotson.fromJson -import com.google.gson.Gson -import com.google.gson.JsonObject import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page @@ -10,11 +7,16 @@ 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.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonPrimitive import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale @@ -142,10 +144,10 @@ class Tohomh : ParsedHttpSource() { return pages } - private val gson = Gson() + private val json: Json by injectLazy() override fun imageUrlParse(response: Response): String { - return gson.fromJson(response.body!!.string())["Code"].asString + return json.decodeFromString(response.body!!.string())["Code"]!!.jsonPrimitive.content } override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") diff --git a/src/zh/wuqimanga/build.gradle b/src/zh/wuqimanga/build.gradle index 6aae533d3..6ff89436b 100644 --- a/src/zh/wuqimanga/build.gradle +++ b/src/zh/wuqimanga/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' ext { extName = 'WuqiManga' diff --git a/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/Comic.kt b/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/Comic.kt index 688f1884a..dcb957081 100644 --- a/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/Comic.kt +++ b/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/Comic.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.extension.zh.wuqimanga -class Comic { +import kotlinx.serialization.Serializable +@Serializable +class Comic { val fs: List? = listOf() } diff --git a/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/WuqiManga.kt b/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/WuqiManga.kt index 1f988d401..0b47c99f3 100644 --- a/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/WuqiManga.kt +++ b/src/zh/wuqimanga/src/eu/kanade/tachiyomi/extension/zh/wuqimanga/WuqiManga.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.extension.zh.wuqimanga -import com.google.gson.Gson import com.squareup.duktape.Duktape import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList @@ -9,11 +8,14 @@ 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.decodeFromString +import kotlinx.serialization.json.Json import okhttp3.Headers import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.injectLazy class WuqiManga : ParsedHttpSource() { @@ -137,7 +139,7 @@ class WuqiManga : ParsedHttpSource() { return chapters } - private val gson = Gson() + private val json: Json by injectLazy() override fun pageListParse(document: Document): List { val html = document.html() @@ -147,7 +149,7 @@ class WuqiManga : ParsedHttpSource() { } val re2 = Regex("""\{.*\}""") val imgJsonStr = re2.find(result)?.groups?.get(0)?.value - val imageJson: Comic = gson.fromJson(imgJsonStr, Comic::class.java) + val imageJson: Comic = json.decodeFromString(imgJsonStr!!) return imageJson.fs!!.mapIndexed { i, imgStr -> val imgurl = "$imageServer$imgStr"