feat(metadata): support multiple values in Web field from ComicInfo.xml

Closes: #1639
This commit is contained in:
Gauthier Roebroeck 2024-09-11 11:17:09 +08:00
parent f07be065d2
commit d12f3b3493
2 changed files with 35 additions and 12 deletions

View file

@ -89,16 +89,18 @@ class ComicInfoProvider(
}
}
val link =
comicInfo.web?.let {
try {
val uri = URI(it)
listOf(WebLink(uri.host, uri))
} catch (e: Exception) {
logger.error(e) { "Could not parse Web element as valid URI: $it" }
null
val links =
comicInfo.web
?.split(" ")
?.filter { it.isNotBlank() }
?.mapNotNull {
try {
URI(it.trim()).let { uri -> WebLink(uri.host, uri) }
} catch (e: Exception) {
logger.error(e) { "Could not parse Web element as valid URI: $it" }
null
}
}
}
val tags = comicInfo.tags?.split(',')?.mapNotNull { it.trim().lowercase().ifBlank { null } }
@ -112,7 +114,7 @@ class ComicInfoProvider(
releaseDate = releaseDate,
authors = authors.ifEmpty { null },
readLists = readLists,
links = link,
links = links?.ifEmpty { null },
tags = if (!tags.isNullOrEmpty()) tags.toSet() else null,
isbn = isbn,
)

View file

@ -57,7 +57,7 @@ class ComicInfoProviderTest {
alternateSeries = "story arc"
alternateNumber = "5"
storyArc = "one, two, three"
web = "https://www.comixology.com/Sandman/digital-comic/727888"
web = " https://www.comixology.com/Sandman/digital-comic/727888 https://www.comics.com/Sandman/digital-comic/727889 "
tags = "dark, Occult"
gtin = "9783440077894"
}
@ -84,9 +84,9 @@ class ComicInfoProviderTest {
)
assertThat(links)
.hasSize(1)
.containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
WebLink("www.comics.com", URI("https://www.comics.com/Sandman/digital-comic/727889")),
)
assertThat(tags as Iterable<String>)
@ -95,6 +95,25 @@ class ComicInfoProviderTest {
}
}
@Test
fun `given comicInfo with single link when getting book metadata then metadata patch is valid`() {
val comicInfo =
ComicInfo().apply {
web = "https://www.comixology.com/Sandman/digital-comic/727888"
}
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
val patch = comicInfoProvider.getBookMetadataFromBook(BookWithMedia(book, media))
with(patch!!) {
assertThat(links)
.containsExactlyInAnyOrder(
WebLink("www.comixology.com", URI("https://www.comixology.com/Sandman/digital-comic/727888")),
)
}
}
@Test
fun `given comicInfo with StoryArcNumber when getting book metadata then metadata patch is valid`() {
val comicInfo =
@ -236,6 +255,7 @@ class ComicInfoProviderTest {
storyArc = ""
penciller = ""
gtin = ""
web = ""
}
every { mockMapper.readValue(any<ByteArray>(), ComicInfo::class.java) } returns comicInfo
@ -250,6 +270,7 @@ class ComicInfoProviderTest {
assertThat(authors).isNull()
assertThat(readLists).isEmpty()
assertThat(isbn).isNull()
assertThat(links).isNull()
}
}