MadTheme: update rate limit for chapter endpoint (#13357)

* MadTheme: update rate limit for chapter endpoint

* Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madtheme/MadTheme.kt

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

* Don't throw null exception

* Remove unneeded variable

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>
This commit is contained in:
Vetle Ledaal 2022-09-06 16:11:38 +02:00 committed by GitHub
parent 0046749cca
commit cfa7d21bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View File

@ -5,10 +5,7 @@ import android.content.SharedPreferences
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.multisrc.madtheme.MadTheme
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
import eu.kanade.tachiyomi.source.ConfigurableSource
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -19,10 +16,6 @@ class MangaBuddy :
"en"
),
ConfigurableSource {
override val client: OkHttpClient = super.client.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 1, 1)
.build()
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

View File

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.multisrc.madtheme
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservable
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
@ -12,6 +14,8 @@ import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
@ -19,6 +23,7 @@ import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
import uy.kohesive.injekt.injectLazy
import java.text.ParseException
import java.text.SimpleDateFormat
@ -42,6 +47,12 @@ abstract class MadTheme(
.rateLimitHost("https://s1.mbcdnv5.xyz".toHttpUrl(), 1, 1)
.build()
// TODO: better cookie sharing
// TODO: don't count cached responses against rate limit
private val chapterClient: OkHttpClient = network.cloudflareClient.newBuilder()
.rateLimit(1, 12)
.build()
override fun headersBuilder() = Headers.Builder().apply {
add("Referer", "$baseUrl/")
}
@ -150,6 +161,35 @@ abstract class MadTheme(
}
// Chapters
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
// API is heavily rate limited. Use custom client
return if (manga.status != SManga.LICENSED) {
chapterClient.newCall(chapterListRequest(manga))
.asObservable()
.map { response ->
chapterListParse(response)
}
} else {
Observable.error(Exception("Licensed - No chapters to show"))
}
}
override fun chapterListParse(response: Response): List<SChapter> {
if (response.code in 200..299) {
return super.chapterListParse(response)
}
// Try to use message from site
response.body?.let { body ->
json.decodeFromString<JsonObject>(body.string())["message"]
?.jsonPrimitive
?.content
?.let { throw Exception(it) }
}
throw Exception("HTTP error ${response.code}")
}
override fun chapterListRequest(manga: SManga): Request =
GET("$baseUrl/api/manga${manga.url}/chapters?source=detail", headers)

View File

@ -9,7 +9,7 @@ class MadThemeGenerator : ThemeSourceGenerator {
override val themeClass = "MadTheme"
override val baseVersionCode: Int = 8
override val baseVersionCode: Int = 9
override val sources = listOf(
SingleLang("BeeHentai", "https://beehentai.com", "en", isNsfw = true),