Jump to content
ants

Building a Spotify player for my Mac SE/30

Recommended Posts

Hi all, I built a Spotify player for my Macintosh SE/30:


macplayer_front.thumb.jpg.91e8bae24cf5535ee451fad6fda02ce9.jpg

 

The app is called MacPlayer and works thanks to the magic of Spotify Connect. The speaker itself streams and plays the music, and the Mac simply tells the speaker which song to play (as well as volume, current playlist, shuffle mode and other settings). Communication is over Wifi:

 

macplayer_back.thumb.jpg.3c42d47f026ef7c9cc153bd6a8411428.jpg


The first version is pretty basic, it just plays your Spotify playlists. You can browse tracks, and the app displays 1-bit album art, which I think is a bit of fun:

 

album-1.png.8a1fd885118e562237f51e5b7864ac7f.pngalbum-2.png.b5e871b61681c01d8e7d438a9043becc.pngalbum-3.png.50cbdeaee686f665a6b2997428e87dcd.pngalbum-4.png.1796f1f07c82be2d200c4eca5f6cd506.pngalbum-5.png.1edf124f28c42895791311ecd8267c21.pngalbum-6.png.bab49d0308916a4b901504e27b314df5.png


You can also choose which device to play from via the Devices menu:

 

devices.png.3d19fdd9bd09d858d3ad5f73ba62157a.png


The app performs well on a stock SE/30, although it does rely on a bit of help from the on-board OpenWRT Wifi router to handle the HTTPS communication with the Spotify API. The router has stunnel installed on it, which acts as a HTTP to HTTPS tunnel. I updated the MacWifi Extension to allow the Mac to create SSL tunnels on the router as needed. Here’s a video of how the app performs (no music unfortunately due to Copyright):

 


Another problem I had to solve was authenticating the app with a Spotify account. Like most modern web API’s, Spotify uses OAuth to allow third party apps to access their services. However the OAuth flow requires a modern web browser for users to enter their login details. To overcome this, I wrote an OAuth bridge for vintage Macs which delegates the login part of the process to another device such as a smartphone. The first steps are handled on the Mac:

 

login-1.png.702207cf4739ec6cacbcb986e57da23a.pnglogin-2.png.15085f8739e582b6070aac6d94afdb8d.png

 

And then completed on a modern device:

 

macauth-1.thumb.png.4a6d7a9d62e948edb685c004b905af2a.png macauth-2.thumb.png.cb3beaf0deba557e6de84532b89d35f2.png macauth-3.thumb.png.073f6c0c46ebc9ec9c62cbf6efe21d17.png


The final hurdle was with text encoding. The modern web uses UTF-8 for encoding text - which is a variant of Unicode. However, Unicode support was only available on PowerPC Macs as of MacOS 8.5, prior to that it was Apple’s own MacRoman encoding. I was able to port a Unix library, libiconv, to the Mac which performs a “best guess” conversion between UTF-8 and MacRoman – so far from my testing it’s been flawless (on English text).

If you’d like to give MacPlayer a go, you’ll need the following:

 

 

  1. A Spotify Premium account (only Premium accounts can use Spotify Connect)
  2. A Spotify Connect speaker/device (any modern Mac or PC with Spotify installed can also act as a target device)
  3. A 68k Mac with an Ethernet Card
  4. An OpenWRT wifi router, such as the GL-AR300M. Follow the setup instructions on the MacWifi Readme.
  5. The latest version of the MacWifi Extension.
  6. Then download the MacPlayer app.

 

Just note that the first version is pretty limited, and probably buggy :)


Looking ahead, I’d like to get the app more functional – and colour monitor support is definitely on the wish list – but for now I’m going to take a break and enjoy the fruits of my labour.

Share this post


Link to post
Share on other sites

I am not a Spotify user but those screenshots are super coooool! 8-)

 

This was done with Retro68? I should probably be making time to learn to build something with that toolkit.

Share this post


Link to post
Share on other sites

Brilliant! I was waiting for this to drop since you mentioned it. Congrats on the build. Seems with the Oauth flow you've paved the way for a few more services too.

 

Re: Spotify connect device, looks like that would include Raspberry Pi as well - https://github.com/dtcooper/raspotify 

 

@nglevin yep looks like it was built in Retro68 according to the GitHub readme https://github.com/antscode/MacPlayer

Edited by nickpunt

Share this post


Link to post
Share on other sites

This is pretty spiffy!

 

