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 {
|
ext {
|
||||||
extName = 'Anchira'
|
extName = 'Anchira'
|
||||||
extClass = '.Anchira'
|
extClass = '.Anchira'
|
||||||
extVersionCode = 13
|
extVersionCode = 14
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.createChapter
|
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.getPathFromUrl
|
||||||
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.prepareTags
|
import eu.kanade.tachiyomi.extension.en.anchira.AnchiraHelper.prepareTags
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
@ -43,7 +44,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
override val baseUrl = "https://anchira.to"
|
override val baseUrl = "https://anchira.to"
|
||||||
|
|
||||||
private val apiUrl = "$baseUrl/api/v1"
|
private val apiUrl = baseUrl.replace("://", "://api.")
|
||||||
|
|
||||||
private val libraryUrl = "$apiUrl/library"
|
private val libraryUrl = "$apiUrl/library"
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||||
.rateLimit(3, 1, TimeUnit.SECONDS)
|
.rateLimit(3, 1, TimeUnit.SECONDS)
|
||||||
.addInterceptor { apiInterceptor(it) }
|
.addInterceptor { resampledInterceptor(it) }
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private val json = Json { ignoreUnknownKeys = true }
|
private val json = Json { ignoreUnknownKeys = true }
|
||||||
|
@ -64,7 +65,9 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
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
|
// Latest
|
||||||
|
|
||||||
|
@ -319,7 +322,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
return data.images.mapIndexed { i, image ->
|
return data.images.mapIndexed { i, image ->
|
||||||
Page(
|
Page(
|
||||||
i,
|
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
|
private val SharedPreferences.useTagGrouping
|
||||||
get() = getBoolean(USE_TAG_GROUPING, false)
|
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 request = chain.request()
|
||||||
val requestUrl = request.url.toString()
|
val url = request.url.toString()
|
||||||
|
|
||||||
return if (requestUrl.contains("/api/v1")) {
|
return if (url.contains("sexo.xyz")) {
|
||||||
val newRequestBuilder = request.newBuilder()
|
val response = chain.proceed(request)
|
||||||
|
|
||||||
if (requestUrl.contains(Regex("/\\d+/\\S+"))) {
|
if (response.isSuccessful) {
|
||||||
newRequestBuilder.header(
|
return response
|
||||||
"Referer",
|
} else if (url.contains("/b/")) {
|
||||||
requestUrl.replace(libraryUrl, "$baseUrl/g"),
|
return chain.proceed(request.newBuilder().url(url.replace("/b/", "/a/")).build())
|
||||||
)
|
|
||||||
} else if (requestUrl.contains("user/favorites")) {
|
|
||||||
newRequestBuilder.header(
|
|
||||||
"Referer",
|
|
||||||
requestUrl.replace("$apiUrl/user/favorites", "$baseUrl/favorites"),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
newRequestBuilder.header("Referer", requestUrl.replace(libraryUrl, baseUrl))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.proceed(newRequestBuilder.build())
|
throw IOException("An error occurred while loading the image - ${response.code}")
|
||||||
} else {
|
} else {
|
||||||
chain.proceed(request)
|
chain.proceed(request)
|
||||||
}
|
}
|
||||||
|
@ -474,7 +469,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
private const val OPEN_SOURCE_PREF = "use_manga_source"
|
private const val OPEN_SOURCE_PREF = "use_manga_source"
|
||||||
private const val USE_TAG_GROUPING = "use_tag_grouping"
|
private const val USE_TAG_GROUPING = "use_tag_grouping"
|
||||||
private const val DATA_JSON =
|
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 {
|
private fun String.titleCase() = replaceFirstChar {
|
||||||
if (it.isLowerCase()) {
|
if (it.isLowerCase()) {
|
||||||
it.titlecase(Locale.getDefault())
|
it.titlecase(Locale.getDefault())
|
||||||
|
|
Loading…
Reference in New Issue