Fixed bug caused by updated hitomi server structure
Version 4.0
This commit is contained in:
26
libpupil/src/main/java/xyz/quaver/Utils.kt
Normal file
26
libpupil/src/main/java/xyz/quaver/Utils.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2019 tom5079
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xyz.quaver
|
||||
|
||||
fun availableInHiyobi(galleryID: Int) : Boolean {
|
||||
return try {
|
||||
xyz.quaver.hiyobi.getReader(galleryID)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,25 @@
|
||||
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import kotlinx.serialization.list
|
||||
import java.net.URL
|
||||
|
||||
const val protocol = "https:"
|
||||
|
||||
fun getGalleryInfo(galleryID: Int): List<GalleryInfo> {
|
||||
return Json(JsonConfiguration.Stable).parse(
|
||||
GalleryInfo.serializer().list,
|
||||
Regex("""\[.+]""").find(
|
||||
URL("$protocol//$domain/galleries/$galleryID.js").readText()
|
||||
)?.value ?: "[]"
|
||||
)
|
||||
}
|
||||
|
||||
//common.js
|
||||
var adapose = false
|
||||
const val numberOfFrontends = 2
|
||||
const val numberOfFrontends = 3
|
||||
const val domain = "ltn.hitomi.la"
|
||||
const val galleryblockdir = "galleryblock"
|
||||
const val nozomiextension = ".nozomi"
|
||||
@@ -37,20 +51,22 @@ fun subdomainFromGalleryID(g: Int) : String {
|
||||
fun subdomainFromURL(url: String, base: String? = null) : String {
|
||||
var retval = "a"
|
||||
|
||||
if (base != null)
|
||||
if (!base.isNullOrEmpty())
|
||||
retval = base
|
||||
|
||||
val r = Regex("""/\d*(\d)/""")
|
||||
val m = r.find(url)
|
||||
val r = Regex("""/galleries/\d*(\d)/""")
|
||||
var m = r.find(url)
|
||||
var b = 10
|
||||
|
||||
m ?: return retval
|
||||
if (m == null) {
|
||||
b = 16
|
||||
val r2 = Regex("""/images/[0-9a-f]/([0-9a-f]{2})/""")
|
||||
m = r2.find(url)
|
||||
if (m == null)
|
||||
return retval
|
||||
}
|
||||
|
||||
var g = m.groups[1]!!.value.toIntOrNull()
|
||||
|
||||
g ?: return retval
|
||||
|
||||
if (g == 1)
|
||||
g = 0
|
||||
val g = m.groupValues[1].toIntOrNull(b) ?: return retval
|
||||
|
||||
retval = subdomainFromGalleryID(g) + retval
|
||||
|
||||
@@ -58,5 +74,22 @@ fun subdomainFromURL(url: String, base: String? = null) : String {
|
||||
}
|
||||
|
||||
fun urlFromURL(url: String, base: String? = null) : String {
|
||||
return url.replace(Regex("//..?\\.hitomi\\.la/"), "//${subdomainFromURL(url, base)}.hitomi.la/")
|
||||
}
|
||||
return url.replace(Regex("""//..?\.hitomi\.la/"""), "//${subdomainFromURL(url, base)}.hitomi.la/")
|
||||
}
|
||||
|
||||
fun fullPathFromHash(hash: String?) : String? {
|
||||
return when {
|
||||
hash?.length ?: 0 < 3 -> hash
|
||||
else -> hash!!.replace(Regex("^.*(..)(.)$"), "$2/$1/$hash")
|
||||
}
|
||||
}
|
||||
|
||||
fun urlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean) : String {
|
||||
return when {
|
||||
oldMethod or image.hash.isNullOrEmpty() -> "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}"
|
||||
else -> "$protocol//a.hitomi.la/images/${fullPathFromHash(image.hash)}.${image.name.split('.').last()}"
|
||||
}
|
||||
}
|
||||
|
||||
fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean = false) =
|
||||
urlFromURL(urlFromHash(galleryID, image, oldMethod))
|
||||
@@ -17,7 +17,6 @@
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import java.net.URL
|
||||
import java.net.URLDecoder
|
||||
|
||||
data class Gallery(
|
||||
@@ -35,7 +34,8 @@ data class Gallery(
|
||||
val thumbnails: List<String>
|
||||
)
|
||||
fun getGallery(galleryID: Int) : Gallery {
|
||||
val url = "https://hitomi.la/galleries/$galleryID.html"
|
||||
val url = Jsoup.connect("https://hitomi.la/galleries/$galleryID.html").get()
|
||||
.select("a").attr("href")
|
||||
|
||||
val doc = Jsoup.connect(url).get()
|
||||
|
||||
@@ -46,7 +46,7 @@ fun getGallery(galleryID: Int) : Gallery {
|
||||
}.toList()
|
||||
|
||||
val langList = doc.select("#lang-list a").map {
|
||||
Pair(it.text(), it.attr("href").replace(".html", ""))
|
||||
Pair(it.text(), "$protocol//hitomi.la${it.attr("href")}")
|
||||
}
|
||||
|
||||
val cover = protocol + doc.selectFirst(".cover img").attr("src")
|
||||
@@ -68,11 +68,9 @@ fun getGallery(galleryID: Int) : Gallery {
|
||||
href.slice(5 until href.indexOf('-'))
|
||||
}
|
||||
|
||||
val thumbnails = Regex("'(//tn.hitomi.la/smalltn/\\d+/.+)',")
|
||||
.findAll(doc.select("script").last().html())
|
||||
.map {
|
||||
protocol + it.groups[1]!!.value
|
||||
}.toList()
|
||||
val thumbnails = getGalleryInfo(galleryID).map {
|
||||
"$protocol//tn.hitomi.la/smalltn/$galleryID/${it.name}.jpg"
|
||||
}
|
||||
|
||||
return Gallery(related, langList, cover, title, artists, groups, type, language, series, characters, tags, thumbnails)
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.jsoup.Jsoup
|
||||
import sun.rmi.runtime.Log
|
||||
import java.net.URL
|
||||
import java.net.URLDecoder
|
||||
import java.nio.ByteBuffer
|
||||
@@ -69,6 +68,7 @@ fun fetchNozomi(area: String? = null, tag: String = "index", language: String =
|
||||
@Serializable
|
||||
data class GalleryBlock(
|
||||
val id: Int,
|
||||
val galleryUrl: String,
|
||||
val thumbnails: List<String>,
|
||||
val title: String,
|
||||
val artists: List<String>,
|
||||
@@ -83,6 +83,8 @@ fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
|
||||
try {
|
||||
val doc = Jsoup.connect(url).get()
|
||||
|
||||
val galleryUrl = doc.selectFirst(".lillie").attr("href")
|
||||
|
||||
val thumbnails = doc.select("img").map { protocol + it.attr("data-src") }
|
||||
|
||||
val title = doc.selectFirst("h1.lillie > a").text()
|
||||
@@ -100,7 +102,7 @@ fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
|
||||
href.slice(5 until href.indexOf("-all"))
|
||||
}
|
||||
|
||||
return GalleryBlock(galleryID, thumbnails, title, artists, series, type, language, relatedTags)
|
||||
return GalleryBlock(galleryID, galleryUrl, thumbnails, title, artists, series, type, language, relatedTags)
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -17,72 +17,28 @@
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import kotlinx.serialization.list
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.hiyobi.HiyobiReader
|
||||
import java.net.URL
|
||||
|
||||
fun getReferer(galleryID: Int) = "https://hitomi.la/reader/$galleryID.html"
|
||||
fun webpUrlFromUrl(url: String) = url.replace("/galleries/", "/webp/") + ".webp"
|
||||
|
||||
fun webpReaderFromReader(reader: Reader) : Reader {
|
||||
if (reader is HiyobiReader)
|
||||
return reader
|
||||
|
||||
return Reader(reader.title, reader.readerItems.map {
|
||||
ReaderItem(
|
||||
if (it.galleryInfo?.haswebp == 1) webpUrlFromUrl(it.url) else it.url,
|
||||
it.galleryInfo
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class GalleryInfo(
|
||||
val width: Int,
|
||||
val hash: String?,
|
||||
val haswebp: Int,
|
||||
val name: String,
|
||||
val height: Int
|
||||
)
|
||||
@Serializable
|
||||
data class ReaderItem(
|
||||
val url: String,
|
||||
val galleryInfo: GalleryInfo?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
open class Reader(val title: String, val readerItems: List<ReaderItem>)
|
||||
open class Reader(val title: String, val galleryInfo: List<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 galleryInfoUrl = "https://ltn.hitomi.la/galleries/$galleryID.js"
|
||||
|
||||
val doc = Jsoup.connect(readerUrl).get()
|
||||
|
||||
val title = doc.title()
|
||||
|
||||
val images = doc.select(".img-url").map {
|
||||
protocol + urlFromURL(it.text())
|
||||
}
|
||||
|
||||
val galleryInfo = ArrayList<GalleryInfo?>()
|
||||
|
||||
galleryInfo.addAll(
|
||||
Json(JsonConfiguration.Stable).parse(
|
||||
GalleryInfo.serializer().list,
|
||||
Regex("""\[.+]""").find(
|
||||
URL(galleryInfoUrl).readText()
|
||||
)?.value ?: "[]"
|
||||
)
|
||||
)
|
||||
|
||||
if (images.size > galleryInfo.size)
|
||||
galleryInfo.addAll(arrayOfNulls(images.size - galleryInfo.size))
|
||||
|
||||
return Reader(title, (images zip galleryInfo).map {
|
||||
ReaderItem(it.first, it.second)
|
||||
})
|
||||
return Reader(doc.title(), getGalleryInfo(galleryID))
|
||||
}
|
||||
@@ -18,18 +18,17 @@ package xyz.quaver.hiyobi
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import kotlinx.serialization.json.content
|
||||
import kotlinx.serialization.list
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.hitomi.GalleryInfo
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.hitomi.ReaderItem
|
||||
import xyz.quaver.hitomi.protocol
|
||||
import java.net.URL
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
const val hiyobi = "xn--9w3b15m8vo.asia"
|
||||
const val user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
|
||||
|
||||
class HiyobiReader(title: String, readerItems: List<ReaderItem>) : Reader(title, readerItems)
|
||||
|
||||
var cookie: String = ""
|
||||
get() {
|
||||
if (field.isEmpty())
|
||||
@@ -38,6 +37,12 @@ var cookie: String = ""
|
||||
return field
|
||||
}
|
||||
|
||||
data class Images(
|
||||
val path: String,
|
||||
val no: Int,
|
||||
val name: String
|
||||
)
|
||||
|
||||
fun renewCookie() : String {
|
||||
val url = "https://$hiyobi/"
|
||||
|
||||
@@ -59,7 +64,8 @@ fun getReader(galleryID: Int) : Reader {
|
||||
|
||||
val title = Jsoup.connect(reader).get().title()
|
||||
|
||||
val json = Json(JsonConfiguration.Stable).parseJson(
|
||||
val galleryInfo = Json(JsonConfiguration.Stable).parse(
|
||||
GalleryInfo.serializer().list,
|
||||
with(URL(url).openConnection() as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
setRequestProperty("Cookie", cookie)
|
||||
@@ -70,8 +76,8 @@ fun getReader(galleryID: Int) : Reader {
|
||||
}
|
||||
)
|
||||
|
||||
return Reader(title, json.jsonArray.map {
|
||||
val name = it.jsonObject["name"]!!.content
|
||||
ReaderItem("https://$hiyobi/data/$galleryID/$name", null)
|
||||
})
|
||||
}
|
||||
return Reader(title, galleryInfo)
|
||||
}
|
||||
|
||||
fun createImgList(galleryID: Int, reader: Reader) =
|
||||
reader.galleryInfo.map { Images("$protocol//$hiyobi/data/$galleryID/${it.name}", galleryID, it.name) }
|
||||
@@ -18,12 +18,16 @@
|
||||
|
||||
package xyz.quaver.hitomi
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class UnitTest {
|
||||
@Test
|
||||
fun test() {
|
||||
|
||||
assertEquals(
|
||||
"6/2d/c26014fc6153ef717932d85f4d26c75195560fb2ce1da60b431ef376501642d6",
|
||||
fullPathFromHash("c26014fc6153ef717932d85f4d26c75195560fb2ce1da60b431ef376501642d6")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +67,7 @@ class UnitTest {
|
||||
|
||||
@Test
|
||||
fun test_getGallery() {
|
||||
val gallery = getGallery(1405267)
|
||||
val gallery = getGallery(1510566)
|
||||
|
||||
print(gallery)
|
||||
}
|
||||
@@ -77,6 +81,15 @@ class UnitTest {
|
||||
|
||||
@Test
|
||||
fun test_hiyobi() {
|
||||
xyz.quaver.hiyobi.getReader(1510567)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_urlFromUrlFromHash() {
|
||||
val url = urlFromUrlFromHash(1510702, GalleryInfo(
|
||||
210, "56e9e1b8bb72194777ed93fee11b06070b905039dd11348b070bcf1793aaed7b", 1, "6.jpg", 300
|
||||
))
|
||||
|
||||
print(url)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user