[HoneyManga] Fix images urls
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.*
|
||||
private const val PAGE_SIZE = 20
|
||||
private const val INFINITE = 999999
|
||||
private const val HEADER_ENCODING = "Content-Encoding"
|
||||
private const val IMAGE_BASEURL_FALLBACK = "https://hmvolumestorage.b-cdn.net/public-resources"
|
||||
|
||||
@MangaSourceParser("HONEYMANGA", "HoneyManga", "uk")
|
||||
class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context, MangaSource.HONEYMANGA, PAGE_SIZE),
|
||||
@@ -32,10 +33,9 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
||||
private val framesApi get() = "$urlApi/chapter/frames"
|
||||
private val searchApi get() = "https://search.api.$domain/v2/manga/pattern?query="
|
||||
|
||||
private val imageStorageUrl = "https://manga-storage.fra1.digitaloceanspaces.com/public-resources"
|
||||
private val imageStorageUrl = SuspendLazy(::fetchCoversBaseUrl)
|
||||
|
||||
override val configKeyDomain: ConfigKey.Domain
|
||||
get() = ConfigKey.Domain("honey-manga.com.ua")
|
||||
override val configKeyDomain = ConfigKey.Domain("honey-manga.com.ua")
|
||||
|
||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
||||
SortOrder.POPULARITY,
|
||||
@@ -160,9 +160,10 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
||||
val body = JSONObject()
|
||||
body.put("chapterId", chapter.url)
|
||||
val content = webClient.httpPost(framesApi, body).parseJson().getJSONObject("resourceIds")
|
||||
val baseUrl = imageStorageUrl.tryGet().getOrDefault(IMAGE_BASEURL_FALLBACK)
|
||||
return List(content.length()) { i ->
|
||||
val item = content.getString(i.toString())
|
||||
MangaPage(id = generateUid(item), "$imageStorageUrl/$item", getCoverUrl(item, 256), source)
|
||||
MangaPage(id = generateUid(item), "$baseUrl/$item", getCoverUrl(item, 256), source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,9 +194,9 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
||||
return intValue != null && intValue >= 18
|
||||
}
|
||||
|
||||
private fun getCoverUrl(id: String, w: Int): String {
|
||||
// https://honey-manga.com.ua/_next/image?url=https%3A%2F%2Fhoneymangastorage.b-cdn.net%2Fpublic-resources%2F1c4613c2-ffe3-405a-b26a-2cab59ddd223%3Foptimizer%3Dimage%26width%3D512%26height%3D512&w=3840&q=75
|
||||
return "https://$domain/_next/image?url=https%3A%2F%2Fhoneymangastorage.b-cdn.net%2Fpublic-resources%2F$id&w=$w&q=75"
|
||||
private suspend fun getCoverUrl(id: String, w: Int): String {
|
||||
val baseUrl = imageStorageUrl.tryGet().getOrDefault(IMAGE_BASEURL_FALLBACK)
|
||||
return concatUrl(baseUrl, "$id?optimizer=image&width=$w&height=$w")
|
||||
}
|
||||
|
||||
private fun getSortKey(order: SortOrder?) = when (order) {
|
||||
@@ -213,4 +214,14 @@ class HoneyMangaParser(context: MangaLoaderContext) : PagedMangaParser(context,
|
||||
}
|
||||
return tagsSet
|
||||
}
|
||||
|
||||
private suspend fun fetchCoversBaseUrl(): String {
|
||||
val scriptUrl = webClient.httpGet("https://$domain")
|
||||
.parseHtml()
|
||||
.select("script")
|
||||
.firstNotNullOf { it.attrOrNull("src")?.takeIf { x -> x.contains("_app-") } }
|
||||
val script = webClient.httpGet(scriptUrl).parseRaw()
|
||||
// "vg":"https://hmvolumestorage.b-cdn.net/public-resources"
|
||||
return Regex("\"vg\":\"([^\"]+)\"").find(script)?.groups?.get(1)?.value ?: error("Image baseUrl not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.koitharu.kotatsu.test_util.isUrlAbsolute
|
||||
import org.koitharu.kotatsu.test_util.maxDuplicates
|
||||
|
||||
|
||||
@ExtendWith(AuthCheckExtension::class)
|
||||
//@ExtendWith(AuthCheckExtension::class)
|
||||
internal class MangaParserTest {
|
||||
|
||||
private val context = MangaLoaderContextMock
|
||||
|
||||
@@ -3,5 +3,5 @@ package org.koitharu.kotatsu.parsers
|
||||
import org.junit.jupiter.params.provider.EnumSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
@EnumSource(MangaSource::class, names = ["LOCAL", "DUMMY"], mode = EnumSource.Mode.EXCLUDE)
|
||||
@EnumSource(MangaSource::class, names = ["HONEYMANGA"], mode = EnumSource.Mode.INCLUDE)
|
||||
internal annotation class MangaSources
|
||||
|
||||
Reference in New Issue
Block a user