From 5ea440a46b065b269400eeb5b274861e4a9cb7b8 Mon Sep 17 00:00:00 2001 From: 0xf4b1 <10889432+0xf4b1@users.noreply.github.com> Date: Sat, 23 Dec 2023 00:37:37 +0100 Subject: [PATCH] Add support for custom mixes and playlists from tidal-kt 0.2.0 --- .../soundcrowd/plugins/tidal/Plugin.kt | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tidal/src/main/java/com/tiefensuche/soundcrowd/plugins/tidal/Plugin.kt b/tidal/src/main/java/com/tiefensuche/soundcrowd/plugins/tidal/Plugin.kt index 122ab9b..51a099e 100644 --- a/tidal/src/main/java/com/tiefensuche/soundcrowd/plugins/tidal/Plugin.kt +++ b/tidal/src/main/java/com/tiefensuche/soundcrowd/plugins/tidal/Plugin.kt @@ -19,6 +19,7 @@ import com.tiefensuche.soundcrowd.extensions.MediaMetadataCompatExt import com.tiefensuche.soundcrowd.plugins.Callback import com.tiefensuche.soundcrowd.plugins.IPlugin import com.tiefensuche.tidal.api.Artist +import com.tiefensuche.tidal.api.Playlist import com.tiefensuche.tidal.api.Track /** @@ -30,8 +31,8 @@ class Plugin(appContext: Context, val context: Context) : IPlugin { const val name = "Tidal" const val TRACKS = "Tracks" const val ARTISTS = "Artists" - const val DAILY = "Daily Discovery" - const val NEW_ARRIVALS = "New Arrivals" + const val PLAYLISTS = "Playlists" + const val MIXES = "Mixes" } private val icon = BitmapFactory.decodeResource(context.resources, R.drawable.plugin_icon) @@ -89,7 +90,7 @@ class Plugin(appContext: Context, val context: Context) : IPlugin { override fun name(): String = name - override fun mediaCategories(): List = listOf(TRACKS, ARTISTS, DAILY, NEW_ARRIVALS) + override fun mediaCategories(): List = listOf(TRACKS, ARTISTS, PLAYLISTS, MIXES) override fun preferences() = listOf(connectPreference) @@ -102,22 +103,8 @@ class Plugin(appContext: Context, val context: Context) : IPlugin { when (mediaCategory) { TRACKS -> callback.onResult(tracksToMediaMetadataCompat(api.getTracks(refresh))) ARTISTS -> callback.onResult(artistsToMediaMetadataCompat(api.getArtists(refresh))) - DAILY -> callback.onResult( - tracksToMediaMetadataCompat( - api.getMix( - Endpoints.Mixes.MIX_DAILY_DISCOVERY, - refresh - ) - ) - ) - NEW_ARRIVALS -> callback.onResult( - tracksToMediaMetadataCompat( - api.getMix( - Endpoints.Mixes.MIX_NEW_ARRIVALS, - refresh - ) - ) - ) + PLAYLISTS -> callback.onResult(playlistToMediaMetadataCompat(api.getPlaylists(refresh))) + MIXES -> callback.onResult(playlistToMediaMetadataCompat(api.getMixes())) } } @@ -130,6 +117,8 @@ class Plugin(appContext: Context, val context: Context) : IPlugin { ) { when (mediaCategory) { ARTISTS -> callback.onResult(tracksToMediaMetadataCompat(api.getArtist(path.toLong(), refresh))) + PLAYLISTS -> callback.onResult(tracksToMediaMetadataCompat(api.getPlaylist(path, refresh))) + MIXES -> callback.onResult(tracksToMediaMetadataCompat(api.getMix(path, refresh))) } } @@ -191,6 +180,19 @@ class Plugin(appContext: Context, val context: Context) : IPlugin { } } + private fun playlistToMediaMetadataCompat(playlists: List): List { + return playlists.map { + MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, it.uuid) + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "") + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, it.title) + .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, it.artwork) + .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, it.duration) + .putString(MediaMetadataCompatExt.METADATA_KEY_TYPE, MediaMetadataCompatExt.MediaType.STREAM.name) + .build() + } + } + private fun sessionCallback(session: TidalApi.Session) { sharedPref.edit() .putLong(context.getString(R.string.user_id_key), session.userId!!)