diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/model/BookMetadataPatch.kt b/komga/src/main/kotlin/org/gotson/komga/domain/model/BookMetadataPatch.kt index 112fba0cf..a9660bde4 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/model/BookMetadataPatch.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/model/BookMetadataPatch.kt @@ -10,6 +10,10 @@ data class BookMetadataPatch( val releaseDate: LocalDate?, val authors: List?, - val readList: String?, - val readListNumber: Int? -) + val readLists: List = emptyList() +) { + data class ReadListEntry( + val name: String, + val number: Int? = null + ) +} diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/MetadataLifecycle.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/MetadataLifecycle.kt index 01e464656..7befdf0f1 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/MetadataLifecycle.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/MetadataLifecycle.kt @@ -71,37 +71,32 @@ class MetadataLifecycle( // handle read lists if (provider is ComicInfoProvider && library.importComicInfoReadList) { - patch?.let { bPatch -> - val readList = bPatch.readList - val readListNumber = bPatch.readListNumber + patch?.readLists?.forEach { readList -> - - if (readList != null) { - readListRepository.findByNameOrNull(readList).let { existing -> - if (existing != null) { - if (existing.bookIds.containsValue(book.id)) - logger.debug { "Book is already in existing readlist '${existing.name}'" } - else { - val map = existing.bookIds.toSortedMap() - val key = if (readListNumber != null && existing.bookIds.containsKey(readListNumber)) { - logger.debug { "Existing readlist '${existing.name}' already contains a book at position $readListNumber, adding book '${book.name}' at the end" } - existing.bookIds.lastKey() + 1 - } else { - logger.debug { "Adding book '${book.name}' to existing readlist '${existing.name}'" } - readListNumber ?: existing.bookIds.lastKey() + 1 - } - map[key] = book.id - readListLifecycle.updateReadList( - existing.copy(bookIds = map) - ) + readListRepository.findByNameOrNull(readList.name).let { existing -> + if (existing != null) { + if (existing.bookIds.containsValue(book.id)) + logger.debug { "Book is already in existing readlist '${existing.name}'" } + else { + val map = existing.bookIds.toSortedMap() + val key = if (readList.number != null && existing.bookIds.containsKey(readList.number)) { + logger.debug { "Existing readlist '${existing.name}' already contains a book at position ${readList.number}, adding book '${book.name}' at the end" } + existing.bookIds.lastKey() + 1 + } else { + logger.debug { "Adding book '${book.name}' to existing readlist '${existing.name}'" } + readList.number ?: existing.bookIds.lastKey() + 1 } - } else { - logger.debug { "Adding book '${book.name}' to new readlist '$readList'" } - readListLifecycle.addReadList(ReadList( - name = readList, - bookIds = mapOf((readListNumber ?: 0) to book.id).toSortedMap() - )) + map[key] = book.id + readListLifecycle.updateReadList( + existing.copy(bookIds = map) + ) } + } else { + logger.debug { "Adding book '${book.name}' to new readlist '$readList'" } + readListLifecycle.addReadList(ReadList( + name = readList.name, + bookIds = mapOf((readList.number ?: 0) to book.id).toSortedMap() + )) } } } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProvider.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProvider.kt index b45f579b4..96f30768d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProvider.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProvider.kt @@ -43,6 +43,15 @@ class ComicInfoProvider( comicInfo.coverArtist?.let { authors += it.splitWithRole("cover") } comicInfo.editor?.let { authors += it.splitWithRole("editor") } + val readLists = mutableListOf() + comicInfo.alternateSeries?.let { readLists.add(BookMetadataPatch.ReadListEntry(it, comicInfo.alternateNumber?.toIntOrNull())) } + + comicInfo.storyArc?.let { value -> + val arcs = value.split(",").map { it.trim() } + readLists.addAll(arcs.map { BookMetadataPatch.ReadListEntry(it) }) + } + + return BookMetadataPatch( title = comicInfo.title, summary = comicInfo.summary, @@ -50,8 +59,7 @@ class ComicInfoProvider( numberSort = comicInfo.number?.toFloatOrNull(), releaseDate = releaseDate, authors = authors.ifEmpty { null }, - readList = comicInfo.alternateSeries ?: comicInfo.storyArc, - readListNumber = comicInfo.alternateNumber?.toIntOrNull() ?: comicInfo.storyArcNumber?.toIntOrNull() + readLists = readLists ) } return null diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/dto/ComicInfo.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/dto/ComicInfo.kt index acd889dfc..21cd52ebd 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/dto/ComicInfo.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/dto/ComicInfo.kt @@ -111,9 +111,6 @@ class ComicInfo { @JsonProperty(value = "StoryArc") var storyArc: String? = null - @JsonProperty(value = "StoryArcNumber") - var storyArcNumber: String? = null - @JsonProperty(value = "SeriesGroup") var seriesGroup: String? = null diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/epub/EpubMetadataProvider.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/epub/EpubMetadataProvider.kt index 8eccc5164..ff4b1d002 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/epub/EpubMetadataProvider.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/metadata/epub/EpubMetadataProvider.kt @@ -56,9 +56,7 @@ class EpubMetadataProvider( number = null, numberSort = null, releaseDate = date, - authors = authors, - readList = null, - readListNumber = null + authors = authors ) } return null diff --git a/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProviderTest.kt b/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProviderTest.kt index 2df3c0853..61f306340 100644 --- a/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProviderTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/comicinfo/ComicInfoProviderTest.kt @@ -44,6 +44,7 @@ class ComicInfoProviderTest { month = 2 alternateSeries = "story arc" alternateNumber = "5" + storyArc = "one, two, three" } every { mockMapper.readValue(any(), ComicInfo::class.java) } returns comicInfo @@ -55,9 +56,15 @@ class ComicInfoProviderTest { assertThat(summary).isEqualTo("summary") assertThat(number).isEqualTo("010") assertThat(numberSort).isEqualTo(10F) - assertThat(readList).isEqualTo("story arc") - assertThat(readListNumber).isEqualTo(5) assertThat(releaseDate).isEqualTo(LocalDate.of(2020, 2, 1)) + with(readLists) { + assertThat(this).hasSize(4) + assertThat(this.map { it.name }).containsExactly("story arc", "one", "two", "three") + this.first { it.number != null }.let { + assertThat(it.name).isEqualTo("story arc") + assertThat(it.number).isEqualTo(5) + } + } } }