diff --git a/app/src/main/kotlin/com/hippo/ehviewer/spider/ComicInfo.kt b/app/src/main/kotlin/com/hippo/ehviewer/spider/ComicInfo.kt index 5f0f2bcd4..cf3106e1c 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/spider/ComicInfo.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/spider/ComicInfo.kt @@ -1,6 +1,7 @@ package com.hippo.ehviewer.spider import com.hippo.ehviewer.client.EhUrl +import com.hippo.ehviewer.client.data.GalleryDetail import com.hippo.ehviewer.client.data.GalleryInfo import com.hippo.ehviewer.client.data.TagNamespace import com.hippo.unifile.UniFile @@ -18,6 +19,7 @@ import nl.adaptivity.xmlutil.serialization.XmlElement import nl.adaptivity.xmlutil.xmlStreaming const val COMIC_INFO_FILE = "ComicInfo.xml" +private const val TAG_ORIGINAL = "original" private val xml = XML { recommended { @@ -33,18 +35,35 @@ fun GalleryInfo.getComicInfo(): ComicInfo { val groups = mutableListOf() val characters = mutableListOf() val parodies = mutableListOf() - val tags = mutableListOf() - simpleTags?.forEach { tagString -> - val (namespace, tag) = tagString.split(':', limit = 2) - with(TagNamespace) { - when (val ns = TagNamespace(namespace)) { - Artist, Cosplayer -> artists.add(tag) - Group -> groups.add(tag) - Character -> characters.add(tag) - Parody -> if (tag != "original") parodies.add(tag) - Other -> tags.add(tag) - Female, Male, Mixed -> ns.toPrefix()?.let { tags.add("$it:$tag") } - else -> Unit + val otherTags = mutableListOf() + with(TagNamespace) { + when (this@getComicInfo) { + is GalleryDetail -> tags.forEach { tagList -> + when (val ns = TagNamespace(tagList.groupName)) { + Artist, Cosplayer -> artists.addAll(tagList) + Group -> groups.addAll(tagList) + Character -> characters.addAll(tagList) + Parody -> tagList.forEach { tag -> if (tag != TAG_ORIGINAL) parodies.add(tag) } + Other -> otherTags.addAll(tagList) + Female, Male, Mixed -> ns.toPrefix()?.let { prefix -> + tagList.forEach { tag -> otherTags.add("$prefix:$tag") } + } + + else -> Unit + } + } + + else -> simpleTags?.forEach { tagString -> + val (namespace, tag) = tagString.split(':', limit = 2) + when (val ns = TagNamespace(namespace)) { + Artist, Cosplayer -> artists.add(tag) + Group -> groups.add(tag) + Character -> characters.add(tag) + Parody -> if (tag != TAG_ORIGINAL) parodies.add(tag) + Other -> otherTags.add(tag) + Female, Male, Mixed -> ns.toPrefix()?.let { otherTags.add("$it:$tag") } + else -> Unit + } } } } @@ -53,7 +72,7 @@ fun GalleryInfo.getComicInfo(): ComicInfo { alternateSeries = titleJpn.takeUnless { it.isNullOrBlank() }, writer = groups.takeUnless { it.isEmpty() }?.joinToString(), penciller = artists.takeUnless { it.isEmpty() }?.joinToString(), - genre = tags.takeUnless { it.isEmpty() }?.joinToString(), + genre = otherTags.takeUnless { it.isEmpty() }?.joinToString(), web = EhUrl.getGalleryDetailUrl(gid, token), pageCount = pages, languageISO = simpleLanguage?.lowercase(), diff --git a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderDen.kt b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderDen.kt index 49eeecd58..46e54042e 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderDen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderDen.kt @@ -25,6 +25,7 @@ import com.hippo.ehviewer.EhDB import com.hippo.ehviewer.Settings import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.EhUtils.getSuitableTitle +import com.hippo.ehviewer.client.data.GalleryDetail import com.hippo.ehviewer.client.data.GalleryInfo import com.hippo.ehviewer.client.ehRequest import com.hippo.ehviewer.client.getImageKey @@ -319,7 +320,7 @@ class SpiderDen(val info: GalleryInfo) { downloadDir?.run { createFile(COMIC_INFO_FILE)?.also { runCatching { - if (fetchMetadata) { + if (info !is GalleryDetail && fetchMetadata) { withNonCancellableContext { EhEngine.fillGalleryListByApi(listOf(info)) }