Skip to content

Commit

Permalink
feat(metadata): use group-position for epub series index
Browse files Browse the repository at this point in the history
  • Loading branch information
bin101 authored Aug 29, 2024
1 parent 85a9934 commit 4354581
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ class EpubMetadataProvider(
.map { it.text().lowercase().removePrefix("isbn:") }
.firstNotNullOfOrNull { isbnValidator.validate(it) }

val seriesIndex =
opf.selectFirst("metadata > *|meta[property=belongs-to-collection]")?.attr("id")?.let { id ->
opf.selectFirst("metadata > *|meta[refines=#$id][property=group-position]")
}?.text()

return BookMetadataPatch(
title = title,
summary = description,
releaseDate = date,
authors = authors,
isbn = isbn,
number = seriesIndex?.ifBlank { null },
numberSort = seriesIndex?.toFloatOrNull(),
)
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class EpubMetadataProviderTest {
Author("The Editor", "editor"),
)
assertThat(isbn).isEqualTo("9783440077894")
assertThat(number).isEqualTo("1.5")
assertThat(numberSort).isEqualTo(1.5f)
}
}

Expand All @@ -74,6 +76,8 @@ class EpubMetadataProviderTest {
Author("Stefanie Wegner", "writer"),
)
assertThat(isbn).isEqualTo("9783440077931")
assertThat(number).isEqualTo("3")
assertThat(numberSort).isEqualTo(3f)
}
}

Expand All @@ -94,6 +98,8 @@ class EpubMetadataProviderTest {
assertThat(releaseDate).isEqualTo(LocalDate.of(2021, 6, 20))
assertThat(authors).containsExactlyInAnyOrder(Author("Ralph Burke", "writer"))
assertThat(isbn).isNull()
assertThat(number).isNull()
assertThat(numberSort).isNull()
}
}

Expand All @@ -114,6 +120,8 @@ class EpubMetadataProviderTest {
Author("The Editor", "editor"),
)
assertThat(isbn).isNull()
assertThat(number).isNull()
assertThat(numberSort).isNull()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion komga/src/test/resources/epub/Panik im Paradies.opf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<opf:meta property="calibre:rating">6</opf:meta>
<opf:meta property="belongs-to-collection" id="id-2">Die drei ??? Kids</opf:meta>
<opf:meta refines="#id-2" property="collection-type">series</opf:meta>
<opf:meta refines="#id-2" property="group-position">1</opf:meta>
<opf:meta refines="#id-2" property="group-position">1.5</opf:meta>
<opf:meta property="calibre:author_link_map">{"Ulf Blanck": ""}</opf:meta>
</metadata>
<manifest>
Expand Down

0 comments on commit 4354581

Please sign in to comment.