Added Offline mode

This commit is contained in:
tom5079
2019-05-16 18:15:53 +09:00
parent 23bf93e960
commit d090a59800
14 changed files with 201 additions and 108 deletions

View File

@@ -1,5 +1,6 @@
package xyz.quaver.hitomi
import kotlinx.serialization.Serializable
import org.jsoup.Jsoup
import java.net.URL
import java.net.URLDecoder
@@ -39,13 +40,14 @@ fun fetchNozomi(area: String? = null, tag: String = "index", language: String =
return nozomi
}
} catch (e: Exception) {
return listOf()
return emptyList()
}
}
@Serializable
data class GalleryBlock(
val id: Int,
val thumbnails: List<URL>,
val thumbnails: List<String>,
val title: String,
val artists: List<String>,
val series: List<String>,
@@ -53,27 +55,31 @@ data class GalleryBlock(
val language: String,
val relatedTags: List<String>
)
fun getGalleryBlock(galleryID: Int) : GalleryBlock {
fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
val url = "$protocol//$domain/$galleryblockdir/$galleryID$extension"
val doc = Jsoup.connect(url).get()
try {
val doc = Jsoup.connect(url).get()
val thumbnails = doc.select("img").map { URL(protocol + it.attr("data-src")) }
val thumbnails = doc.select("img").map { protocol + it.attr("data-src") }
val title = doc.selectFirst("h1.lillie > a").text()
val artists = doc.select("div.artist-list a").map{ it.text() }
val series = doc.select("a[href~=^/series/]").map { it.text() }
val type = doc.selectFirst("a[href~=^/type/]").text()
val title = doc.selectFirst("h1.lillie > a").text()
val artists = doc.select("div.artist-list a").map{ it.text() }
val series = doc.select("a[href~=^/series/]").map { it.text() }
val type = doc.selectFirst("a[href~=^/type/]").text()
val language = {
val href = doc.select("a[href~=^/index-.+-1.html]").attr("href")
href.slice(7 until href.indexOf("-1"))
}.invoke()
val language = {
val href = doc.select("a[href~=^/index-.+-1.html]").attr("href")
href.slice(7 until href.indexOf("-1"))
}.invoke()
val relatedTags = doc.select(".relatedtags a").map {
val href = URLDecoder.decode(it.attr("href"), "UTF-8")
href.slice(5 until href.indexOf('-'))
val relatedTags = doc.select(".relatedtags a").map {
val href = URLDecoder.decode(it.attr("href"), "UTF-8")
href.slice(5 until href.indexOf('-'))
}
return GalleryBlock(galleryID, thumbnails, title, artists, series, type, language, relatedTags)
} catch (e: Exception) {
return null
}
return GalleryBlock(galleryID, thumbnails, title, artists, series, type, language, relatedTags)
}