Fix UA list parsing in YM. (#14726)

This commit is contained in:
Alessandro Jean 2022-12-29 19:11:24 -03:00 committed by GitHub
parent 4bb3a039a8
commit f783cf6018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 17 deletions

View File

@ -10,6 +10,7 @@ import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import org.jsoup.nodes.Element
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.concurrent.TimeUnit
@ -52,26 +53,32 @@ class YugenMangas : Madara(
private var checkedUa = false
private fun uaIntercept(chain: Interceptor.Chain): Response {
if (userAgent == null && !checkedUa) {
val uaResponse = chain.proceed(GET(UA_DB_URL))
try {
if (userAgent == null && !checkedUa) {
val uaResponse = chain.proceed(GET(UA_DB_URL))
if (uaResponse.isSuccessful) {
userAgent = json.decodeFromString<List<String>>(uaResponse.body!!.string()).random()
checkedUa = true
if (uaResponse.isSuccessful) {
val uaMap =
json.decodeFromString<Map<String, List<String>>>(uaResponse.body!!.string())
userAgent = uaMap["desktop"]?.random()
checkedUa = true
}
uaResponse.close()
}
uaResponse.close()
if (userAgent != null) {
val newRequest = chain.request().newBuilder()
.header("User-Agent", userAgent!!)
.build()
return chain.proceed(newRequest)
}
return chain.proceed(chain.request())
} catch (e: Exception) {
throw IOException(e.message)
}
if (userAgent != null) {
val newRequest = chain.request().newBuilder()
.header("User-Agent", userAgent!!)
.build()
return chain.proceed(newRequest)
}
return chain.proceed(chain.request())
}
companion object {

View File

@ -442,7 +442,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("YaoiToon", "https://yaoitoon.com", "en", isNsfw = true),
SingleLang("Yetişkin Rüya Manga", "https://yetiskin.ruyamanga.com", "tr", isNsfw = true, className = "YetiskinRuyaManga"),
SingleLang("YonaBar", "https://yonabar.com", "ar", isNsfw = true, overrideVersionCode = 2),
SingleLang("YugenMangas", "https://yugenmangas.com.br", "pt-BR"),
SingleLang("YugenMangas", "https://yugenmangas.com.br", "pt-BR", overrideVersionCode = 1),
SingleLang("Yuri Verso", "https://yuri.live", "pt-BR", overrideVersionCode = 3),
SingleLang("Zero Scan", "https://zeroscan.com.br", "pt-BR", isNsfw = true),
SingleLang("Zinmanga", "https://zinmanga.com", "en", overrideVersionCode = 1),