Bypass CF in YM and add a harsher rate limiting. (#11138)

This commit is contained in:
Alessandro Jean 2022-03-16 10:54:54 -03:00 committed by GitHub
parent cf07fe4326
commit 99d7c00d5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 4 deletions

View File

@ -2,10 +2,14 @@ package eu.kanade.tachiyomi.extension.all.yugenmangas
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers import okhttp3.Headers
import okhttp3.Interceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Response
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
@ -25,7 +29,7 @@ abstract class YugenMangas(
) : Madara("YugenMangas", baseUrl, lang, dateFormat) { ) : Madara("YugenMangas", baseUrl, lang, dateFormat) {
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
name = element.selectFirst("a")!!.ownText() name = element.selectFirst("p.chapter-manhwa-title")!!.text()
date_upload = parseChapterDate(element.selectFirst("span.chapter-release-date i")?.text()) date_upload = parseChapterDate(element.selectFirst("span.chapter-release-date i")?.text())
val chapterUrl = element.selectFirst("a")!!.attr("abs:href") val chapterUrl = element.selectFirst("a")!!.attr("abs:href")
@ -45,11 +49,51 @@ class YugenMangasBr : YugenMangas(
) { ) {
override val client: OkHttpClient = super.client.newBuilder() override val client: OkHttpClient = super.client.newBuilder()
.addInterceptor(RateLimitInterceptor(1, 2, TimeUnit.SECONDS)) .addInterceptor(::uaIntercept)
.addInterceptor(RateLimitInterceptor(1, 3, TimeUnit.SECONDS))
.build() .build()
override fun headersBuilder(): Headers.Builder = Headers.Builder() override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("Referer", baseUrl) .add("Origin", baseUrl)
.add("Referer", "$baseUrl/")
override val formHeaders: Headers = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.set("Referer", "$baseUrl/todas-las-series/")
.build()
override val useNewChapterEndpoint: Boolean = true override val useNewChapterEndpoint: Boolean = true
private var userAgent: String? = null
private var checkedUa = false
private fun uaIntercept(chain: Interceptor.Chain): Response {
if (userAgent == null && !checkedUa) {
val browser = BROWSERS.random()
val uaResponse = chain.proceed(GET("$UA_DB_URL/$browser"))
if (uaResponse.isSuccessful) {
userAgent = uaResponse.asJsoup()
.select(".listing-of-useragents span.code")
.firstOrNull()
?.text()
checkedUa = true
}
}
if (userAgent != null) {
val newRequest = chain.request().newBuilder()
.header("User-Agent", userAgent!!)
.build()
return chain.proceed(newRequest)
}
return chain.proceed(chain.request())
}
companion object {
private val BROWSERS = arrayOf("chrome", "firefox", "edge", "opera", "vivaldi")
private const val UA_DB_URL = "https://whatismybrowser.com/guides/the-latest-user-agent"
}
} }

View File

@ -18,7 +18,7 @@ class MadaraGenerator : ThemeSourceGenerator {
MultiLang("Manhwa18.cc", "https://manhwa18.cc", listOf("en", "ko", "all"), isNsfw = true, className = "Manhwa18CcFactory", pkgName = "manhwa18cc", overrideVersionCode = 1), MultiLang("Manhwa18.cc", "https://manhwa18.cc", listOf("en", "ko", "all"), isNsfw = true, className = "Manhwa18CcFactory", pkgName = "manhwa18cc", overrideVersionCode = 1),
MultiLang("Reaper Scans", "https://reaperscans.com", listOf("en", "pt-BR"), className = "ReaperScansFactory", pkgName = "reaperscans", overrideVersionCode = 3), MultiLang("Reaper Scans", "https://reaperscans.com", listOf("en", "pt-BR"), className = "ReaperScansFactory", pkgName = "reaperscans", overrideVersionCode = 3),
MultiLang("Seven King Scanlation", "https://sksubs.net", listOf("es", "en"), isNsfw = true), MultiLang("Seven King Scanlation", "https://sksubs.net", listOf("es", "en"), isNsfw = true),
MultiLang("YugenMangas", "https://yugenmangas.com", listOf("es", "pt-BR"), overrideVersionCode = 1), MultiLang("YugenMangas", "https://yugenmangas.com", listOf("es", "pt-BR"), overrideVersionCode = 2),
SingleLang("1st Kiss Manga.love", "https://1stkissmanga.love", "en", className = "FirstKissMangaLove"), SingleLang("1st Kiss Manga.love", "https://1stkissmanga.love", "en", className = "FirstKissMangaLove"),
SingleLang("1st Kiss Manhua", "https://1stkissmanhua.com", "en", className = "FirstKissManhua", overrideVersionCode = 2), SingleLang("1st Kiss Manhua", "https://1stkissmanhua.com", "en", className = "FirstKissManhua", overrideVersionCode = 2),
SingleLang("1st Kiss", "https://1stkissmanga.io", "en", className = "FirstKissManga", pkgName = "firstkissmanga", overrideVersionCode = 6), SingleLang("1st Kiss", "https://1stkissmanga.io", "en", className = "FirstKissManga", pkgName = "firstkissmanga", overrideVersionCode = 6),