Koharu | Fix Pages (#4539)

Fix Pages

- Fix Chapter Images
- Fix Chapter not being viewable when quality's `id` or `public_key` is not provided
This commit is contained in:
KenjieDec 2024-08-10 12:16:56 +07:00 committed by Draff
parent b99fc8af0d
commit db149972bd
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 37 additions and 19 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Koharu' extName = 'Koharu'
extClass = '.Koharu' extClass = '.Koharu'
extVersionCode = 5 extVersionCode = 6
isNsfw = true isNsfw = true
} }

View File

@ -68,25 +68,43 @@ class Koharu : HttpSource(), ConfigurableSource {
thumbnail_url = book.thumbnail.path thumbnail_url = book.thumbnail.path
} }
private fun getImagesByMangaEntry(entry: MangaEntry): ImagesInfo { private fun getImagesByMangaEntry(entry: MangaEntry): Pair<ImagesInfo, String> {
val data = entry.data val data = entry.data
val dataKey = when (quality()) { val quality = 0
"1600" -> data.`1600` ?: data.`1280` ?: data.`0` fun getIPK(
"1280" -> data.`1280` ?: data.`1600` ?: data.`0` ori: DataKey?,
"980" -> data.`980` ?: data.`1280` ?: data.`0` alt1: DataKey?,
"780" -> data.`780` ?: data.`980` ?: data.`0` alt2: DataKey?,
else -> data.`0` alt3: DataKey?,
alt4: DataKey?,
): Pair<Int?, String?> {
return Pair(
ori?.id ?: alt1?.id ?: alt2?.id ?: alt3?.id ?: alt4?.id,
ori?.public_key ?: alt1?.public_key ?: alt2?.public_key ?: alt3?.public_key ?: alt4?.public_key,
)
} }
val realQuality = when (dataKey) { val (id, public_key) = when (quality()) {
data.`1600` -> "1600" "1600" -> getIPK(data.`1600`, data.`1280`, data.`0`, data.`980`, data.`780`)
data.`1280` -> "1280" "1280" -> getIPK(data.`1280`, data.`1600`, data.`0`, data.`980`, data.`780`)
data.`980` -> "980" "980" -> getIPK(data.`980`, data.`1280`, data.`0`, data.`1600`, data.`780`)
data.`780` -> "780" "780" -> getIPK(data.`780`, data.`980`, data.`0`, data.`1280`, data.`1600`)
else -> getIPK(data.`0`, data.`1600`, data.`1280`, data.`980`, data.`780`)
}
if (id == null || public_key == null) {
throw Exception("No Images Found")
}
val realQuality = when (id) {
data.`1600`?.id -> "1600"
data.`1280`?.id -> "1280"
data.`980`?.id -> "980"
data.`780`?.id -> "780"
else -> "0" else -> "0"
} }
val imagesResponse = client.newCall(GET("$apiBooksUrl/data/${entry.id}/${entry.public_key}/${dataKey.id}/${dataKey.public_key}?v=${entry.updated_at ?: entry.created_at}&w=$realQuality", headers)).execute() val imagesResponse = client.newCall(GET("$apiBooksUrl/data/${entry.id}/${entry.public_key}/$id/$public_key?v=${entry.updated_at ?: entry.created_at}&w=$realQuality", headers)).execute()
val images = imagesResponse.parseAs<ImagesInfo>() val images = imagesResponse.parseAs<ImagesInfo>() to realQuality
return images return images
} }
@ -308,8 +326,8 @@ class Koharu : HttpSource(), ConfigurableSource {
val mangaEntry = response.parseAs<MangaEntry>() val mangaEntry = response.parseAs<MangaEntry>()
val imagesInfo = getImagesByMangaEntry(mangaEntry) val imagesInfo = getImagesByMangaEntry(mangaEntry)
return imagesInfo.entries.mapIndexed { index, image -> return imagesInfo.first.entries.mapIndexed { index, image ->
Page(index, imageUrl = "${imagesInfo.base}/${image.path}") Page(index, imageUrl = "${imagesInfo.first.base}/${image.path}?w=${imagesInfo.second}")
} }
} }

View File

@ -59,9 +59,9 @@ class Data(
@Serializable @Serializable
class DataKey( class DataKey(
val id: Int, val id: Int? = null,
val size: Double = 0.0, val size: Double = 0.0,
val public_key: String, val public_key: String? = null,
) { ) {
fun readableSize() = when { fun readableSize() = when {
size >= 300 * 1000 * 1000 -> "${"%.2f".format(size / (1000.0 * 1000.0 * 1000.0))} GB" size >= 300 * 1000 * 1000 -> "${"%.2f".format(size / (1000.0 * 1000.0 * 1000.0))} GB"