andrehaveman / spotify-node-applescript

Control Spotify on Mac OSX with NodeJS and AppleScript
MIT License
316 stars 38 forks source link

Implement getArtwork to get the path to the artwork as PNG #6

Closed rmehner closed 11 years ago

rmehner commented 11 years ago

This implements a getArtwork method that gets the current artwork as PNG (from the actual TIFF Data that spotify returns). The conversion to PNG happens because it's more compatible with current browsers and everything.

Example:

var spotify = require('spotify-node-applescript');

spotify.getArtwork(function(err, artworkPath) {
    console.log('Current artwork is at %s', artworkPath);
});

Please note: The used applescript takes some time (0.5s to 1.5s on different machines), so don't run the script too often (not every second) or you will run into strange errors. Especially don't run them in parallel.

Also the apple script is seperated into an external file, which makes it easier to maintain IMHO.

rmehner commented 11 years ago

About the separation of the AppleScript: I'd love to do that for the other not-single line applescripts as well, as it makes maintaining way easier. But that might be a matter of taste.

If you prefer, I can inline the script for the artwork as well. Let me know what you think.

andrehaveman commented 11 years ago

I experienced a problem with the applescript in OSX 10.7. It has problems with the colons in the track id, which is used for the filename. I replaced colons with underscores to get it working in Lion (see: https://github.com/andrehaveman/spotify-node-applescript/blob/rmehner-get_artwork/lib/scripts/get_artwork.applescript).

I like the separate files.

andrehaveman commented 11 years ago

I merged it.

rmehner commented 11 years ago

Interesting, will investigate. Also we now have the same code twice (replace_chars is basically like escape_quotes). Wanted to improve the script anyway, will open up a new PR then :)