Start integrating some more song metadata

main
maia arson crimew 2021-12-16 00:49:55 +01:00
parent 4648e56b15
commit bdbea9fb42
12 changed files with 89 additions and 22 deletions

View File

@ -39,6 +39,9 @@ class HistoryEntity(
@ColumnInfo(name = "artist_name")
val artistName: String,
val composer: String?,
@ColumnInfo(name = "cover_art")
val coverArt: String?,
val genres: String?,
@ColumnInfo(name = "album_artist")
val albumArtist: String?,
@ColumnInfo(name = "time_played")

View File

@ -41,6 +41,9 @@ class PlayCountEntity(
val composer: String?,
@ColumnInfo(name = "album_artist")
val albumArtist: String?,
@ColumnInfo(name = "cover_art")
val coverArt: String?,
val genres: String?,
@ColumnInfo(name = "time_played")
val timePlayed: Long,
@ColumnInfo(name = "play_count")

View File

@ -19,7 +19,7 @@ import androidx.room.RoomDatabase
@Database(
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class, LyricsEntity::class],
version = 23,
version = 24,
exportSchema = false
)
abstract class RetroDatabase : RoomDatabase() {

View File

@ -48,5 +48,8 @@ class SongEntity(
val artistName: String,
val composer: String?,
@ColumnInfo(name = "album_artist")
val albumArtist: String?
val albumArtist: String?,
@ColumnInfo(name = "cover_art")
val coverArt: String?,
val genres: String?
) : Parcelable

View File

@ -43,7 +43,9 @@ fun Song.toHistoryEntity(timePlayed: Long): HistoryEntity {
artistName = artistName,
composer = composer,
albumArtist = albumArtist,
timePlayed = timePlayed
timePlayed = timePlayed,
coverArt = coverArt,
genres = genres?.joinToString(";")
)
}
@ -62,7 +64,9 @@ fun Song.toSongEntity(playListId: Long): SongEntity {
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
albumArtist = albumArtist,
coverArt = coverArt,
genres = genres?.joinToString(";")
)
}
@ -80,7 +84,9 @@ fun SongEntity.toSong(): Song {
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
albumArtist = albumArtist,
coverArt = coverArt,
genres = genres?.split(';')?.toTypedArray()
)
}
@ -98,7 +104,9 @@ fun PlayCountEntity.toSong(): Song {
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
albumArtist = albumArtist,
coverArt = coverArt,
genres = genres?.split(';')?.toTypedArray()
)
}
@ -116,7 +124,9 @@ fun HistoryEntity.toSong(): Song {
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
albumArtist = albumArtist,
coverArt = coverArt,
genres = genres?.split(';')?.toTypedArray()
)
}
@ -136,7 +146,9 @@ fun Song.toPlayCount(): PlayCountEntity {
composer = composer,
albumArtist = albumArtist,
timePlayed = System.currentTimeMillis(),
playCount = 1
playCount = 1,
coverArt = coverArt,
genres = genres?.joinToString(";")
)
}

View File

