From 9713ac2bcf5bbc1d4476ccb21c1fadd80d576759 Mon Sep 17 00:00:00 2001 From: Chopper <156493704+ttony2chopper@users.noreply.github.com> Date: Tue, 23 Apr 2024 05:03:57 -0300 Subject: [PATCH] Plot Twist No Fansub: Fix chapters loading (#2516) * Fix loading chapters * Change attribute * Cleanup * Update src/es/plottwistnofansub/build.gradle --- src/es/plottwistnofansub/build.gradle | 6 ++++- .../es/plottwistnofansub/PlotTwistNoFansub.kt | 27 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/es/plottwistnofansub/build.gradle b/src/es/plottwistnofansub/build.gradle index 147ed76eb..a3eb29699 100644 --- a/src/es/plottwistnofansub/build.gradle +++ b/src/es/plottwistnofansub/build.gradle @@ -1,8 +1,12 @@ ext { extName = 'Plot Twist No Fansub' extClass = '.PlotTwistNoFansub' - extVersionCode = 3 + extVersionCode = 4 isNsfw = true } apply from: "$rootDir/common.gradle" + +dependencies { + implementation(project(':lib:randomua')) +} diff --git a/src/es/plottwistnofansub/src/eu/kanade/tachiyomi/extension/es/plottwistnofansub/PlotTwistNoFansub.kt b/src/es/plottwistnofansub/src/eu/kanade/tachiyomi/extension/es/plottwistnofansub/PlotTwistNoFansub.kt index 80ac67320..5ce0db8c6 100644 --- a/src/es/plottwistnofansub/src/eu/kanade/tachiyomi/extension/es/plottwistnofansub/PlotTwistNoFansub.kt +++ b/src/es/plottwistnofansub/src/eu/kanade/tachiyomi/extension/es/plottwistnofansub/PlotTwistNoFansub.kt @@ -1,8 +1,16 @@ package eu.kanade.tachiyomi.extension.es.plottwistnofansub +import android.app.Application +import android.content.SharedPreferences +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.interceptor.rateLimitHost +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 @@ -24,9 +32,11 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import org.jsoup.nodes.Entities import org.jsoup.select.Elements +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -class PlotTwistNoFansub : ParsedHttpSource() { +class PlotTwistNoFansub : ParsedHttpSource(), ConfigurableSource { override val name = "Plot Twist No Fansub" @@ -38,10 +48,21 @@ class PlotTwistNoFansub : ParsedHttpSource() { private val json: Json by injectLazy() - override val client: OkHttpClient = network.client.newBuilder() + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x000) + + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .setRandomUserAgent( + preferences.getPrefUAType(), + preferences.getPrefCustomUA(), + ) .rateLimitHost(baseUrl.toHttpUrl(), 1) .build() + override fun setupPreferenceScreen(screen: PreferenceScreen) { + addRandomUAPreferenceToScreen(screen) + } + override fun headersBuilder(): Headers.Builder = Headers.Builder() .add("Referer", "$baseUrl/") @@ -117,7 +138,7 @@ class PlotTwistNoFansub : ParsedHttpSource() { override fun chapterListParse(response: Response): List { val document = response.asJsoup() - val mangaId = document.selectFirst("div.td-ss-main-content > article[id^=post-]")!!.id().substringAfter("-") + val mangaId = document.selectFirst(".chapters-container .row.itemlist p[data-mangaid]")!!.attr("data-mangaid") val key = getKey(document) val url = "$baseUrl/wp-admin/admin-ajax.php"