Anchira: Fix API changes (#3089)
* Anchira: Fix API changes * Anchira: Update versin code * Anchira: Add interceptor for resampled images, update data URL * Apply suggestions from code review
This commit is contained in:
parent
6bbb9d0da9
commit
871c4d7a22
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'Anchira'
|
||||
extClass = '.Anchira'
|
||||
extVersionCode = 13
|
||||
extVersionCode = 14
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.preference.ListPreference
|
|||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.createChapter
|
||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.getCdn
|
||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.getPathFromUrl
|
||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.prepareTags
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
|
@ -43,7 +44,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
|
||||
override val baseUrl = "https://anchira.to"
|
||||
|
||||
private val apiUrl = "$baseUrl/api/v1"
|
||||
private val apiUrl = baseUrl.replace("://", "://api.")
|
||||
|
||||
private val libraryUrl = "$apiUrl/library"
|
||||
|
||||
|
@ -55,7 +56,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
|
||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||
.rateLimit(3, 1, TimeUnit.SECONDS)
|
||||
.addInterceptor { apiInterceptor(it) }
|
||||
.addInterceptor { resampledInterceptor(it) }
|
||||
.build()
|
||||
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
|
@ -64,7 +65,9 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
override fun headersBuilder() = super.headersBuilder().add("X-Requested-With", "XMLHttpRequest")
|
||||
override fun headersBuilder() = super.headersBuilder()
|
||||
.add("Referer", "$baseUrl/")
|
||||
.add("Origin", baseUrl)
|
||||
|
||||
// Latest
|
||||
|
||||
|
@ -319,7 +322,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
return data.images.mapIndexed { i, image ->
|
||||
Page(
|
||||
i,
|
||||
imageUrl = "$cdnUrl/${imageData.id}/${imageData.key}/${imageData.hash}/b/${image.name}",
|
||||
imageUrl = "${getCdn(i)}/${imageData.id}/${imageData.key}/${imageData.hash}/b/${image.name}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -429,28 +432,20 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
private val SharedPreferences.useTagGrouping
|
||||
get() = getBoolean(USE_TAG_GROUPING, false)
|
||||
|
||||
private fun apiInterceptor(chain: Interceptor.Chain): Response {
|
||||
private fun resampledInterceptor(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val requestUrl = request.url.toString()
|
||||
val url = request.url.toString()
|
||||
|
||||
return if (requestUrl.contains("/api/v1")) {
|
||||
val newRequestBuilder = request.newBuilder()
|
||||
return if (url.contains("sexo.xyz")) {
|
||||
val response = chain.proceed(request)
|
||||
|
||||
if (requestUrl.contains(Regex("/\\d+/\\S+"))) {
|
||||
newRequestBuilder.header(
|
||||
"Referer",
|
||||
requestUrl.replace(libraryUrl, "$baseUrl/g"),
|
||||
)
|
||||
} else if (requestUrl.contains("user/favorites")) {
|
||||
newRequestBuilder.header(
|
||||
"Referer",
|
||||
requestUrl.replace("$apiUrl/user/favorites", "$baseUrl/favorites"),
|
||||
)
|
||||
} else {
|
||||
newRequestBuilder.header("Referer", requestUrl.replace(libraryUrl, baseUrl))
|
||||
if (response.isSuccessful) {
|
||||
return response
|
||||
} else if (url.contains("/b/")) {
|
||||
return chain.proceed(request.newBuilder().url(url.replace("/b/", "/a/")).build())
|
||||
}
|
||||
|
||||
chain.proceed(newRequestBuilder.build())
|
||||
throw IOException("An error occurred while loading the image - ${response.code}")
|
||||
} else {
|
||||
chain.proceed(request)
|
||||
}
|
||||
|
@ -474,7 +469,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
|||
private const val OPEN_SOURCE_PREF = "use_manga_source"
|
||||
private const val USE_TAG_GROUPING = "use_tag_grouping"
|
||||
private const val DATA_JSON =
|
||||
"https://gist.githubusercontent.com/LetrixZ/2b559cc5829d1c221c701e02ecd81411/raw/data-v5.json"
|
||||
"https://raw.githubusercontent.com/LetrixZ/gallery-data/main/extension_data.min.json"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ object AnchiraHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun getCdn(page: Int) = if (page % 2 == 0) "https://kisakisexo.xyz" else "https://aronasexo.xyz"
|
||||
|
||||
private fun String.titleCase() = replaceFirstChar {
|
||||
if (it.isLowerCase()) {
|
||||
it.titlecase(Locale.getDefault())
|
||||
|
|
Loading…
Reference in New Issue