Plot Twist No Fansub: Fix chapters loading (#2516)

* Fix loading chapters

* Change attribute

* Cleanup

* Update src/es/plottwistnofansub/build.gradle
This commit is contained in:
Chopper 2024-04-23 05:03:57 -03:00 committed by Draff
parent 7ec1b79d3c
commit 9713ac2bcf
2 changed files with 29 additions and 4 deletions

View File

@ -1,8 +1,12 @@
ext { ext {
extName = 'Plot Twist No Fansub' extName = 'Plot Twist No Fansub'
extClass = '.PlotTwistNoFansub' extClass = '.PlotTwistNoFansub'
extVersionCode = 3 extVersionCode = 4
isNsfw = true isNsfw = true
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"
dependencies {
implementation(project(':lib:randomua'))
}

View File

@ -1,8 +1,16 @@
package eu.kanade.tachiyomi.extension.es.plottwistnofansub 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.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost 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.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage 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.Element
import org.jsoup.nodes.Entities import org.jsoup.nodes.Entities
import org.jsoup.select.Elements import org.jsoup.select.Elements
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class PlotTwistNoFansub : ParsedHttpSource() { class PlotTwistNoFansub : ParsedHttpSource(), ConfigurableSource {
override val name = "Plot Twist No Fansub" override val name = "Plot Twist No Fansub"
@ -38,10 +48,21 @@ class PlotTwistNoFansub : ParsedHttpSource() {
private val json: Json by injectLazy() private val json: Json by injectLazy()
override val client: OkHttpClient = network.client.newBuilder() private val preferences: SharedPreferences =
Injekt.get<Application>().getSharedPreferences("source_$id", 0x000)
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
.setRandomUserAgent(
preferences.getPrefUAType(),
preferences.getPrefCustomUA(),
)
.rateLimitHost(baseUrl.toHttpUrl(), 1) .rateLimitHost(baseUrl.toHttpUrl(), 1)
.build() .build()
override fun setupPreferenceScreen(screen: PreferenceScreen) {
addRandomUAPreferenceToScreen(screen)
}
override fun headersBuilder(): Headers.Builder = Headers.Builder() override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("Referer", "$baseUrl/") .add("Referer", "$baseUrl/")
@ -117,7 +138,7 @@ class PlotTwistNoFansub : ParsedHttpSource() {
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup() 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 key = getKey(document)
val url = "$baseUrl/wp-admin/admin-ajax.php" val url = "$baseUrl/wp-admin/admin-ajax.php"