epsil / spotgen

Spotify Playlist Generator
https://epsil.github.io/spotgen/
Other
130 stars 26 forks source link

Use an external Spotify library #6

Open epsil opened 7 years ago

epsil commented 7 years ago

This project should use an external library for Spotify requests. Since it is rather request-intensive, throttling is an absolute must so that we don't butt up against Spotify's rate limits.

Currently, Spotify requests are handled by our own spotify.js layer, which depends on the http.js client to enforce limits. In practice, this is done with a setTimeout() call with a delay set to 100 ms.

The most promising replacement library seems to be spotify-web-api-node. Unfortunately, that library currently lacks options for HTTP throttling. Until this issue is resolved, we will, of necessity, stick with our own implementation for the time being.

epsil commented 7 years ago

JMPerez, one of spotify-web-api-node's project owners, replied:

One option would be to have this built in, but we tried to keep the library as light as possible. What I have recommended in the past is to use something like https://github.com/JMPerez/promise-throttle. You can see an example of the library used together with the client-side Spotify JS wrapper on https://github.com/JMPerez/spotify-dedup/blob/b6091581e3700ccbb1e5a0e26dbb59422fa3d15f/app/scripts/main.js#L80.