Anchira - Apply API changes (#180)
This commit is contained in:
parent
84418c477f
commit
a9faf70d33
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'Anchira'
|
extName = 'Anchira'
|
||||||
pkgNameSuffix = 'en.anchira'
|
pkgNameSuffix = 'en.anchira'
|
||||||
extClass = '.Anchira'
|
extClass = '.Anchira'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
override fun latestUpdatesRequest(page: Int) = GET("$libraryUrl?page=$page", headers)
|
override fun latestUpdatesRequest(page: Int) = GET("$libraryUrl?page=$page", headers)
|
||||||
|
|
||||||
override fun latestUpdatesParse(response: Response): MangasPage {
|
override fun latestUpdatesParse(response: Response): MangasPage {
|
||||||
val data = decodeBytes<LibraryResponse>(response.body)
|
val data = decodeBytes<LibraryResponse>(response.body, anchiraData.key)
|
||||||
|
|
||||||
return MangasPage(
|
return MangasPage(
|
||||||
data.entries.map {
|
data.entries.map {
|
||||||
|
@ -154,7 +154,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
GET("$libraryUrl/${getPathFromUrl(manga.url)}", headers)
|
GET("$libraryUrl/${getPathFromUrl(manga.url)}", headers)
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response): SManga {
|
override fun mangaDetailsParse(response: Response): SManga {
|
||||||
val data = decodeBytes<Entry>(response.body)
|
val data = decodeBytes<Entry>(response.body, anchiraData.key)
|
||||||
|
|
||||||
return SManga.create().apply {
|
return SManga.create().apply {
|
||||||
url = "/g/${data.id}/${data.key}"
|
url = "/g/${data.id}/${data.key}"
|
||||||
|
@ -171,7 +171,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
override fun getMangaUrl(manga: SManga) = if (preferences.openSource) {
|
override fun getMangaUrl(manga: SManga) = if (preferences.openSource) {
|
||||||
val id = manga.url.split("/").reversed()[1].toInt()
|
val id = manga.url.split("/").reversed()[1].toInt()
|
||||||
entryExtraData.find { it.id == id }?.url ?: "$baseUrl${manga.url}"
|
anchiraData.galleries.find { it.id == id }?.url ?: "$baseUrl${manga.url}"
|
||||||
} else {
|
} else {
|
||||||
"$baseUrl${manga.url}"
|
"$baseUrl${manga.url}"
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
GET("$libraryUrl/${getPathFromUrl(manga.url)}", headers)
|
GET("$libraryUrl/${getPathFromUrl(manga.url)}", headers)
|
||||||
|
|
||||||
override fun chapterListParse(response: Response): List<SChapter> {
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
val data = decodeBytes<Entry>(response.body)
|
val data = decodeBytes<Entry>(response.body, anchiraData.key)
|
||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
|
@ -202,7 +202,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
GET("$libraryUrl/${getPathFromUrl(chapter.url)}", headers)
|
GET("$libraryUrl/${getPathFromUrl(chapter.url)}", headers)
|
||||||
|
|
||||||
override fun pageListParse(response: Response): List<Page> {
|
override fun pageListParse(response: Response): List<Page> {
|
||||||
val data = decodeBytes<Entry>(response.body)
|
val data = decodeBytes<Entry>(response.body, anchiraData.key)
|
||||||
val imageData = getImageData(data)
|
val imageData = getImageData(data)
|
||||||
|
|
||||||
return data.data.mapIndexed { i, img ->
|
return data.data.mapIndexed { i, img ->
|
||||||
|
@ -214,7 +214,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getImageData(entry: Entry): ImageData {
|
private fun getImageData(entry: Entry): ImageData {
|
||||||
val keys = entryExtraData.find { it.id == entry.id }
|
val keys = anchiraData.galleries.find { it.id == entry.id }
|
||||||
|
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
return ImageData(keys.id, keys.key, keys.hash)
|
return ImageData(keys.id, keys.key, keys.hash)
|
||||||
|
@ -225,7 +225,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
client.newCall(GET("$libraryUrl/${entry.id}/${entry.key}/data", headers)).execute()
|
client.newCall(GET("$libraryUrl/${entry.id}/${entry.key}/data", headers)).execute()
|
||||||
val body = response.body
|
val body = response.body
|
||||||
|
|
||||||
return decodeBytes(body)
|
return decodeBytes(body, anchiraData.key)
|
||||||
} catch (_: IOException) {
|
} catch (_: IOException) {
|
||||||
throw IOException("Complete a Captcha in the site to continue")
|
throw IOException("Complete a Captcha in the site to continue")
|
||||||
}
|
}
|
||||||
|
@ -323,15 +323,15 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
it.name == "session"
|
it.name == "session"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val entryExtraData by lazy {
|
private val anchiraData by lazy {
|
||||||
client.newCall(GET(KEYS_JSON, headers)).execute()
|
client.newCall(GET(DATA_JSON, headers)).execute()
|
||||||
.use { json.decodeFromStream<List<ExtraData>>(it.body.byteStream()) }
|
.use { json.decodeFromStream<AnchiraData>(it.body.byteStream()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val IMAGE_QUALITY_PREF = "image_quality"
|
private const val IMAGE_QUALITY_PREF = "image_quality"
|
||||||
private const val OPEN_SOURCE_PREF = "use_manga_source"
|
private const val OPEN_SOURCE_PREF = "use_manga_source"
|
||||||
private const val KEYS_JSON =
|
private const val DATA_JSON =
|
||||||
"https://gist.githubusercontent.com/LetrixZ/2b559cc5829d1c221c701e02ecd81411/raw/keys.json"
|
"https://gist.githubusercontent.com/LetrixZ/2b559cc5829d1c221c701e02ecd81411/raw/site_data.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,15 @@ data class ImageData(
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ExtraData(
|
data class EntryKey(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val key: String,
|
val key: String,
|
||||||
val hash: String,
|
val hash: String,
|
||||||
val url: String?,
|
val url: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class AnchiraData(
|
||||||
|
val key: String,
|
||||||
|
val galleries: List<EntryKey>,
|
||||||
|
)
|
||||||
|
|
|
@ -7,18 +7,18 @@ import okhttp3.ResponseBody
|
||||||
import okio.ByteString.Companion.decodeBase64
|
import okio.ByteString.Companion.decodeBase64
|
||||||
|
|
||||||
object AnchiraHelper {
|
object AnchiraHelper {
|
||||||
const val KEY = "ZnVjayBuaWdnZXJzIGFuZCBmYWdnb3RzLCBhbmQgZGVhdGggdG8gYWxsIGpld3M="
|
const val KEY = "ZnVja19uaWdnZXJzX2FuZF9mYWdnb3RzLF9hbmRfZGVhdGhfdG9fYWxsX2pld3M="
|
||||||
|
|
||||||
val json = Json { ignoreUnknownKeys = true }
|
val json = Json { ignoreUnknownKeys = true }
|
||||||
|
|
||||||
fun getPathFromUrl(url: String) = "${url.split("/").reversed()[1]}/${url.split("/").last()}"
|
fun getPathFromUrl(url: String) = "${url.split("/").reversed()[1]}/${url.split("/").last()}"
|
||||||
|
|
||||||
inline fun <reified T> decodeBytes(body: ResponseBody): T {
|
inline fun <reified T> decodeBytes(body: ResponseBody, key: String = KEY): T {
|
||||||
val encryptedText = body.string().decodeBase64()!!
|
val encryptedText = body.string().decodeBase64()!!
|
||||||
return json.decodeFromString(
|
return json.decodeFromString(
|
||||||
XXTEA.decryptToString(
|
XXTEA.decryptToString(
|
||||||
encryptedText.toByteArray(),
|
encryptedText.toByteArray(),
|
||||||
key = Base64.decode(KEY, Base64.DEFAULT).decodeToString(),
|
key = Base64.decode(key, Base64.DEFAULT).decodeToString(),
|
||||||
)!!,
|
)!!,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue