AwkwardPeak7 50b5d33614
Random User-Agent Refactor (#17059)
* lib-randomua

* NHentai: Random mobile ua

* Madara random UA overhaul

* MangaThemesia random UA overhaul

* MangaHub random UA overhaul

* build errors and warnings

* remove preference from Constellar

* change to singleton object

* network.client

* fix copy paste and chapter deep link

* exit early

* use data class and enum options

* missing import

* suggested changes

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* re-add empty check to filters

* convert to interceptor

* update comment

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>

* update error message

* initialize client by lazy

* dont check on excluded Filters

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* newlines

* move preference helper function into lib

* move preference helper function into lib x2

* move check to lib too

* move defaultRandomUserAgentType to constructor

* rename the interceptor

* organize the interceptor and preference stuff in different files

* hide custom ua setting when random ua is enabled

* English

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* catch specific exception

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* setVisible()

fresh stuff

* setVisible()

fresh stuff

* change summary

* workaround

* Update error message

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>

* Update comment

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>

---------

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>
2023-07-15 19:52:35 -03:00

51 lines
1.7 KiB
Kotlin

package eu.kanade.tachiyomi.extension.pt.yugenmangas
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.lib.randomua.UserAgentType
import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent
import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.model.SChapter
import okhttp3.OkHttpClient
import org.jsoup.nodes.Element
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.concurrent.TimeUnit
class YugenMangas : Madara(
"YugenMangas",
"https://yugenmangas.com.br",
"pt-BR",
SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")),
) {
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
.setRandomUserAgent(
UserAgentType.DESKTOP,
)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.rateLimit(1, 3, TimeUnit.SECONDS)
.build()
override fun headersBuilder() = super.headersBuilder()
.add("Origin", baseUrl)
override val useNewChapterEndpoint: Boolean = true
override val mangaSubString = "series"
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
name = element.selectFirst("p.chapter-manhwa-title")!!.text()
date_upload = parseChapterDate(element.selectFirst("span.chapter-release-date i")?.text())
val chapterUrl = element.selectFirst("a")!!.attr("abs:href")
setUrlWithoutDomain(
chapterUrl.substringBefore("?style=paged") +
if (!chapterUrl.endsWith(chapterUrlSuffix)) chapterUrlSuffix else "",
)
}
override fun setupPreferenceScreen(screen: PreferenceScreen) { }
}