feat: import ComicInfo Tags element

closes #541
This commit is contained in:
Gauthier Roebroeck 2022-01-19 14:43:14 +08:00
parent cc6f4228ba
commit d3daaf1f9c
8 changed files with 34 additions and 12 deletions

View file

@ -11,6 +11,7 @@ data class BookMetadataPatch(
val authors: List<Author>? = null,
val isbn: String? = null,
val links: List<WebLink>? = null,
val tags: Set<String>? = null,
val readLists: List<ReadListEntry> = emptyList(),
) {

View file

@ -24,6 +24,7 @@ class MetadataApplier {
authors = getIfNotLocked(authors, patch.authors, authorsLock),
isbn = getIfNotLocked(isbn, patch.isbn, isbnLock),
links = getIfNotLocked(links, patch.links, linksLock),
tags = getIfNotLocked(tags, patch.tags, tagsLock),
)
}

View file

@ -94,6 +94,8 @@ class ComicInfoProvider(
}
}
val tags = comicInfo.tags?.split(',')?.mapNotNull { it.trim().lowercase().ifBlank { null } }
return BookMetadataPatch(
title = comicInfo.title?.ifBlank { null },
summary = comicInfo.summary?.ifBlank { null },
@ -103,6 +105,7 @@ class ComicInfoProvider(
authors = authors.ifEmpty { null },
readLists = readLists,
links = link,
tags = if (!tags.isNullOrEmpty()) tags.toSet() else null,
)
}
return null

View file

@ -79,6 +79,9 @@ class ComicInfo {
@JsonProperty(value = "Genre")
var genre: String? = null
@JsonProperty(value = "Tags")
var tags: String? = null
@JsonProperty(value = "Web")
var web: String? = null

View file

@ -45,6 +45,7 @@ class MetadataApplierTest {
authors = listOf(Author("Marcel", "writer")),
isbn = "9782811632397",
links = listOf(WebLink("Comixology", URI("https://www.comixology.com/Sandman/digital-comic/727888"))),
tags = setOf("tag1", "tag2"),
)
val patched = metadataApplier.apply(patch, metadata)
@ -58,6 +59,7 @@ class MetadataApplierTest {
assertThat(patched.tags).isEmpty()
assertThat(patched.isbn).isEqualTo("")
assertThat(patched.links).isEmpty()
assertThat(patched.tags).isEmpty()
}
@Test
@ -77,6 +79,7 @@ class MetadataApplierTest {
authors = listOf(Author("Marcel", "writer")),
isbn = "9782811632397",
links = listOf(WebLink("Comixology", URI("https://www.comixology.com/Sandman/digital-comic/727888"))),
tags = setOf("tag1", "tag2"),
)
val patched = metadataApplier.apply(patch, metadata)
@ -91,13 +94,15 @@ class MetadataApplierTest {
Author("Marcel", "writer"),
)
assertThat(patched.releaseDate).isEqualTo(patch.releaseDate)
assertThat(patched.tags).isEmpty()
assertThat(patched.isbn).isEqualTo(patch.isbn)
assertThat(patched.links)
.hasSize(1)
.containsExactlyInAnyOrder(
WebLink("Comixology", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
)
assertThat(patched.tags)
.hasSize(2)
.containsExactlyInAnyOrder("tag1", "tag2")
}
}

View file

@ -54,6 +54,7 @@ class ComicInfoProviderTest {
alternateNumber = "5"
storyArc = "one, two, three"
web = "https://www.comixology.com/Sandman/digital-comic/727888"
tags = "dark, Occult"
}
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
@ -67,18 +68,24 @@ class ComicInfoProviderTest {
assertThat(numberSort).isEqualTo(10F)
assertThat(releaseDate).isEqualTo(LocalDate.of(2020, 2, 1))
assertThat(readLists).hasSize(4)
assertThat(readLists).containsExactlyInAnyOrder(
BookMetadataPatch.ReadListEntry("story arc", 5),
BookMetadataPatch.ReadListEntry("one"),
BookMetadataPatch.ReadListEntry("two"),
BookMetadataPatch.ReadListEntry("three"),
)
assertThat(readLists)
.hasSize(4)
.containsExactlyInAnyOrder(
BookMetadataPatch.ReadListEntry("story arc", 5),
BookMetadataPatch.ReadListEntry("one"),
BookMetadataPatch.ReadListEntry("two"),
BookMetadataPatch.ReadListEntry("three"),
)
assertThat(links).hasSize(1)
assertThat(links).containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
)
assertThat(links)
.hasSize(1)
.containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
)
assertThat(tags)
.hasSize(2)
.containsExactlyInAnyOrder("dark", "occult")
}
}

View file

@ -25,6 +25,7 @@ class ComicInfoTest {
assertThat(imprint).isEqualTo("Vertigo")
assertThat(count).isEqualTo(10)
assertThat(genre).isEqualTo("Fantasy, Supernatural/Occult, Horror, Mature, Superhero, Mythology, Drama")
assertThat(tags).isEqualTo("dark, Occult")
assertThat(pageCount).isEqualTo(237)
assertThat(languageISO).isEqualTo("en")
assertThat(scanInformation).isEqualTo("")

View file

@ -26,6 +26,7 @@
<Imprint>Vertigo</Imprint>
<Count>10</Count>
<Genre>Fantasy, Supernatural/Occult, Horror, Mature, Superhero, Mythology, Drama</Genre>
<Tags>dark, Occult</Tags>
<PageCount>237</PageCount>
<LanguageISO>en</LanguageISO>
<AgeRating>Mature 17+</AgeRating>