This commit is contained in:
tom5079
2020-12-27 13:39:57 +09:00
parent 3051d800bd
commit 8703fde9b1
9 changed files with 143 additions and 36 deletions

View File

@@ -40,7 +40,6 @@ data class ItemInfo(
val title: String,
val thumbnail: String,
val artists: String,
val tags: List<String>,
val extra: Map<ExtraType, Deferred<String?>> = emptyMap()
) {
enum class ExtraType {
@@ -48,8 +47,11 @@ data class ItemInfo(
CHARACTER,
SERIES,
TYPE,
TAGS,
LANGUAGE,
PAGECOUNT
PAGECOUNT,
PREVIEW,
RELATED_ITEM,
}
@Serializable
@@ -60,7 +62,6 @@ data class ItemInfo(
val title: String,
val thumbnail: String,
val artists: String,
val tags: List<String>,
val extra: Map<ExtraType, String?> = emptyMap()
)
@@ -74,7 +75,6 @@ data class ItemInfo(
value.title,
value.thumbnail,
value.artists,
value.tags,
value.extra.mapValues { runBlocking { it.value.await() } }
)
encoder.encodeSerializableValue(ItemInfoSurrogate.serializer(), surrogate)
@@ -88,7 +88,6 @@ data class ItemInfo(
surrogate.title,
surrogate.thumbnail,
surrogate.artists,
surrogate.tags,
surrogate.extra.mapValues { CoroutineScope(Dispatchers.Unconfined).async { it.value } }
)
}
@@ -119,7 +118,7 @@ abstract class Source<Query_SortMode: Enum<Query_SortMode>, Suggestion: SearchSu
abstract suspend fun search(query: String, range: IntRange, sortMode: Enum<*>) : Pair<Channel<ItemInfo>, Int>
abstract suspend fun suggestion(query: String) : List<Suggestion>
abstract suspend fun images(id: String) : List<String>
/* abstract suspend */ fun info(id: String)/* : ItemInfo */{}
abstract suspend fun info(id: String) : ItemInfo
open fun getHeadersForImage(id: String, url: String): Map<String, String> {
return emptyMap()

View File

@@ -18,7 +18,6 @@
package xyz.quaver.pupil.sources
import android.util.Log
import android.view.LayoutInflater
import android.widget.TextView
import kotlinx.coroutines.*
@@ -93,6 +92,12 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
return Pair(channel, cache.size)
}
override suspend fun suggestion(query: String) : List<TagSuggestion> {
return getSuggestionsForQuery(query.takeLastWhile { !it.isWhitespace() }).map {
TagSuggestion(it)
}
}
override suspend fun images(id: String): List<String> {
val galleryID = id.toInt()
@@ -103,18 +108,35 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
}
}
override suspend fun info(id: String): ItemInfo = coroutineScope {
getGallery(id.toInt()).let {
ItemInfo(
name,
id,
it.title,
it.cover,
it.artists.joinToString { it.wordCapitalize() },
mapOf(
ExtraType.TYPE to async { it.type.wordCapitalize() },
ExtraType.GROUP to async { it.groups.joinToString { it.wordCapitalize() } },
ExtraType.LANGUAGE to async { languageMap[it.language] ?: it.language },
ExtraType.SERIES to async { it.series.joinToString { it.wordCapitalize() } },
ExtraType.CHARACTER to async { it.characters.joinToString { it.wordCapitalize() } },
ExtraType.TAGS to async { it.tags.joinToString() },
ExtraType.PREVIEW to async { it.thumbnails.joinToString() },
ExtraType.RELATED_ITEM to async { it.related.joinToString() },
ExtraType.PAGECOUNT to async { it.thumbnails.size.toString() },
)
)
}
}
override fun getHeadersForImage(id: String, url: String): Map<String, String> {
return mapOf(
"Referer" to getReferer(id.toInt())
)
}
override suspend fun suggestion(query: String) : List<Hitomi.TagSuggestion> {
return getSuggestionsForQuery(query.takeLastWhile { !it.isWhitespace() }).map {
TagSuggestion(it)
}
}
override fun onSuggestionBind(binding: SearchSuggestionItemBinding, item: TagSuggestion) {
binding.leftIcon.setImageResource(
when(item.n) {
@@ -195,7 +217,6 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
galleryBlock.title,
galleryBlock.thumbnails.first(),
galleryBlock.artists.joinToString { it.wordCapitalize() },
galleryBlock.relatedTags,
mapOf(
ExtraType.GROUP to CoroutineScope(Dispatchers.IO).async { kotlin.runCatching {
getGallery(galleryBlock.id).groups.joinToString { it.wordCapitalize() }
@@ -205,7 +226,8 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
ExtraType.LANGUAGE to CoroutineScope(Dispatchers.Unconfined).async { languageMap[galleryBlock.language] ?: galleryBlock.language },
ExtraType.PAGECOUNT to CoroutineScope(Dispatchers.IO).async { kotlin.runCatching {
getGalleryInfo(galleryBlock.id).files.size.toString()
}.getOrNull() }
}.getOrNull() },
ExtraType.TAGS to CoroutineScope(Dispatchers.Unconfined).async { galleryBlock.relatedTags.joinToString() }
)
)
}

View File

@@ -78,6 +78,10 @@ class Hiyobi : Source<DefaultSortMode, DefaultSearchSuggestion>() {
}
}
override suspend fun info(id: String): ItemInfo {
return transform(name, getGalleryBlock(id))
}
override fun onSuggestionBind(binding: SearchSuggestionItemBinding, item: DefaultSearchSuggestion) {
val split = item.body.split(':', limit = 2)
@@ -121,13 +125,13 @@ class Hiyobi : Source<DefaultSortMode, DefaultSearchSuggestion>() {
galleryBlock.title,
"https://cdn.$hiyobi/tn/${galleryBlock.id}.jpg",
galleryBlock.artists.joinToString { it.value.wordCapitalize() },
galleryBlock.tags.map { it.value },
mapOf(
ItemInfo.ExtraType.CHARACTER to async { galleryBlock.characters.joinToString { it.value.wordCapitalize() } },
ItemInfo.ExtraType.SERIES to async { galleryBlock.parodys.joinToString { it.value.wordCapitalize() } },
ItemInfo.ExtraType.TYPE to async { galleryBlock.type.name.replace('_', ' ').wordCapitalize() },
ItemInfo.ExtraType.PAGECOUNT to async { getGalleryInfo(galleryBlock.id).files.size.toString() },
ItemInfo.ExtraType.GROUP to async { galleryBlock.groups.joinToString { it.value.wordCapitalize() } }
ItemInfo.ExtraType.GROUP to async { galleryBlock.groups.joinToString { it.value.wordCapitalize() } },
ItemInfo.ExtraType.TAGS to async { galleryBlock.tags.joinToString() { it.value } }
)
)
}