musikr: remove musictype auxio dependency
This commit is contained in:
parent
c70c27a7b4
commit
3da9e6c5b3
5 changed files with 32 additions and 25 deletions
|
@ -81,23 +81,34 @@ sealed interface Music : Item {
|
|||
class UID
|
||||
private constructor(
|
||||
private val format: Format,
|
||||
private val type: MusicType,
|
||||
private val item: Item,
|
||||
private val uuid: UUID
|
||||
) : Parcelable {
|
||||
// Cache the hashCode for HashMap efficiency.
|
||||
@IgnoredOnParcel private var hashCode = format.hashCode()
|
||||
|
||||
init {
|
||||
hashCode = 31 * hashCode + type.hashCode()
|
||||
hashCode = 31 * hashCode + item.hashCode()
|
||||
hashCode = 31 * hashCode + uuid.hashCode()
|
||||
}
|
||||
|
||||
override fun hashCode() = hashCode
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is UID && format == other.format && type == other.type && uuid == other.uuid
|
||||
other is UID && format == other.format && item == other.item && uuid == other.uuid
|
||||
|
||||
override fun toString() = "${format.namespace}:${type.intCode.toString(16)}-$uuid"
|
||||
override fun toString() = "${format.namespace}:${item.intCode.toString(16)}-$uuid"
|
||||
|
||||
enum class Item(val intCode: Int) {
|
||||
// Item used to be MusicType back when the music module was
|
||||
// part of Auxio, so these old integer codes remain.
|
||||
// TODO: Introduce new UID format that removes these.
|
||||
SONG(0xA10B),
|
||||
ALBUM(0xA10A),
|
||||
ARTIST(0xA109),
|
||||
GENRE(0xA108),
|
||||
PLAYLIST(0xA107)
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal marker of [Music.UID] format type.
|
||||
|
@ -125,23 +136,23 @@ sealed interface Music : Item {
|
|||
* Creates an Auxio-style [UID] of random composition. Used if there is no
|
||||
* non-subjective, unlikely-to-change metadata of the music.
|
||||
*
|
||||
* @param type The analogous [MusicType] of the item that created this [UID].
|
||||
* @param item The type of [Item] that created this [UID].
|
||||
*/
|
||||
fun auxio(type: MusicType): UID {
|
||||
return UID(Format.AUXIO, type, UUID.randomUUID())
|
||||
fun auxio(item: Item): UID {
|
||||
return UID(Format.AUXIO, item, UUID.randomUUID())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Auxio-style [UID] with a [UUID] composed of a hash of the non-subjective,
|
||||
* unlikely-to-change metadata of the music.
|
||||
*
|
||||
* @param type The analogous [MusicType] of the item that created this [UID].
|
||||
* @param item The type of [Item] that created this [UID].
|
||||
* @param updates Block to update the [MessageDigest] hash with the metadata of the
|
||||
* item. Make sure the metadata hashed semantically aligns with the format
|
||||
* specification.
|
||||
* @return A new auxio-style [UID].
|
||||
*/
|
||||
fun auxio(type: MusicType, updates: MessageDigest.() -> Unit): UID {
|
||||
fun auxio(item: Item, updates: MessageDigest.() -> Unit): UID {
|
||||
val digest =
|
||||
MessageDigest.getInstance("SHA-256").run {
|
||||
updates()
|
||||
|
@ -171,19 +182,19 @@ sealed interface Music : Item {
|
|||
.or(digest[13].toLong().and(0xFF).shl(16))
|
||||
.or(digest[14].toLong().and(0xFF).shl(8))
|
||||
.or(digest[15].toLong().and(0xFF)))
|
||||
return UID(Format.AUXIO, type, uuid)
|
||||
return UID(Format.AUXIO, item, uuid)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MusicBrainz-style [UID] with a [UUID] derived from the MusicBrainz ID
|
||||
* extracted from a file.
|
||||
*
|
||||
* @param type The analogous [MusicType] of the item that created this [UID].
|
||||
* @param item The analogous [MusicType] of the item that created this [UID].
|
||||
* @param mbid The analogous MusicBrainz ID for this item that was extracted from a
|
||||
* file.
|
||||
* @return A new MusicBrainz-style [UID].
|
||||
*/
|
||||
fun musicBrainz(type: MusicType, mbid: UUID) = UID(Format.MUSICBRAINZ, type, mbid)
|
||||
fun musicBrainz(item: Item, mbid: UUID) = UID(Format.MUSICBRAINZ, item, mbid)
|
||||
|
||||
/**
|
||||
* Convert a [UID]'s string representation back into a concrete [UID] instance.
|
||||
|
@ -211,8 +222,8 @@ sealed interface Music : Item {
|
|||
return null
|
||||
}
|
||||
|
||||
val type =
|
||||
MusicType.fromIntCode(ids[0].toIntOrNull(16) ?: return null) ?: return null
|
||||
val intCode = ids[0].toIntOrNull(16) ?: return null
|
||||
val type = Item.entries.firstOrNull { it.intCode == intCode } ?: return null
|
||||
val uuid = ids[1].toUuidOrNull() ?: return null
|
||||
return UID(format, type, uuid)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.oxycblt.musikr.model
|
||||
|
||||
import org.oxycblt.auxio.music.MusicType
|
||||
import org.oxycblt.auxio.util.update
|
||||
import org.oxycblt.musikr.Album
|
||||
import org.oxycblt.musikr.Artist
|
||||
|
@ -45,8 +44,8 @@ class AlbumImpl(private val core: AlbumCore) : Album {
|
|||
|
||||
override val uid =
|
||||
// Attempt to use a MusicBrainz ID first before falling back to a hashed UID.
|
||||
preAlbum.musicBrainzId?.let { Music.UID.musicBrainz(MusicType.ALBUMS, it) }
|
||||
?: Music.UID.auxio(MusicType.ALBUMS) {
|
||||
preAlbum.musicBrainzId?.let { Music.UID.musicBrainz(Music.UID.Item.ALBUM, it) }
|
||||
?: Music.UID.auxio(Music.UID.Item.ALBUM) {
|
||||
// Hash based on only names despite the presence of a date to increase stability.
|
||||
// I don't know if there is any situation where an artist will have two albums with
|
||||
// the exact same name, but if there is, I would love to know.
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.oxycblt.musikr.model
|
||||
|
||||
import org.oxycblt.auxio.music.MusicType
|
||||
import org.oxycblt.auxio.util.update
|
||||
import org.oxycblt.musikr.Album
|
||||
import org.oxycblt.musikr.Artist
|
||||
|
@ -44,8 +43,8 @@ interface ArtistCore {
|
|||
class ArtistImpl(private val core: ArtistCore) : Artist {
|
||||
override val uid =
|
||||
// Attempt to use a MusicBrainz ID first before falling back to a hashed UID.
|
||||
core.preArtist.musicBrainzId?.let { Music.UID.musicBrainz(MusicType.ARTISTS, it) }
|
||||
?: Music.UID.auxio(MusicType.ARTISTS) { update(core.preArtist.rawName) }
|
||||
core.preArtist.musicBrainzId?.let { Music.UID.musicBrainz(Music.UID.Item.ARTIST, it) }
|
||||
?: Music.UID.auxio(Music.UID.Item.ARTIST) { update(core.preArtist.rawName) }
|
||||
override val name = core.preArtist.name
|
||||
|
||||
override val songs = core.songs
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.oxycblt.musikr.model
|
||||
|
||||
import org.oxycblt.auxio.music.MusicType
|
||||
import org.oxycblt.auxio.util.update
|
||||
import org.oxycblt.musikr.Artist
|
||||
import org.oxycblt.musikr.Genre
|
||||
|
@ -39,7 +38,7 @@ interface GenreCore {
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class GenreImpl(private val core: GenreCore) : Genre {
|
||||
override val uid = Music.UID.auxio(MusicType.GENRES) { update(core.preGenre.rawName) }
|
||||
override val uid = Music.UID.auxio(Music.UID.Item.GENRE) { update(core.preGenre.rawName) }
|
||||
override val name = core.preGenre.name
|
||||
|
||||
override val songs = mutableSetOf<Song>()
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.oxycblt.musikr.tag.interpret
|
|||
|
||||
import android.net.Uri
|
||||
import java.util.UUID
|
||||
import org.oxycblt.auxio.music.MusicType
|
||||
import org.oxycblt.auxio.playback.replaygain.ReplayGainAdjustment
|
||||
import org.oxycblt.auxio.util.update
|
||||
import org.oxycblt.musikr.Music
|
||||
|
@ -54,8 +53,8 @@ data class PreSong(
|
|||
val preGenres: List<PreGenre>
|
||||
) {
|
||||
fun computeUid() =
|
||||
musicBrainzId?.let { Music.UID.musicBrainz(MusicType.SONGS, it) }
|
||||
?: Music.UID.auxio(MusicType.SONGS) {
|
||||
musicBrainzId?.let { Music.UID.musicBrainz(Music.UID.Item.SONG, it) }
|
||||
?: Music.UID.auxio(Music.UID.Item.SONG) {
|
||||
// Song UIDs are based on the raw data without parsing so that they remain
|
||||
// consistent across music setting changes. Parents are not held up to the
|
||||
// same standard since grouping is already inherently linked to settings.
|
||||
|
|
Loading…
Reference in a new issue