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)

This commit is contained in:
j-romchain 2022-09-21 11:09:15 -04:00
parent b88c119a01
commit d30daf913b
2 changed files with 33 additions and 4 deletions

View File

@ -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,10 +184,16 @@ 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.)
//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;
}
}
}
}
}
//and set the title and image from the author data above
title = artistDataObject?.name.toString();
coverUrl = artistDataObject?.images?.elementAtOrNull(0)?.url.toString();

View File

@ -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 {