MangaSwat: fix order filter & preven 302 redirect (#4582)

This commit is contained in:
AwkwardPeak7 2024-08-13 06:13:59 +05:00 committed by Draff
parent 2bbdd0a351
commit 50e1900029
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 36 additions and 15 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.MangaSwat' extClass = '.MangaSwat'
themePkg = 'mangathemesia' themePkg = 'mangathemesia'
baseUrl = 'https://tatwt.com' baseUrl = 'https://tatwt.com'
overrideVersionCode = 21 overrideVersionCode = 22
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.extension.ar.mangaswat package eu.kanade.tachiyomi.extension.ar.mangaswat
import android.app.Application import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast import android.widget.Toast
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
@ -12,7 +11,6 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
@ -32,29 +30,53 @@ class MangaSwat :
override val baseUrl by lazy { getPrefBaseUrl() } override val baseUrl by lazy { getPrefBaseUrl() }
private val preferences: SharedPreferences by lazy { private val preferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000) Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
} }
override val client: OkHttpClient = super.client.newBuilder() override val client = super.client.newBuilder()
.rateLimit(1) .rateLimit(1)
.build() .build()
override fun latestUpdatesRequest(page: Int): Request {
val filter = FilterList(OrderByFilter("", orderByFilterOptions, "added"))
return searchMangaRequest(page, "", filter)
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val request = super.searchMangaRequest(page, query, filters) val request = super.searchMangaRequest(page, query, filters)
if (query.isBlank()) return request val urlBuilder = request.url.newBuilder()
val url = request.url.newBuilder() // remove trailing slash
if (request.url.pathSegments.last().isBlank()) {
urlBuilder.removePathSegment(
request.url.pathSegments.lastIndex,
)
}
if (query.isNotBlank()) {
urlBuilder
.removePathSegment(0) .removePathSegment(0)
.removeAllQueryParameters("title") .removeAllQueryParameters("title")
.addQueryParameter("s", query) .addQueryParameter("s", query)
.build() .build()
}
return request.newBuilder() return request.newBuilder()
.url(url) .url(urlBuilder.build())
.build() .build()
} }
override val orderByFilterOptions = arrayOf(
Pair(intl["order_by_filter_default"], ""),
Pair(intl["order_by_filter_az"], "a-z"),
Pair(intl["order_by_filter_za"], "z-a"),
Pair(intl["order_by_filter_latest_update"], "update"),
Pair(intl["order_by_filter_latest_added"], "added"),
Pair(intl["order_by_filter_popular"], "popular"),
)
override fun searchMangaNextPageSelector() = "a[rel=next]" override fun searchMangaNextPageSelector() = "a[rel=next]"
override val seriesTitleSelector = "h1[itemprop=headline]" override val seriesTitleSelector = "h1[itemprop=headline]"
@ -82,13 +104,12 @@ class MangaSwat :
} }
@Serializable @Serializable
data class TSReader( class TSReader(
val sources: List<ReaderImageSource>, val sources: List<ReaderImageSource>,
) )
@Serializable @Serializable
data class ReaderImageSource( class ReaderImageSource(
val source: String,
val images: List<String>, val images: List<String>,
) )