Skip to content

Commit

Permalink
Rizz Comic: use random User-Agent to avoid blocking (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-tran committed Jan 16, 2024
1 parent dd5cf18 commit 3ed83d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/en/rizzcomic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ ext {
extName = 'Rizz Comic'
pkgNameSuffix = 'en.rizzcomic'
extClass = '.RizzComic'
extVersionCode = 1
extVersionCode = 2
}

apply from: "$rootDir/common.gradle"
apply from: "$rootDir/common.gradle"

dependencies {
implementation(project(":lib-randomua"))
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package eu.kanade.tachiyomi.extension.en.rizzcomic

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.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
Expand All @@ -18,11 +25,13 @@ import okhttp3.FormBody
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.text.SimpleDateFormat
import java.util.Locale

class RizzComic : HttpSource() {
class RizzComic : HttpSource(), ConfigurableSource {

override val name = "Rizz Comic"

Expand All @@ -34,9 +43,19 @@ class RizzComic : HttpSource() {

private val json: Json by injectLazy()

override val client = network.cloudflareClient.newBuilder()
.rateLimit(1)
.build()
private val preferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

override val client by lazy {
network.cloudflareClient.newBuilder()
.setRandomUserAgent(
preferences.getPrefUAType(),
preferences.getPrefCustomUA(),
)
.rateLimit(1, 3)
.build()
}

override fun headersBuilder() = super.headersBuilder()
.set("Referer", "$baseUrl/")
Expand Down Expand Up @@ -254,6 +273,10 @@ class RizzComic : HttpSource() {
return GET(page.imageUrl!!, newHeaders)
}

override fun setupPreferenceScreen(screen: PreferenceScreen) {
addRandomUAPreferenceToScreen(screen)
}

override fun mangaDetailsParse(response: Response): SManga {
throw UnsupportedOperationException("Not Used")
}
Expand Down

0 comments on commit 3ed83d7

Please sign in to comment.