Skip to content

Commit

Permalink
better volume cover fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Snd-R committed Feb 19, 2023
1 parent 3c9748e commit 2e54e53
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,22 @@ class MangaDexMetadataMapper(
links = links
)

val coversByLocale = covers.groupBy { it.locale }
// TODO configurable language
val books = covers.groupBy { it.volume }.values
.map { byVolume ->
byVolume.groupBy { it.locale }
.mapValues { (_, value) -> value.firstOrNull() }
}
.mapNotNull { byLocale ->
(byLocale["en"] ?: byLocale["jp"] ?: byLocale.values.firstOrNull())
?.let { coverArtToBook(it) }
}

return MetadataConfigApplier.apply(
ProviderSeriesMetadata(
id = ProviderSeriesId(manga.id.id),
metadata = metadata,
// TODO configurable language
books = (coversByLocale["en"] ?: coversByLocale["ja"] ?: coversByLocale.values.firstOrNull())?.map { coverArt ->
SeriesBook(
id = ProviderBookId(coverArt.fileName),
number = coverArt.volume?.toDoubleOrNull()?.let { BookRange(it, it) },
name = coverArt.volume,
type = null,
edition = null
)
} ?: emptyList()
books = books
),
seriesMetadataConfig
)
Expand All @@ -128,4 +129,14 @@ class MangaDexMetadataMapper(

return MetadataConfigApplier.apply(providerMetadata, bookMetadataConfig)
}

private fun coverArtToBook(coverArt: MangaDexCoverArt): SeriesBook {
return SeriesBook(
id = ProviderBookId(coverArt.fileName),
number = coverArt.volume?.toDoubleOrNull()?.let { BookRange(it, it) },
name = coverArt.volume,
type = null,
edition = null
)
}
}

0 comments on commit 2e54e53

Please sign in to comment.