Added support for gallery unregistered in hitomi
This commit is contained in:
@@ -39,7 +39,7 @@ import kotlinx.android.synthetic.main.activity_reader.*
|
||||
import kotlinx.android.synthetic.main.activity_reader.view.*
|
||||
import kotlinx.android.synthetic.main.dialog_numberpicker.view.*
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.adapters.ReaderAdapter
|
||||
@@ -264,8 +264,8 @@ class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
menu?.findItem(R.id.reader_type)?.icon = ContextCompat.getDrawable(this@ReaderActivity,
|
||||
when (reader.code) {
|
||||
Reader.Code.HITOMI -> R.drawable.hitomi
|
||||
Reader.Code.HIYOBI -> R.drawable.ic_hiyobi
|
||||
Code.HITOMI -> R.drawable.hitomi
|
||||
Code.HIYOBI -> R.drawable.ic_hiyobi
|
||||
else -> android.R.color.transparent
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import kotlinx.coroutines.launch
|
||||
import xyz.quaver.hitomi.Gallery
|
||||
import xyz.quaver.hitomi.GalleryBlock
|
||||
import xyz.quaver.hitomi.getGallery
|
||||
import xyz.quaver.hitomi.getGalleryBlock
|
||||
import xyz.quaver.pupil.BuildConfig
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
@@ -51,6 +50,7 @@ import xyz.quaver.pupil.adapters.ThumbnailAdapter
|
||||
import xyz.quaver.pupil.types.Tag
|
||||
import xyz.quaver.pupil.ui.ReaderActivity
|
||||
import xyz.quaver.pupil.util.ItemClickSupport
|
||||
import xyz.quaver.pupil.util.download.Cache
|
||||
import xyz.quaver.pupil.util.wordCapitalize
|
||||
|
||||
class GalleryDialog(context: Context, private val galleryID: Int) : Dialog(context) {
|
||||
@@ -237,7 +237,7 @@ class GalleryDialog(context: Context, private val galleryID: Int) : Dialog(conte
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
gallery.related.forEachIndexed { i, galleryID ->
|
||||
async(Dispatchers.IO) {
|
||||
getGalleryBlock(galleryID)
|
||||
Cache(context).getGalleryBlock(galleryID)
|
||||
}.let {
|
||||
val galleryBlock = it.await() ?: return@let
|
||||
|
||||
|
||||
@@ -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? {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user