Duuuuuuude!

Again, I know this is no big deal but I’ve never had such an uninterrupted stretch of things working as expected. I don’t mind the unexpected or things not working as long as I don’t spend days and days trying to figure out why. I like mistakes. I like fixing things. I like a learning curve.

Behold, my array.

array.png

Including compilations returns 42 items in the array.

I was pleasantly surprised at that little array panel opening on the right. AND the items are numbered!

Now to do that a few more times and replacing the old functions because …

I was making a motherload of requests (resulting in 423 “too many requests” errors) because, depending on how you request and album or song, you may or may not get all the properties you want. For example, Get An Artist’s Albums doesn’t give you each album’s popularity and Get An Album’s Tracks doesn’t give you each track’s popularity. Get An Album and Get A Track do. As you can see in the image above, depending on how you make the request, Alice has 37-67 albums and some of those albums are big-ass box sets with dozens of tracks.

I was pleased to discover I could reduce the number of requests by storing all albumIDs in an array and making a request using Get Several Albums (which, as it turns out, gives me Popularity I want and need) but, while Get An Artist’s Albums has a maximum limit of 50, Get Several Albums has a maximum limit of 20.

And so I think my pseudo code outline currently looks like this:

  1. Build artistURL using artistID
  2. Use artistURL to request artist JSON
    • Get artist name
    • Get artist popularity
  3. Build artistAlbumsURL using artistID
  4. Use artistAlbumsURL to request artist’s albums JSON
    • For each album
      • Push albumID into artistAlbums array
  5. Check for length of artistAlbums array
    • Splice into arrays of 20 items or less
    • For each array of artistAlbums
      • Request Several Albums
        • For each album
          • Get album popularity
          • Get album release date
          • Push trackIDs into albumTracks array
          • Check for length of albumTracks array
            • Splice into arrays of 50 items or less
            • For each array of albumTracks
              • Request Several Tracks
                • For each track
                  • Get track name
                  • Get track popularity
Advertisements

About jotascript

Aiming to please. Seeking to impress.
This entry was posted in APIs, JavaScript, Spotify. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s