Quantcast
Channel: Squeezebox : Community : Forums - 3rd Party Software
Viewing all articles
Browse latest Browse all 2059

Spotify Connect on LMS - Proof of concept

$
0
0
I've searched the web for a solution to use my Squeezeboxes as targets for Spotify Connect, but just come out empty handed. So, if you want something properly done, you have to do it yourself. :-)

As a first step, I created a proof of concept using librespot and vlc. This turned out to work quite well, so I thought I should share what I did. Note that this require a fair level of technical expertise. See this as inspiration, rather than a failure-proof step-by-step recipe (despite the format :-)).

I hope someone can help me pick this up to turn it into a proper plugin.

Anyway, here's the instructions.

1. Install rust

Follow the instructions on [rustup.rs](CENSORED). This is
typically: `curl CENSORED -sSf | sh`

2. Install librespot

Follow the instructions on [github](CENSORED).
This is typically: `git clone CENSORED`
followed by `cargo build --release`, if you have all dependencies installed
(portaudio and buildtools).

3. Install vlc

On Ubuntu, `sudo apt install vlc`.

4. Try it out

Collect some raw audio data from librespot: `target/release/librespot --name
Squeezebox --cache /tmp/librespot --backend pipe > /tmp/raw.dat`

Run this command, use another Spotify client to connect to "Squeezebox" and
play a song for like 10 seconds. Then exit the command with Ctrl-C. Verify
that you have a (fairly large) file `/tmp/raw.dat`.

Try converting the raw data to mp3 using vlc: `cvlc --demux=rawaud
--rawaud-channels 2 --rawaud-samplerate 44100 /tmp/raw.dat
:sout='#transcode{vcodec=none,acodec=mp3,ab=320,ch annels=2,samplerate=44100}:std{access=file,mux=raw ,dst=/tmp/vlc.mp3}'
:no-sout-rtp-sap :no-sout-standard-sap`

Verify that `/tmp/vlc.mp3` plays as an correct mp3 file.

5. Build a streaming pipeline

Connect librespot with vlc streaming: `target/release/librespot --name
SqueezeBox --cache /tmp/librespot --backend pipe | cvlc --demux=rawaud
--rawaud-channels 2 --rawaud-samplerate 44100 -
:sout='#transcode{vcodec=none,acodec=mp3,ab=320,ch annels=2,samplerate=44100}:http{dst=:8081/respot.mp3}'
:no-sout-rtp-sap :no-sout-standard-sap`

6. Listen in on the Squeezebox

On your Squeezebox, go to Radio > Tune in URL and enter
`CENSORED`, where HOSTNAME is the name of the host you're
running librespot on.

If all works well, you should now have streaming music from Spotify Connect.

7. Tie it all together

You'd probably want to start the librespot + vlc command on boot, and add
the URL as a bookmark. How to achieve this is left as an excercise to the
reader.

8. Limitations

You will not get track information or album art, since from the Squeezebox
point of view you're just playing a single streaming mp3 file. There's a
clear and noticable lag (~ 5 seconds) from the control on Spotify. This
solution requires extra CPU power due to the re-encoding of the stream. It
is probably not very robust, and it is likely that you will need to restart
the pipeline from time to time. The legal reservations that apply to
librespot of course also apply to this solution (that is, if this is
considered a breach of the Spotify ToS or not).

Consider this a proof of concept. I'd really like to turn this into a proper
solution with an LMS plugin, but unfortunately I don't have the time to do
that.

Note that this solution will not replace nor conflict with any current
solution you have for playing music from Spotify directly on your Squeezebox
(the official client or the libspotify-based plugin).

9. Acknowledgements

I was inspired by [this blog
post](CENSORED).

Viewing all articles
Browse latest Browse all 2059

Trending Articles