Ryan Daulton
Ryan Daulton

Reputation: 1237

Spotify iOS SDK returning songs that do not exist? - Swift

So I'm building some playlist and song retrieval into my app at the moment, and I'm really confused by some of the results I'm getting back from the API. It seems to be returning songs that no longer exist on Spotify or have been long removed from a playlist.

Retrieving a list of Playlists from a user is working fine, but just in case this problem is arising from the way I draw that playlist's tracks, here is the code I use to get them:

SPTPlaylistSnapshot.playlistWithURI(uri, accessToken: session.accessToken) { (error, playlistSnapshotOb) -> Void in
        if let playlistSnapshot = playlistSnapshotOb as? SPTPlaylistSnapshot {
            let itemz = playlistSnapshot.firstTrackPage.items //tracksForPlayback()
            for item in itemz{
                let track = item as! SPTPlaylistTrack
                let splice = "\(track.uri)"

                let trackURI = splice.stringByReplacingOccurrencesOfString("spotify:track:", withString: "")

                var displayArtist = String()
                let artistz = track.artists
                if artistz.count > 1{
                    for i in 0...(artistz.count - 1){
                       let itz = artistz[i] as! SPTPartialArtist
                        if i > 0 {
                            displayArtist += ", \(itz.name)"

                        }else{
                            displayArtist += "\(itz.name)"
                        }
                    }
                    self.tracks.append(track.name)
                    self.ArtistObjects.append(displayArtist)
                    self.uriS.append(trackURI)


                }else{
                    let singularArtist = artistz[0] as! SPTPartialArtist
                    displayArtist = singularArtist.name
                    self.tracks.append(track.name)
                    self.ArtistObjects.append(displayArtist)
                    self.uriS.append(trackURI)
                }

Additionally, below is a screenshot of the desktop Spotify app showing the real content of the playlist I am pulling: Spotify per Desktop

You'll see that the songs "Big Bank Dank" and "Light Day Remix" are not actually on this playlist, but for some reason, on my app below, when I pull this playlist, it has these songs listed: Spotify In My App

(Apparently I can't post an actual image because of my rep - apologies)

Any idea why it's doing this?

Upvotes: 1

Views: 403

Answers (1)

jooon
jooon

Reputation: 2031

The tracks are probably just not available any longer for some unspecified reason. This is quite common. By default, the Spotify client does not show unavailable tracks in playlists, but in settings there is a toggle you can flip so that they are shown as greyed out instead.

I don't know about iOS SDK, but there should be either an attribute telling you the available markets for the tracks or if it is playable or not, depending on the country of the user being logged in.

This is how it works in the Web API, which should be similar. https://developer.spotify.com/web-api/track-relinking-guide/

Upvotes: 0

Related Questions