Comx. Fix download some chapter and avoiding antibot feature (#1842)

* Comx. Fix download some chapter and avoiding antibot feature

* Fix build with missing CookieJar
This commit is contained in:
Pavka 2019-12-01 01:06:52 +03:00 committed by arkon
parent 1dfc271ddb
commit b6c602545c
2 changed files with 35 additions and 14 deletions

View File

@ -5,8 +5,12 @@ ext {
appName = 'Tachiyomi: ComX' appName = 'Tachiyomi: ComX'
pkgNameSuffix = 'ru.comx' pkgNameSuffix = 'ru.comx'
extClass = '.ComX' extClass = '.ComX'
extVersionCode = 3 extVersionCode = 4
libVersion = '1.2' libVersion = '1.2'
} }
dependencies {
implementation project(':lib-ratelimit')
}
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.extension.ru.comx 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.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.model.FilterList 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.model.SManga
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.FormBody import okhttp3.*
import okhttp3.Headers
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
@ -24,6 +22,30 @@ class ComX : ParsedHttpSource() {
override val supportsLatest = true 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<Cookie>) {}
override fun loadForRequest(url: HttpUrl): MutableList<Cookie> {
return ArrayList<Cookie>().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 popularMangaSelector() = "div.shortstory1"
override fun latestUpdatesSelector() = "ul.last-comix li" override fun latestUpdatesSelector() = "ul.last-comix li"
@ -152,7 +174,7 @@ class ComX : ParsedHttpSource() {
val urlElement = element.select("a").first() val urlElement = element.select("a").first()
val urlText = urlElement.text() val urlText = urlElement.text()
val chapter = SChapter.create() val chapter = SChapter.create()
chapter.name = urlText chapter.name = urlText.split('/')[0] // Remove english part of name
chapter.setUrlWithoutDomain(urlElement.attr("href")) chapter.setUrlWithoutDomain(urlElement.attr("href"))
chapter.date_upload = 0 chapter.date_upload = 0
return chapter return chapter
@ -172,10 +194,9 @@ class ComX : ParsedHttpSource() {
val pages = mutableListOf<Page>() val pages = mutableListOf<Page>()
for (i in 0 until urls.size) { for (i in urls.indices) {
pages.add(Page(i, "", link+(urls[i].removeSurrounding("'")))) pages.add(Page(i, "", link+(urls[i].removeSurrounding("'"))))
} }
return pages return pages
} }
@ -186,10 +207,6 @@ class ComX : ParsedHttpSource() {
override fun imageUrlParse(document: Document) = "" override fun imageUrlParse(document: Document) = ""
override fun imageRequest(page: Page): Request { override fun imageRequest(page: Page): Request {
val imgHeader = Headers.Builder().apply { return GET(page.imageUrl!!, headers)
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
add("Referer", baseUrl)
}.build()
return GET(page.imageUrl!!, imgHeader)
} }
} }