From 67a07dba498aaad3ea236fe37d77761f71e5facd Mon Sep 17 00:00:00 2001 From: shabinder Date: Sun, 11 Jul 2021 11:17:36 +0530 Subject: [PATCH] Metadata TrackNumber Inclusion when Available --- .../kotlin/com/shabinder/common/models/DownloadObject.kt | 1 + .../kotlin/com/shabinder/common/di/AudioTagging.kt | 5 +++++ .../com/shabinder/common/di/providers/SpotifyProvider.kt | 1 + 3 files changed, 7 insertions(+) diff --git a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt index 87df64c5..c03630e0 100644 --- a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt +++ b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt @@ -30,6 +30,7 @@ data class TrackDetails( var albumName: String? = null, var albumArtists: List = emptyList(), var genre: List = emptyList(), + var trackNumber: Int? = null, var year: String? = null, var comment: String? = null, var lyrics: String? = null, diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AudioTagging.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AudioTagging.kt index 23759240..871a6361 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AudioTagging.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AudioTagging.kt @@ -40,6 +40,8 @@ fun Mp3File.setId3v1Tags(track: TrackDetails): Mp3File { album = track.albumName year = track.year comment = "Genres:${track.comment}" + if(track.trackNumber != null) + this.track = track.trackNumber.toString() } this.id3v1Tag = id3v1Tag return this @@ -53,10 +55,13 @@ suspend fun Mp3File.setId3v2TagsAndSaveFile(track: TrackDetails) { title = track.title album = track.albumName year = track.year + genreDescription = "Genre: " + track.genre.joinToString(", ") comment = track.comment lyrics = track.lyrics ?: "" url = track.trackUrl + if(track.trackNumber != null) + this.track = track.trackNumber.toString() } try { val art = File(track.albumArtPath) diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt index d5951abb..361ef77f 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/SpotifyProvider.kt @@ -200,6 +200,7 @@ class SpotifyProvider( private fun List.toTrackDetailsList(type: String, subFolder: String) = this.map { TrackDetails( title = it.name.toString(), + trackNumber = it.track_number, genre = it.album?.genres?.filterNotNull() ?: emptyList(), artists = it.artists?.map { artist -> artist?.name.toString() } ?: listOf(), albumArtists = it.album?.artists?.mapNotNull { artist -> artist?.name } ?: emptyList(),