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>> {
|
class CoverKeyer @Inject constructor() : Keyer<Collection<Cover>> {
|
||||||
override fun key(data: Collection<Cover>, options: Options) =
|
override fun key(data: Collection<Cover>, options: Options) =
|
||||||
"${data.map { it.perceptualHash }.hashCode()}"
|
"${data.map { it.uniqueness }.hashCode()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
class CoverFetcher
|
class CoverFetcher
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.image.extractor
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import org.oxycblt.auxio.list.sort.Sort
|
import org.oxycblt.auxio.list.sort.Sort
|
||||||
|
import org.oxycblt.auxio.music.Music
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,14 +32,20 @@ import org.oxycblt.auxio.music.Song
|
||||||
* an album cover.
|
* an album cover.
|
||||||
* @author Alexander Capehart (OxygenCobalt)
|
* @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 {
|
companion object {
|
||||||
private val FALLBACK_SORT = Sort(Sort.Mode.ByAlbum, Sort.Direction.ASCENDING)
|
private val FALLBACK_SORT = Sort(Sort.Mode.ByAlbum, Sort.Direction.ASCENDING)
|
||||||
|
|
||||||
fun order(songs: Collection<Song>) =
|
fun order(songs: Collection<Song>) =
|
||||||
FALLBACK_SORT.songs(songs)
|
FALLBACK_SORT.songs(songs)
|
||||||
.map { it.cover }
|
.map { it.cover }
|
||||||
.groupBy { it.perceptualHash }
|
.groupBy { it.uniqueness }
|
||||||
.entries
|
.entries
|
||||||
.sortedByDescending { it.value.size }
|
.sortedByDescending { it.value.size }
|
||||||
.map { it.value.first() }
|
.map { it.value.first() }
|
||||||
|
|
|
@ -114,7 +114,11 @@ class SongImpl(
|
||||||
get() = _genres
|
get() = _genres
|
||||||
|
|
||||||
override val cover =
|
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
|
* The [RawAlbum] instances collated by the [Song]. This can be used to group [Song]s into an
|
||||||
|
|
Loading…
Reference in a new issue