diff --git a/src/es/lectormanga/build.gradle b/src/es/lectormanga/build.gradle index b1fb2ebe8..889eb2d08 100755 --- a/src/es/lectormanga/build.gradle +++ b/src/es/lectormanga/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'LectorManga' pkgNameSuffix = 'es.lectormanga' extClass = '.LectorManga' - extVersionCode = 28 + extVersionCode = 29 isNsfw = true } diff --git a/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt b/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt index 1396cad5b..4f478e151 100755 --- a/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt +++ b/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.extension.es.lectormanga import android.app.Application import android.content.SharedPreferences import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.interceptor.rateLimitHost import eu.kanade.tachiyomi.source.ConfigurableSource @@ -14,6 +15,7 @@ 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 okhttp3.FormBody import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient @@ -251,7 +253,7 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { } override fun pageListParse(document: Document): List = mutableListOf().apply { - var doc = document + var doc = redirectToReadPage(document) val currentUrl = doc.location() val newUrl = if (!currentUrl.contains("cascade")) { @@ -264,7 +266,7 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { doc = client.newCall(GET(newUrl, headers)).execute().asJsoup() } - doc.select("div.viewer-image-container img").forEach { + doc.select("div.viewer-container img:not(noscript img)").forEach { add( Page( size, @@ -281,6 +283,41 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { } } + // Some chapters uses JavaScript to redirect to read page + private fun redirectToReadPage(document: Document): Document { + val script1 = document.selectFirst("script:containsData(uniqid)") + val script2 = document.selectFirst("script:containsData(window.location.replace)") + + val redirectHeaders = Headers.Builder() + .add("Referer", document.baseUri()) + .build() + + if (script1 != null) { + val data = script1.data() + val regexParams = """\{uniqid:'(.+)',cascade:(.+)\}""".toRegex() + val regexAction = """form\.action\s?=\s?'(.+)'""".toRegex() + val params = regexParams.find(data)!! + val action = regexAction.find(data)!!.groupValues[1] + + val formBody = FormBody.Builder() + .add("uniqid", params.groupValues[1]) + .add("cascade", params.groupValues[2]) + .build() + + return redirectToReadPage(client.newCall(POST(action, redirectHeaders, formBody)).execute().asJsoup()) + } + + if (script2 != null) { + val data = script2.data() + val regexRedirect = """window\.location\.replace\('(.+)'\)""".toRegex() + val url = regexRedirect.find(data)!!.groupValues[1] + + return redirectToReadPage(client.newCall(GET(url, redirectHeaders)).execute().asJsoup()) + } + + return document + } + override fun imageRequest(page: Page) = GET( url = page.imageUrl!!, headers = headers.newBuilder()