From b6c602545c88d9ee5143f8ccb42c700c307f2db7 Mon Sep 17 00:00:00 2001 From: Pavka Date: Sun, 1 Dec 2019 01:06:52 +0300 Subject: [PATCH] Comx. Fix download some chapter and avoiding antibot feature (#1842) * Comx. Fix download some chapter and avoiding antibot feature * Fix build with missing CookieJar --- src/ru/comx/build.gradle | 6 ++- .../tachiyomi/extension/ru/comx/ComX.kt | 43 +++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/ru/comx/build.gradle b/src/ru/comx/build.gradle index 476e6c5dd..b78a17e65 100644 --- a/src/ru/comx/build.gradle +++ b/src/ru/comx/build.gradle @@ -5,8 +5,12 @@ ext { appName = 'Tachiyomi: ComX' pkgNameSuffix = 'ru.comx' extClass = '.ComX' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' } +dependencies { + implementation project(':lib-ratelimit') +} + apply from: "$rootDir/common.gradle" diff --git a/src/ru/comx/src/eu/kanade/tachiyomi/extension/ru/comx/ComX.kt b/src/ru/comx/src/eu/kanade/tachiyomi/extension/ru/comx/ComX.kt index 123716d57..92976f545 100644 --- a/src/ru/comx/src/eu/kanade/tachiyomi/extension/ru/comx/ComX.kt +++ b/src/ru/comx/src/eu/kanade/tachiyomi/extension/ru/comx/ComX.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.extension.ru.comx +import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.FilterList @@ -8,10 +9,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.Request -import okhttp3.Response +import okhttp3.* import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -24,6 +22,30 @@ class ComX : ParsedHttpSource() { override val supportsLatest = true + private val userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0" // in case of change regenerate antibot cookie + + override val client = super.client.newBuilder() + .addNetworkInterceptor(RateLimitInterceptor(4)) + .cookieJar(object : CookieJar { + override fun saveFromResponse(url: HttpUrl, cookies: MutableList) {} + override fun loadForRequest(url: HttpUrl): MutableList { + return ArrayList().apply { + add(Cookie.Builder() + .domain("com-x.life") + .path("/") + .name("antibot") + .value("e28a31fb6bcbc2858bdf53fac455d54a") // avoid - https://antibot.cloud/. Change cookie if userAgent changes + .build()) + } + } + + }) + .build() + + override fun headersBuilder(): Headers.Builder = Headers.Builder() + .add("User-Agent", userAgent) + .add("Referer", baseUrl) + override fun popularMangaSelector() = "div.shortstory1" override fun latestUpdatesSelector() = "ul.last-comix li" @@ -152,7 +174,7 @@ class ComX : ParsedHttpSource() { val urlElement = element.select("a").first() val urlText = urlElement.text() val chapter = SChapter.create() - chapter.name = urlText + chapter.name = urlText.split('/')[0] // Remove english part of name chapter.setUrlWithoutDomain(urlElement.attr("href")) chapter.date_upload = 0 return chapter @@ -172,10 +194,9 @@ class ComX : ParsedHttpSource() { val pages = mutableListOf() - for (i in 0 until urls.size) { + for (i in urls.indices) { pages.add(Page(i, "", link+(urls[i].removeSurrounding("'")))) } - return pages } @@ -186,10 +207,6 @@ class ComX : ParsedHttpSource() { override fun imageUrlParse(document: Document) = "" override fun imageRequest(page: Page): Request { - val imgHeader = Headers.Builder().apply { - add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)") - add("Referer", baseUrl) - }.build() - return GET(page.imageUrl!!, imgHeader) + return GET(page.imageUrl!!, headers) } -} \ No newline at end of file +}