@ -15,7 +15,6 @@ import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.ArtistSignatureUtil
import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getFile
import code.name.monkey.retromusic.util.CustomArtistImageUtil.Companion.getInstance
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
import code.name.monkey.retromusic.util.PreferenceUtil
import com.bumptech.glide.GenericTransitionOptions
import com.bumptech.glide.Priority
@ -51,10 +50,11 @@ object RetroGlideExtension {
}
private fun getSongModel(song: Song, ignoreMediaStore: Boolean): Any {
return if (ignoreMediaStore) {
AudioFileCover(song.data)
return if (!song.coverArt.isNullOrEmpty()) {
song.coverArtUri!!
} else {
getMediaStoreAlbumCoverUri(song.albumId)
// this won't work but is a fallback for now i guess lol
AudioFileCover(song.data)
}
}

View File

@ -34,7 +34,9 @@ class PlaylistSong(
val playlistId: Long,
val idInPlayList: Long,
override val composer: String?,
override val albumArtist: String?
override val albumArtist: String?,
override val coverArt: String?,
override val genres: Array<String>?
) : Song(
id = id,
title = title,
@ -48,7 +50,9 @@ class PlaylistSong(
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
albumArtist = albumArtist,
coverArt = coverArt,
genres = genres
) {
override fun equals(other: Any?): Boolean {
@ -73,6 +77,8 @@ class PlaylistSong(
if (idInPlayList != other.idInPlayList) return false
if (composer != other.composer) return false
if (albumArtist != other.albumArtist) return false
if (coverArt != other.coverArt) return false
if (!genres.contentEquals(other.genres)) return false
return true
}
@ -93,7 +99,9 @@ class PlaylistSong(
result = 31 * result + playlistId.hashCode()
result = 31 * result + idInPlayList.hashCode()
result = 31 * result + composer.hashCode()
result = 31 * result + (albumArtist?.hashCode() ?: 0)
result = 31 * result + albumArtist.hashCode()
result = 31 * result + coverArt.hashCode()
result = 31 * result + genres.contentHashCode()
return result
}
}

View File

@ -13,6 +13,7 @@
*/
package code.name.monkey.retromusic.model
import android.net.Uri
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@ -24,6 +25,7 @@ open class Song(
open val trackNumber: Int,
open val year: Int,
open val duration: Long,
// stream path
open val data: String,
open val dateModified: Long,
open val albumId: Long,
@ -31,9 +33,14 @@ open class Song(
open val artistId: Long,
open val artistName: String,
open val composer: String?,
open val albumArtist: String?
open val albumArtist: String?,
open val coverArt: String?,
// TODO: store genres in a smarter way
open val genres: Array<String>?
) : Parcelable {
val coverArtUri: Uri?
get() = Uri.parse(coverArt)
// need to override manually because is open and cannot be a data class
override fun equals(other: Any?): Boolean {
@ -55,6 +62,8 @@ open class Song(
if (artistName != other.artistName) return false
if (composer != other.composer) return false
if (albumArtist != other.albumArtist) return false
if (coverArt != other.coverArt) return false
if (!genres.contentEquals(other.genres)) return false
return true
}
@ -73,6 +82,8 @@ open class Song(
result = 31 * result + artistName.hashCode()
result = 31 * result + (composer?.hashCode() ?: 0)
result = 31 * result + (albumArtist?.hashCode() ?: 0)
result = 31 * result + (coverArt?.hashCode() ?: 0)
result = 31 * result + (genres?.contentHashCode() ?: 0)
return result
}
@ -93,7 +104,9 @@ open class Song(
artistId = -1,
artistName = "",
composer = "",
albumArtist = ""
albumArtist = "",
coverArt = "",
genres = emptyArray()
)
}
}

View File

@ -53,6 +53,7 @@ interface PlaylistRepository {
fun playlistSongs(playlistId: Long): List<Song>
}
// TODO: uncursorify this
class RealPlaylistRepository(
private val contentResolver: ContentResolver
) : PlaylistRepository {
@ -168,7 +169,9 @@ class RealPlaylistRepository(
playlistId,
idInPlaylist,
composer ?: "",
albumArtist
albumArtist,
null,
emptyArray()
)
}

View File

@ -32,6 +32,7 @@ import code.name.monkey.retromusic.model.Song
* Created by hemanths on 16/08/17.
*/
// TODO: uncursorify this
object PlaylistSongsLoader {
fun getPlaylistSongList(
@ -99,7 +100,9 @@ object PlaylistSongsLoader {
playlistId,
idInPlaylist,
composer,
albumArtist
albumArtist,
null,
emptyArray()
)
}

View File

@ -85,7 +85,7 @@ class RealSongRepository(private val context: Context) : SongRepository {
"river-lake convergence",
1,
2021,
23723478,
237234,
"https://versary.town/river-lake-convergence.mp3",
1639589623,
1,
@ -93,7 +93,26 @@ class RealSongRepository(private val context: Context) : SongRepository {
1,
"annieversary",
null,
"annieversary"
"annieversary",
"https://i1.sndcdn.com/artworks-T3nLbND6w681B2ey-YDI6ew-t500x500.jpg",
genres = arrayOf("Lakecore")
),
Song(
2,
"river-lake convergence 2",
1,
2021,
237234,
"https://versary.town/river-lake-convergence.mp3",
1639589623,
2,
"river-lake convergence 2",
1,
"annieversary",
null,
"annieversary",
"https://i1.sndcdn.com/artworks-T3nLbND6w681B2ey-YDI6ew-t500x500.jpg",
genres = arrayOf("Lakecore")
)
)
}

View File

@ -854,7 +854,7 @@ public class MusicService extends MediaBrowserServiceCompat
.setMediaId(String.valueOf(song.getId()))
.setTitle(song.getTitle())
.setSubtitle(song.getArtistName())
.setIconUri(MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()))
.setIconUri(song.getCoverArtUri())
.build(), FLAG_PLAYABLE
);
result.sendResult(Collections.singletonList(mediaItem));