From 8aa1497d4d5fbb9bd2a43406ff2c0fa6b49ef212 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Thu, 8 Apr 2021 12:39:20 -0300 Subject: [PATCH] Fix JSON error in MangasProject. (#6476) --- .../mangasproject/leitornet/src/LeitorNet.kt | 5 +---- .../mangasproject/mangalivre/src/MangaLivre.kt | 5 +---- .../overrides/mangasproject/toonei/src/Toonei.kt | 5 +---- .../multisrc/mangasproject/MangasProject.kt | 12 +++++++++--- .../multisrc/mangasproject/MangasProjectGenerator.kt | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt b/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt index 3892dc00d..ffc5e592e 100644 --- a/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt +++ b/multisrc/overrides/mangasproject/leitornet/src/LeitorNet.kt @@ -17,11 +17,8 @@ class LeitorNet : MangasProject("Leitor.net", "https://leitor.net", "pt-BR") { // Existing mangas and other titles in the library still work. override val id: Long = 2225174659569980836 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(RateLimitInterceptor(5, 1, TimeUnit.SECONDS)) - .connectTimeout(1, TimeUnit.MINUTES) - .readTimeout(1, TimeUnit.MINUTES) - .writeTimeout(1, TimeUnit.MINUTES) .build() /** diff --git a/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt b/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt index d0d738208..872834f0b 100644 --- a/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt +++ b/multisrc/overrides/mangasproject/mangalivre/src/MangaLivre.kt @@ -16,11 +16,8 @@ class MangaLivre : MangasProject("Mangá Livre", "https://mangalivre.net", "pt-B // Hardcode the id because the language wasn't specific. override val id: Long = 4762777556012432014 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(RateLimitInterceptor(5, 1, TimeUnit.SECONDS)) - .connectTimeout(1, TimeUnit.MINUTES) - .readTimeout(1, TimeUnit.MINUTES) - .writeTimeout(1, TimeUnit.MINUTES) .build() override fun popularMangaRequest(page: Int): Request { diff --git a/multisrc/overrides/mangasproject/toonei/src/Toonei.kt b/multisrc/overrides/mangasproject/toonei/src/Toonei.kt index 1011829b2..f3e3f0966 100644 --- a/multisrc/overrides/mangasproject/toonei/src/Toonei.kt +++ b/multisrc/overrides/mangasproject/toonei/src/Toonei.kt @@ -8,11 +8,8 @@ import java.util.concurrent.TimeUnit class Toonei : MangasProject("Toonei", "https://toonei.com", "pt-BR") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(RateLimitInterceptor(5, 1, TimeUnit.SECONDS)) - .connectTimeout(1, TimeUnit.MINUTES) - .readTimeout(1, TimeUnit.MINUTES) - .writeTimeout(1, TimeUnit.MINUTES) .build() override fun getReaderToken(document: Document): String? { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt index f5fe49cc8..83d79de5d 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProject.kt @@ -232,7 +232,7 @@ abstract class MangasProject( (if (chapterName == "") "" else " - $chapterName") date_upload = obj["date_created"].string.substringBefore("T").toDate() scanlator = release["scanlators"]!!.array - .map { scanObj -> scanObj.obj["name"].string } + .mapNotNull { scanObj -> scanObj.obj["name"].string.ifEmpty { null } } .sorted() .joinToString() url = release["link"].string @@ -299,7 +299,13 @@ abstract class MangasProject( return GET(page.imageUrl!!, newHeaders) } - private fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj + private fun Response.asJsonObject(): JsonObject { + if (!isSuccessful) { + throw Exception("HTTP error ${code()}") + } + + return JSON_PARSER.parse(body()!!.string()).obj + } private fun String.toDate(): Long { return try { @@ -315,7 +321,7 @@ abstract class MangasProject( private const val ACCEPT_JSON = "application/json, text/javascript, */*; q=0.01" private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5" private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + - "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36" + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" private val JSON_PARSER by lazy { JsonParser() } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProjectGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProjectGenerator.kt index afaf41c33..07f6a72c6 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProjectGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangasproject/MangasProjectGenerator.kt @@ -9,7 +9,7 @@ class MangasProjectGenerator : ThemeSourceGenerator { override val themeClass = "MangasProject" - override val baseVersionCode: Int = 1 + override val baseVersionCode: Int = 2 override val sources = listOf( SingleLang("Leitor.net", "https://leitor.net", "pt-BR", className = "LeitorNet", isNsfw = true, overrideVersionCode = 1),