Added support for gallery unregistered in hitomi

This commit is contained in:
Pupil
2020-02-08 20:36:08 +09:00
parent ecaecc1b91
commit a0a989c785
11 changed files with 112 additions and 26 deletions

View File

@@ -108,13 +108,16 @@ class Cache(context: Context) : ContextWrapper(context) {
val metadata = Cache(this).getCachedMetadata(galleryID)
val galleryBlock = if (metadata?.galleryBlock == null)
withContext(Dispatchers.IO) {
try {
xyz.quaver.hitomi.getGalleryBlock(galleryID)
} catch (e: Exception) {
null
listOf(
{ xyz.quaver.hitomi.getGalleryBlock(galleryID) },
{ xyz.quaver.hiyobi.getGalleryBlock(galleryID) }
).map {
CoroutineScope(Dispatchers.IO).async {
kotlin.runCatching {
it.invoke()
}.getOrNull()
}
}
}.awaitAll().filterNotNull()
else
metadata.galleryBlock
@@ -123,7 +126,11 @@ class Cache(context: Context) : ContextWrapper(context) {
Metadata(Cache(this).getCachedMetadata(galleryID), galleryBlock = galleryBlock)
)
return galleryBlock
val mirrors = preference.getString("mirrors", "")!!.split('>')
return galleryBlock.firstOrNull {
mirrors.contains(it.code.name)
} ?: galleryBlock.firstOrNull()
}
fun getReaderOrNull(galleryID: Int): Reader? {

View File

@@ -33,6 +33,7 @@ import io.fabric.sdk.android.Fabric
import kotlinx.coroutines.*
import okhttp3.*
import okio.*
import xyz.quaver.Code
import xyz.quaver.hitomi.Reader
import xyz.quaver.hitomi.getReferer
import xyz.quaver.hitomi.urlFromUrlFromHash
@@ -237,7 +238,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
val request = Request.Builder().apply {
when (reader.code) {
Reader.Code.HITOMI -> {
Code.HITOMI -> {
url(
urlFromUrlFromHash(
galleryID,
@@ -247,7 +248,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
)
addHeader("Referer", getReferer(galleryID))
}
Reader.Code.HIYOBI -> {
Code.HIYOBI -> {
url(createImgList(galleryID, reader, lowQuality)[index].path)
addHeader("User-Agent", user_agent)
addHeader("Cookie", cookie)

View File

@@ -25,14 +25,14 @@ import xyz.quaver.hitomi.Reader
@Serializable
data class Metadata(
val thumbnail: String? = null,
val galleryBlock: GalleryBlock? = null,
val galleryBlock: List<GalleryBlock>? = null,
val readers: List<Reader>? = null,
val isDownloading: Boolean? = null
) {
constructor(
metadata: Metadata?,
thumbnail: String? = null,
galleryBlock: GalleryBlock? = null,
galleryBlock: List<GalleryBlock>? = null,
readers: List<Reader>? = null,
isDownloading: Boolean? = null
) : this(