Hiyobi file structure changed
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.list
|
||||
import xyz.quaver.proxy
|
||||
import java.net.URL
|
||||
|
||||
@@ -26,12 +25,10 @@ const val protocol = "https:"
|
||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
||||
fun getGalleryInfo(galleryID: Int) =
|
||||
Json.nonstrict.parse(
|
||||
GalleryInfo.serializer().list,
|
||||
Regex("""\[.+]""").find(
|
||||
URL("$protocol//$domain/galleries/$galleryID.js").openConnection(proxy).getInputStream().use {
|
||||
it.reader().readText()
|
||||
}
|
||||
)?.value ?: "[]"
|
||||
GalleryInfo.serializer(),
|
||||
URL("$protocol//$domain/galleries/$galleryID.js").openConnection(proxy).getInputStream().use {
|
||||
it.reader().readText()
|
||||
}.replace("var galleryinfo = ", "")
|
||||
)
|
||||
|
||||
//common.js
|
||||
@@ -71,6 +68,7 @@ fun urlFromURL(url: String, base: String? = null) : String {
|
||||
return url.replace(Regex("""//..?\.hitomi\.la/"""), "//${subdomainFromURL(url, base)}.hitomi.la/")
|
||||
}
|
||||
|
||||
|
||||
fun fullPathFromHash(hash: String?) : String? {
|
||||
return when {
|
||||
(hash?.length ?: 0) < 3 -> hash
|
||||
@@ -79,11 +77,20 @@ fun fullPathFromHash(hash: String?) : String? {
|
||||
}
|
||||
|
||||
@Suppress("NAME_SHADOWING", "UNUSED_PARAMETER")
|
||||
fun urlFromHash(galleryID: Int, image: GalleryInfo, dir: String? = null, ext: String? = null) : String {
|
||||
fun urlFromHash(galleryID: Int, image: GalleryFiles, dir: String? = null, ext: String? = null) : String {
|
||||
val ext = ext ?: dir ?: image.name.split('.').last()
|
||||
val dir = dir ?: "images"
|
||||
return "$protocol//a.hitomi.la/$dir/${fullPathFromHash(image.hash)}.$ext"
|
||||
}
|
||||
|
||||
fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, dir: String? = null, ext: String? = null, base: String? = null) =
|
||||
urlFromURL(urlFromHash(galleryID, image, dir, ext), base)
|
||||
fun urlFromUrlFromHash(galleryID: Int, image: GalleryFiles, dir: String? = null, ext: String? = null, base: String? = null) =
|
||||
urlFromURL(urlFromHash(galleryID, image, dir, ext), base)
|
||||
|
||||
fun imageUrlFromImage(galleryID: Int, image: GalleryFiles, noWebp: Boolean) : String {
|
||||
val webp = if (image.hash != null && image.haswebp != 0 && !noWebp)
|
||||
"webp"
|
||||
else
|
||||
null
|
||||
|
||||
return urlFromUrlFromHash(galleryID, image, webp)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ fun getGallery(galleryID: Int) : Gallery {
|
||||
href.slice(5 until href.indexOf('-'))
|
||||
}
|
||||
|
||||
val thumbnails = getGalleryInfo(galleryID).map { galleryInfo ->
|
||||
val thumbnails = getGalleryInfo(galleryID).files.map { galleryInfo ->
|
||||
urlFromUrlFromHash(galleryID, galleryInfo, "smalltn", "jpg", "tn")
|
||||
}
|
||||
|
||||
|
||||
@@ -17,29 +17,35 @@
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.proxy
|
||||
|
||||
fun getReferer(galleryID: Int) = "https://hitomi.la/reader/$galleryID.html"
|
||||
|
||||
@Serializable
|
||||
data class GalleryInfo(
|
||||
val language_localname: String? = null,
|
||||
val language: String? = null,
|
||||
val date: String? = null,
|
||||
val files: List<GalleryFiles>,
|
||||
val id: Int? = null,
|
||||
val type: String? = null,
|
||||
val title: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GalleryFiles(
|
||||
val width: Int,
|
||||
val hash: String? = null,
|
||||
val haswebp: Int = 0,
|
||||
val name: String,
|
||||
val height: Int
|
||||
val height: Int,
|
||||
val hasavif: Int = 0
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Reader(val code: Code, val title: String, val galleryInfo: List<GalleryInfo>)
|
||||
data class Reader(val code: Code, val galleryInfo: GalleryInfo)
|
||||
|
||||
//Set header `Referer` to reader url to avoid 403 error
|
||||
fun getReader(galleryID: Int) : Reader {
|
||||
val readerUrl = "https://hitomi.la/reader/$galleryID.html"
|
||||
|
||||
val doc = Jsoup.connect(readerUrl).proxy(proxy).get()
|
||||
|
||||
return Reader(Code.HITOMI, doc.title(), getGalleryInfo(galleryID))
|
||||
return Reader(Code.HITOMI, getGalleryInfo(galleryID))
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.list
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.hitomi.GalleryFiles
|
||||
import xyz.quaver.hitomi.GalleryInfo
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.hitomi.protocol
|
||||
@@ -63,12 +64,12 @@ fun renewCookie() : String {
|
||||
@UseExperimental(UnstableDefault::class)
|
||||
fun getReader(galleryID: Int) : Reader {
|
||||
val reader = "https://$hiyobi/reader/$galleryID"
|
||||
val url = "https://$hiyobi/data/json/${galleryID}_list.json"
|
||||
val url = "https://cdn.hiyobi.me/data/json/${galleryID}_list.json"
|
||||
|
||||
val title = Jsoup.connect(reader).proxy(proxy).get().title()
|
||||
|
||||
val galleryInfo = Json.nonstrict.parse(
|
||||
GalleryInfo.serializer().list,
|
||||
val galleryFiles = Json.nonstrict.parse(
|
||||
GalleryFiles.serializer().list,
|
||||
with(URL(url).openConnection(proxy) as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
setRequestProperty("Cookie", cookie)
|
||||
@@ -79,14 +80,14 @@ fun getReader(galleryID: Int) : Reader {
|
||||
}
|
||||
)
|
||||
|
||||
return Reader(Code.HIYOBI, title, galleryInfo)
|
||||
return Reader(Code.HIYOBI, GalleryInfo(title = title, files = galleryFiles))
|
||||
}
|
||||
|
||||
fun createImgList(galleryID: Int, reader: Reader, lowQuality: Boolean = false) =
|
||||
if (lowQuality)
|
||||
reader.galleryInfo.map {
|
||||
reader.galleryInfo.files.map {
|
||||
val name = it.name.replace(Regex("""\.[^/.]+$"""), "")
|
||||
Images("$protocol//$hiyobi/data_r/$galleryID/$name.jpg", galleryID, it.name)
|
||||
}
|
||||
else
|
||||
reader.galleryInfo.map { Images("$protocol//$hiyobi/data/$galleryID/${it.name}", galleryID, it.name) }
|
||||
reader.galleryInfo.files.map { Images("$protocol//$hiyobi/data/$galleryID/${it.name}", galleryID, it.name) }
|
||||
@@ -82,14 +82,14 @@ class UnitTest {
|
||||
|
||||
@Test
|
||||
fun test_hiyobi() {
|
||||
val reader = xyz.quaver.hiyobi.getReader(10000062)
|
||||
val reader = xyz.quaver.hiyobi.getReader(1574736)
|
||||
|
||||
print(reader)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_urlFromUrlFromHash() {
|
||||
val url = urlFromUrlFromHash(1531795, GalleryInfo(
|
||||
val url = urlFromUrlFromHash(1531795, GalleryFiles(
|
||||
212, "719d46a7556be0d0021c5105878507129b5b3308b02cf67f18901b69dbb3b5ef", 1, "00.jpg", 300
|
||||
), "webp")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user