Hentaiteca: Add random UA (#3819)

* Add random UA

* Fix WebView UA

* Add useLoadMoreRequest

* Fix date format

* Remove hardcode UA
This commit is contained in:
Chopper 2024-07-02 03:47:04 -03:00 committed by Draff
parent b5b65b7be4
commit 5b0a105213
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 52 additions and 7 deletions

View File

@ -3,8 +3,12 @@ ext {
extClass = '.HentaiTeca' extClass = '.HentaiTeca'
themePkg = 'madara' themePkg = 'madara'
baseUrl = 'https://hentaiteca.net' baseUrl = 'https://hentaiteca.net'
overrideVersionCode = 1 overrideVersionCode = 2
isNsfw = true isNsfw = true
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"
dependencies {
implementation project(':lib:randomua')
}

View File

@ -1,20 +1,61 @@
package eu.kanade.tachiyomi.extension.pt.hentaiteca package eu.kanade.tachiyomi.extension.pt.hentaiteca
import android.app.Application
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.lib.randomua.addRandomUAPreferenceToScreen
import eu.kanade.tachiyomi.lib.randomua.getPrefCustomUA
import eu.kanade.tachiyomi.lib.randomua.getPrefUAType
import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent
import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import okhttp3.Headers
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class HentaiTeca : Madara( class HentaiTeca :
Madara(
"Hentai Teca", "Hentai Teca",
"https://hentaiteca.net", "https://hentaiteca.net",
"pt-BR", "pt-BR",
SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")), SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR")),
) { ),
ConfigurableSource {
private val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
override val client: OkHttpClient = super.client.newBuilder() override val client: OkHttpClient = super.client.newBuilder()
.setRandomUserAgent(
preferences.getPrefUAType(),
preferences.getPrefCustomUA(),
)
.rateLimit(1, 2, TimeUnit.SECONDS) .rateLimit(1, 2, TimeUnit.SECONDS)
.build() .build()
override fun headersBuilder(): Headers.Builder = super.headersBuilder()
.addCustomUA()
override val useLoadMoreRequest = LoadMoreStrategy.Never
override fun setupPreferenceScreen(screen: PreferenceScreen) {
addRandomUAPreferenceToScreen(screen)
}
/*
* Using Custom UA also in WebView
* */
private fun Headers.Builder.addCustomUA(): Headers.Builder {
preferences.getPrefCustomUA()
.takeIf { !it.isNullOrBlank() }
?.let { set(UA_KEY, it) }
return this
}
companion object {
const val UA_KEY = "User-Agent"
}
} }