music: lowercase names when hashing

Lowercase music names when hashing them to prevent drift stemming from
grouping.

The addition of the song may change the case of an artist if such
mitigations are in effect. To prevent such from invalidating music
hashes, we take the lowercase of every name hashed.
This commit is contained in:
OxygenCobalt 2022-07-17 16:11:16 -06:00
parent 51b9b0e734
commit 10362b9efc
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 8 additions and 7 deletions

View file

@ -15,6 +15,7 @@ at the cost of longer loading times
- Fixed shuffle shortcut and file opening not working on startup on some devices - Fixed shuffle shortcut and file opening not working on startup on some devices
#### What's Changed #### What's Changed
- Play and skip icons are filled again
- Updated music hashing (Will wipe playback state) - Updated music hashing (Will wipe playback state)
## 2.5.0 ## 2.5.0

View file

@ -110,9 +110,9 @@ data class Song(
) : Music() { ) : Music() {
override val id: Long override val id: Long
get() { get() {
var result = rawName.hashCode().toLong() var result = rawName.lowercase().hashCode().toLong()
result = 31 * result + album.rawName.hashCode() result = 31 * result + album.rawName.lowercase().hashCode()
result = 31 * result + (album.artist.rawName ?: MediaStore.UNKNOWN_STRING).hashCode() result = 31 * result + (album.artist.rawName?.lowercase() ?: MediaStore.UNKNOWN_STRING).hashCode()
result = 31 * result + (track ?: 0) result = 31 * result + (track ?: 0)
result = 31 * result + (disc ?: 0) result = 31 * result + (disc ?: 0)
result = 31 * result + durationMs result = 31 * result + durationMs
@ -218,8 +218,8 @@ data class Album(
override val id: Long override val id: Long
get() { get() {
var result = rawName.hashCode().toLong() var result = rawName.lowercase().hashCode().toLong()
result = 31 * result + (artist.rawName ?: MediaStore.UNKNOWN_STRING).hashCode() result = 31 * result + (artist.rawName?.lowercase() ?: MediaStore.UNKNOWN_STRING).hashCode()
result = 31 * result + (date?.year ?: 0) result = 31 * result + (date?.year ?: 0)
return result return result
} }
@ -262,7 +262,7 @@ data class Artist(
} }
override val id: Long override val id: Long
get() = (rawName ?: MediaStore.UNKNOWN_STRING).hashCode().toLong() get() = (rawName?.lowercase() ?: MediaStore.UNKNOWN_STRING).hashCode().toLong()
override fun resolveName(context: Context) = rawName ?: context.getString(R.string.def_artist) override fun resolveName(context: Context) = rawName ?: context.getString(R.string.def_artist)
@ -283,7 +283,7 @@ data class Genre(override val rawName: String?, override val songs: List<Song>)
get() = rawName get() = rawName
override val id: Long override val id: Long
get() = (rawName ?: MediaStore.UNKNOWN_STRING).hashCode().toLong() get() = (rawName?.lowercase() ?: MediaStore.UNKNOWN_STRING).hashCode().toLong()
override fun resolveName(context: Context) = rawName ?: context.getString(R.string.def_genre) override fun resolveName(context: Context) = rawName ?: context.getString(R.string.def_genre)
} }