How to listen to a live broadcast show on Spreaker, with a raspberry and a stereo

How to listen to a live broadcast show on Spreaker, with a raspberry and a stereo

I was used to listening to a radio show with two hosts: Sandro “Fuffo” Bernardini and Nicole Fondato. Then, for various reasons, they stopped broadcasting and started making a podcast on Spreaker. From 8 to 9 it goes live and then you can listen to it like any normal podcast. So I decided to use my Raspberry to listen to the show live every morning. The Raspberry is connected to my amplifier with a 3.5mm jack and a cable, like the one in the picture.

3-meter-stereo-jack-plug-3-5mm-to-2-x-phono-plugs-for-raspberry-pi-audio-lead-111-800x600.JPG (800×600)

I wrote a bash script that gets the latest show episode’s ID using the Spreaker API. The script saves the response to a variable rawresponse then, if the show is live, It retrieves the streaming audio URL. That URL does a 302 redirect towards the real location of the file, probably on a CDN, and this latest value of the URL is saved in a variable, then played via the MPlayer program (included in Linux)


#!/bin/bash
rawresponse=$(curl -s 'https://api.spreaker.com/v2/shows/5913168/episodes?sorting=newest')
islive=$(echo $rawresponse | jq --raw-output '.response.items[0].is_on_air')
if [ $islive == "true" ];
then
    urldef=$(echo $rawresponse | jq --raw-output '.response.items[0].playback_url')
    url=$(curl -w "%{url_effective}\n" -I -L -s -S $urldef -o /dev/null)
    mplayer $url > /dev/null
fi

 

Finally, using Linux crontab, every day from Monday to Friday at 8 o’clock (actually a few minutes earlier, at 7:59) it starts playing and the call stops playing at 9:20 (it stops it brutally via pkill, but it works, and therefore ok).  


# plumcake start
59 7 * * mon-fri /home/pi/plumcake-stereo.sh
# plumcake stop
20 9 * * mon-fri pkill mplayer

MiroAdmin