From d30daf913ba5964737c408152c8519f2aea91ce6 Mon Sep 17 00:00:00 2001 From: j-romchain Date: Wed, 21 Sep 2022 11:09:15 -0400 Subject: [PATCH] added the ability to handle more than 50 albums, and a check to make sure that all the songs have the author being looked up as their author, and aren't a song from another person in the same album. (still lets joint authored pieces go, just blockes the unrelated ones) --- .../spotify/SpotifyProvider.kt | 33 +++++++++++++++++-- .../spotify/requests/SpotifyRequests.kt | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/SpotifyProvider.kt b/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/SpotifyProvider.kt index 7037f760..4879c298 100644 --- a/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/SpotifyProvider.kt +++ b/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/SpotifyProvider.kt @@ -146,8 +146,31 @@ class SpotifyProvider( val artistObject = getArtist(link) //and his image, etc for later val artistDataObject = getArtistData(link); + var albumsList = artistObject.items; + // Check For More Albums using code from the playlist handler \/ + var moreAlbumsAvailable = !artistObject.next.isNullOrBlank() + while (moreAlbumsAvailable) { + // Fetch Remaining Tracks + val moreAlbums = + getArtist(link, offset = albumsList?.size!!.toInt()); + //moreAlbums.items?.forEach() { + // albumsList = albumsList + it; + //} + //albumsList = albumsList+moreAlbums.items; + albumsList = albumsList!!.plus(ArrayList(moreAlbums?.items)); + //println(moreAlbums); + //println("hilow") + //albumsList.addAll(moreAlbums?.items); + //var list: MutableList = ArrayList(albumsList) + //list?.addAll(albumsList); + //list?.addAll(moreAlbums?.items); + //albumsList=list; + //println(albumsList!!.plus(moreAlbums?.items)); + moreAlbumsAvailable = !moreAlbums.next.isNullOrBlank() + //println(albumsList?.size); + } //now run some modified code from the album handler /\ in a loop for each album made by the author - artistObject.items?.forEach { + albumsList?.forEach { val albumObject = getAlbum(it?.id.toString()) folderType = "Artists" subFolder = artistDataObject?.name.toString() @@ -161,7 +184,13 @@ class SpotifyProvider( //println(tempTrackList); //and the track list needs to be added up, not just the last album //(might cause problems with previous runs residual tracks, depends on the rest of the code.) - trackList = trackList+it; + //println(it) + //make sure it isn't another persons song in the same album + it.forEach { + if (artistDataObject?.name.toString() in it?.artists.toString()) { + trackList = trackList + it; + } + } } } } diff --git a/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/requests/SpotifyRequests.kt b/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/requests/SpotifyRequests.kt index 28c104a1..54878488 100644 --- a/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/requests/SpotifyRequests.kt +++ b/common/providers/src/commonMain/kotlin/com.shabinder.common.providers/spotify/requests/SpotifyRequests.kt @@ -66,8 +66,8 @@ interface SpotifyRequests { return httpClient.get("$BASE_URL/albums/$id") } - suspend fun getArtist(id: String): artistAlbums { - return httpClient.get("$BASE_URL/artists/$id/albums?limit=50") + suspend fun getArtist(id: String, offset: Int = 0): artistAlbums { + return httpClient.get("$BASE_URL/artists/$id/albums?offset=$offset&limit=10") } suspend fun getArtistData(id: String): Artist {