Add hiyobi image booster

This commit is contained in:
tom5079
2019-05-13 12:56:39 +09:00
parent cbb52f3dc9
commit 2bf0f86510
9 changed files with 89 additions and 28 deletions

View File

@@ -1,11 +1,9 @@
package xyz.quaver.hitomi
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.list
import kotlinx.serialization.parseList
import org.jsoup.Jsoup
import java.net.URL
@@ -18,10 +16,7 @@ data class GalleryInfo(
val name: String,
val height: Int
)
data class Reader(
val title: String,
val images: List<Pair<URL, GalleryInfo?>>
)
typealias Reader = List<Pair<URL, GalleryInfo?>>
//Set header `Referer` to reader url to avoid 403 error
fun getReader(galleryID: Int) : Reader {
val readerUrl = "https://hitomi.la/reader/$galleryID.html"
@@ -29,8 +24,6 @@ fun getReader(galleryID: Int) : Reader {
val doc = Jsoup.connect(readerUrl).get()
val title = doc.selectFirst("title").text()
val images = doc.select(".img-url").map {
URL(protocol + urlFromURL(it.text()))
}
@@ -49,5 +42,5 @@ fun getReader(galleryID: Int) : Reader {
if (images.size > galleryInfo.size)
galleryInfo.addAll(arrayOfNulls(images.size - galleryInfo.size))
return Reader(title, images zip galleryInfo)
return images zip galleryInfo
}

View File

@@ -0,0 +1,47 @@
package xyz.quaver.hiyobi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.content
import xyz.quaver.hitomi.Reader
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"
var cookie: String = ""
fun renewCookie() : String {
val url = "https://$hiyobi/"
with(URL(url).openConnection() as HttpsURLConnection) {
setRequestProperty("User-Agent", user_agent)
connectTimeout = 2000
connect()
return headerFields["Set-Cookie"]!![0]
}
}
fun getReader(galleryId: Int) : Reader {
val url = "https://$hiyobi/data/json/${galleryId}_list.json"
if (cookie.isEmpty())
cookie = renewCookie()
val json = Json(JsonConfiguration.Stable).parseJson(
with(URL(url).openConnection() as HttpsURLConnection) {
setRequestProperty("User-Agent", user_agent)
setRequestProperty("Cookie", cookie)
connectTimeout = 2000
connect()
inputStream.bufferedReader().use { it.readText() }
}
)
return json.jsonArray.map {
val name = it.jsonObject["name"]!!.content
Pair(URL("https://$hiyobi/data/$galleryId/$name"), null)
}
}

View File

@@ -61,4 +61,9 @@ class UnitTest {
print(reader)
}
@Test
fun test_hiyobi() {
xyz.quaver.hiyobi.getReader(1414061)
}
}