image: properly handle uniqueness of non-embedded covers
Use a UID instead. This is non-ideal but all we can do.
This commit is contained in:
parent
657b8267f1
commit
e687658874
3 changed files with 15 additions and 4 deletions
|
@ -27,7 +27,7 @@ import javax.inject.Inject
|
|||
|
||||
class CoverKeyer @Inject constructor() : Keyer<Collection<Cover>> {
|
||||
override fun key(data: Collection<Cover>, options: Options) =
|
||||
"${data.map { it.perceptualHash }.hashCode()}"
|
||||
"${data.map { it.uniqueness }.hashCode()}"
|
||||
}
|
||||
|
||||
class CoverFetcher
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.image.extractor
|
|||
|
||||
import android.net.Uri
|
||||
import org.oxycblt.auxio.list.sort.Sort
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.Song
|
||||
|
||||
/**
|
||||
|
@ -31,14 +32,20 @@ import org.oxycblt.auxio.music.Song
|
|||
* an album cover.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
data class Cover(val perceptualHash: String?, val mediaStoreUri: Uri, val songUri: Uri) {
|
||||
data class Cover(val uniqueness: Uniqueness?, val mediaStoreUri: Uri, val songUri: Uri) {
|
||||
sealed interface Uniqueness {
|
||||
data class PerceptualHash(val perceptualHash: String) : Uniqueness
|
||||
|
||||
data class UID(val uid: Music.UID) : Uniqueness
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val FALLBACK_SORT = Sort(Sort.Mode.ByAlbum, Sort.Direction.ASCENDING)
|
||||
|
||||
fun order(songs: Collection<Song>) =
|
||||
FALLBACK_SORT.songs(songs)
|
||||
.map { it.cover }
|
||||
.groupBy { it.perceptualHash }
|
||||
.groupBy { it.uniqueness }
|
||||
.entries
|
||||
.sortedByDescending { it.value.size }
|
||||
.map { it.value.first() }
|
||||
|
|
|
@ -114,7 +114,11 @@ class SongImpl(
|
|||
get() = _genres
|
||||
|
||||
override val cover =
|
||||
Cover(rawSong.coverPerceptualHash, requireNotNull(rawSong.mediaStoreId).toCoverUri(), uri)
|
||||
Cover(
|
||||
rawSong.coverPerceptualHash?.let { Cover.Uniqueness.PerceptualHash(it) }
|
||||
?: Cover.Uniqueness.UID(uid),
|
||||
requireNotNull(rawSong.mediaStoreId).toCoverUri(),
|
||||
uri)
|
||||
|
||||
/**
|
||||
* The [RawAlbum] instances collated by the [Song]. This can be used to group [Song]s into an
|
||||
|
|
Loading…
Reference in a new issue