Improved loading speed of the cached gallery

This commit is contained in:
tom5079
2019-05-16 16:25:28 +09:00
parent 5e61912f75
commit 23bf93e960
15 changed files with 162 additions and 76 deletions

View File

@@ -16,7 +16,12 @@ data class GalleryInfo(
val name: String,
val height: Int
)
typealias Reader = List<Pair<URL, GalleryInfo?>>
@Serializable
data class ReaderItem(
val url: String,
val galleryInfo: GalleryInfo?
)
typealias Reader = List<ReaderItem>
//Set header `Referer` to reader url to avoid 403 error
fun getReader(galleryID: Int) : Reader {
val readerUrl = "https://hitomi.la/reader/$galleryID.html"
@@ -25,7 +30,7 @@ fun getReader(galleryID: Int) : Reader {
val doc = Jsoup.connect(readerUrl).get()
val images = doc.select(".img-url").map {
URL(protocol + urlFromURL(it.text()))
protocol + urlFromURL(it.text())
}
val galleryInfo = ArrayList<GalleryInfo?>()
@@ -42,5 +47,7 @@ fun getReader(galleryID: Int) : Reader {
if (images.size > galleryInfo.size)
galleryInfo.addAll(arrayOfNulls(images.size - galleryInfo.size))
return images zip galleryInfo
return (images zip galleryInfo).map {
ReaderItem(it.first, it.second)
}
}

View File

@@ -4,6 +4,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.content
import xyz.quaver.hitomi.Reader
import xyz.quaver.hitomi.ReaderItem
import java.net.URL
import javax.net.ssl.HttpsURLConnection
@@ -42,6 +43,6 @@ fun getReader(galleryId: Int) : Reader {
return json.jsonArray.map {
val name = it.jsonObject["name"]!!.content
Pair(URL("https://$hiyobi/data/$galleryId/$name"), null)
ReaderItem("https://$hiyobi/data/$galleryId/$name", null)
}
}