Any chance you could make it work with Amazon Music as well? Or is the underlying architecture too different?

 

Maybe on better/higher end 68k Macs and/or OldWorld PPCs, you can allow for the option of playing audio through the computer's built-in sound? It'd likely sound quite bad on the SE/30 with its puny mono speaker, but on a Mac with better sound, it could be passable?

 

6 hours ago, ants said:

An OpenWRT wifi router, such as the GL-AR300M.

I *really* need to get myself one of these sometime!!

 

c

Share this post


Link to post
Share on other sites

This is incredible.

 

Idea: it's probably easier for a lot of people to stand up a small HTTP proxy on their local network that communicates with Spotify over HTTPS, rather than requiring that dedicated WiFI hardware. I think that would allow this to work regardless of how you're getting your TCP/IP party on... the "Spotify API URL" could presumably be added to the preferences of this app to enable something like that?

 

Would love to see this eventually take advantage slightly more modern Macs (OS 9-era?) with color album art, and possibly fewer workarounds required! This is a perfect excuse to put my Duo w/ Ethernet mini dock into use sitting on top of my receiver :)

 

Side note: seeing the WiFi antenna sticking out of the back of the SE/30 made my jaw drop. So cool, don't think I've seen that before.

Share this post


Link to post
Share on other sites

Dude. This could have been a darn good RetroChallenge project. Wow. Impressive. 

 

But, what is 68k.io? and how is it in involved? 

Edited by techknight

Share this post


Link to post
Share on other sites

@techknight 68k.io is a simple page that hits the Spotify API to grab a short code that you need to confirm your device's authorization. Seems you'd need to be logged into Spotify via your browser and then 68k.io just displays a page to grab the short key to confirm connection. That requires HTTPS & modern web browser as Ants mentioned. It doesn't look like it stores credentials or anything.

Share this post


Link to post
Share on other sites
30 minutes ago, nickpunt said:

@techknight 68k.io is a simple page that hits the Spotify API to grab a short code that you need to confirm your device's authorization. Seems you'd need to be logged into Spotify via your browser and then 68k.io just displays a page to grab the short key to confirm connection. That requires HTTPS & modern web browser as Ants mentioned. It doesn't look like it stores credentials or anything.

Maybe, but I dont see the 68k.io code, so to me, its abstracted so I cant see how it REALLY works. Would be awesome to me to see it so I could understand it better. Because there are gaps here personally I would like to fullfill. 

 

For a minute, I thought 68k.io was an internal webserver that ran on the openwrt platform or something, but it isnt. its an actual webserver with an actual https cert. 

Edited by techknight

Share this post


Link to post
Share on other sites
On 12/17/2018 at 11:00 AM, nickpunt said:

Seems with the Oauth flow you've paved the way for a few more services too

I created 2 separate GitHub projects for the OAuth stuff:

Technically these projects should work with any OAuth implementation.

 

20 hours ago, CC_333 said:

Any chance you could make it work with Amazon Music as well?

There doesn't seem to be much of an API for Amazon Music that I can find. Also, Spotify is the only streaming provider I'm aware of that streams music from the target device - and not from the source device, if that makes sense?

 

7 hours ago, eameso said:

Would this work with an imac G3?

If the imac is running a classic version of MacOS - or OS X with classic support, then maybe? You'd still need an OpenWRT router though.

Share this post


Link to post
Share on other sites
On 12/18/2018 at 2:11 AM, ants said:

...Spotify is the only streaming provider I'm aware of that streams music from the target device - and not from the source device, if that makes sense?

AirPlay hands off a URL to the target device, in most cases.

 

So: Apple Music via speakers, YouTube via Apple TV, etc

 

Anyway, awesome work! 

 

Edited by gingerbeardman

Share this post


Link to post
Share on other sites

This is way cool!

 

I have everything necessary, except that specific router. However, my router is OpenWRT compatible. Maybe this is the project that makes it worth trying out.

 

Also, for anyone interested, Amazon Echos can be used as Spotify connect targets as well. I imagine other smart speakers also work if they have Spotify support... maybe Sonos?

Share this post


Link to post
Share on other sites

Just kidding.  My router was only "Supported*" where the asterisk was a whole lot of broken features.  So I ordered a GL-AR300M.  Amazon has a deal going on right now for the model without the external antennas for $40, plus 10% off at checkout.  OpenWRT comes preinstalled.  I'll update on my progress of following your setup in a week or so.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×