From 37c4df824a42fe444eddd8fb0067cff99736b008 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sun, 28 Nov 2021 13:15:28 -0300 Subject: [PATCH] Add Google Drive view limit warning in MMK. (#9947) --- src/pt/mundomangakun/build.gradle | 2 +- .../pt/mundomangakun/MundoMangaKun.kt | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/pt/mundomangakun/build.gradle b/src/pt/mundomangakun/build.gradle index 0c452613c..485e9e613 100644 --- a/src/pt/mundomangakun/build.gradle +++ b/src/pt/mundomangakun/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Mundo Mangá-Kun' pkgNameSuffix = 'pt.mundomangakun' extClass = '.MundoMangaKun' - extVersionCode = 6 + extVersionCode = 7 isNsfw = true } diff --git a/src/pt/mundomangakun/src/eu/kanade/tachiyomi/extension/pt/mundomangakun/MundoMangaKun.kt b/src/pt/mundomangakun/src/eu/kanade/tachiyomi/extension/pt/mundomangakun/MundoMangaKun.kt index 5707d473d..f10d6ba3d 100644 --- a/src/pt/mundomangakun/src/eu/kanade/tachiyomi/extension/pt/mundomangakun/MundoMangaKun.kt +++ b/src/pt/mundomangakun/src/eu/kanade/tachiyomi/extension/pt/mundomangakun/MundoMangaKun.kt @@ -136,12 +136,29 @@ class MundoMangaKun : ParsedHttpSource() { } override fun pageListParse(document: Document): List { - return document.select("script:containsData(var paginas)").first().data() + val pageList = document.select("script:containsData(var paginas)").first().data() .substringAfter("var paginas = ") .substringBefore("];") .let { json.parseToJsonElement("$it]") } .jsonArray .mapIndexed { i, page -> Page(i, document.location(), page.jsonPrimitive.content) } + + // Check if the pages have exceeded the view limit of Google Drive. + val firstPage = pageList[0] + + val hasExceededViewLimit = runCatching { + val firstPageRequest = imageRequest(firstPage) + + client.newCall(firstPageRequest).execute().use { + it.headers["Content-Type"]!!.contains("text/html") + } + } + + if (hasExceededViewLimit.getOrDefault(false)) { + throw Exception(EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT) + } + + return pageList } override fun imageUrlParse(document: Document) = "" @@ -240,6 +257,9 @@ class MundoMangaKun : ParsedHttpSource() { companion object { private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + - "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36" + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" + + private const val EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT = "Limite de visualizações atingido " + + "no Google Drive. Aguarde com que o limite seja reestabelecido." } }