Add Google Drive view limit warning in MMK. (#9947)

This commit is contained in:
Alessandro Jean 2021-11-28 13:15:28 -03:00 committed by GitHub
parent 54b055d5b3
commit 37c4df824a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Mundo Mangá-Kun' extName = 'Mundo Mangá-Kun'
pkgNameSuffix = 'pt.mundomangakun' pkgNameSuffix = 'pt.mundomangakun'
extClass = '.MundoMangaKun' extClass = '.MundoMangaKun'
extVersionCode = 6 extVersionCode = 7
isNsfw = true isNsfw = true
} }

View File

@ -136,12 +136,29 @@ class MundoMangaKun : ParsedHttpSource() {
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
return document.select("script:containsData(var paginas)").first().data() val pageList = document.select("script:containsData(var paginas)").first().data()
.substringAfter("var paginas = ") .substringAfter("var paginas = ")
.substringBefore("];") .substringBefore("];")
.let { json.parseToJsonElement("$it]") } .let { json.parseToJsonElement("$it]") }
.jsonArray .jsonArray
.mapIndexed { i, page -> Page(i, document.location(), page.jsonPrimitive.content) } .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) = "" override fun imageUrlParse(document: Document) = ""
@ -240,6 +257,9 @@ class MundoMangaKun : ParsedHttpSource() {
companion object { companion object {
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + 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."
} }
} }