Linux and "For The God Who Sings"...

In this page I have attempted to combine my love of an amazing radio broadcast called " For the God Who Sings" with my passion for Linux. Perhaps an uneasy mix in the eyes of many but humour me, Gentle Reader, and read the entire page; perhaps you will follow me down this same path? Every Sunday night at 2200hrs Stephen Watkins hosts a 2 hour radio show that presents "music and texts that seek to enlighten the path untravelled, the idea unravelled". Following the iconic introduction of Arvo Pärt's 'Cantus in Memoriam Benjamin Britten' Stephen's beautiful and quietly contemplative voice introduces and expands on sacred music for 2 peaceful hours. The music echoes the title of the radio presentation as it speaks of God, with words from Zephaniah 3:14-17, in an exultation of song:

Sing aloud, O daughter Zion; shout, O Israel! Rejoice and exult with all your heart, O daughter Jerusalem! The LORD has taken away the judgements against you, he has turned away your enemies. The king of Israel, the LORD, is in your midst; you shall fear disaster no more. On that day it shall be said to Jerusalem: Do not fear O Zion; do not let your hands grow weak. The LORD, your God, is in your midst, a warrior who gives you victory; he will rejoice over you with gladness, he will renew you in his love; he will exult over you with loud singing as on a day of festival.

But can I say for all this it is often way past my bedtime!! So on this page I will demonstrate how with crontab, FFmpeg, eyeD3 and AtomicParsley you can download the live stream of "For the God Who Sings" in a format suitable for offline playback on any computer, smart phone or similar playback device. A perhaps unusual mix of religious music and modern technology?

All the steps...

Downloading and converting the live stream for "For The God Who Sings" can be easily done from within most modern Linux distros that have a recent copy of FFmpeg and eyeD3. However I will share a few tips and tricks that will hopefully make the whole process a little easier, so that you will not have to struggle, as I initially did, to get it all set up and running smoothly.

Finding the stream...

ABC is not hugely forthcoming about the actual location of their live streams, I suspect that they would prefer people to use ABC apps or web based players; fair enough. As well it is a little difficult to download the older copies of the broadcasts for offline use. Never fear, Gentle Reader, I have managed to sort out both the live streams and the HLS (HTTP Live Streaming) streams used for the older broadcasts of "For The God Who Sings". The ABC ClassicFM station live broadcast itself can still be accessed directly via one of the three links below:

# AAC (HE-AACv2), 44100 Hz, stereo, 64 kb/s:
ffplay https://live-radio01.mediahubaustralia.com/2FMW/aac/

# mp3, 44100 Hz, stereo, fltp, 96 kb/s:
ffplay https://live-radio01.mediahubaustralia.com/2FMW/mp3/

# AAC HLS Stream:
ffplay https://abcradiolivehls-lh.akamaihd.net/i/classicfmnsw_1@327292/index_64_a-p.m3u8

The biggest reason to initially play back these streams is so that their bitrate and their specific codecs can be identified. From this the decision will be made whether to use FFmpeg to simply copy the stream, convert to stream to a suitable lossy codec or whether to save the stream to a lossless format such as wav or flac. For my purposes here I use the mp3 stream because it sounds better on my playback devices; for this a simple 'copy' will suffice. A bigger bitrate or a lossless stream would be better to work with but neither of these are available.

Scripting the stream...

The real magic of course lies in capturing the stream live as it is actually broadcast and I have developed a small script to do this for me automagically every Sunday night between 2159hrs and 0001hrs. This contains a 1 minute 'sneeze' factor before and after the 2 hour broadcast. I have named the following script ftgws_download.sh and it lives in /home/andrew/bin:

#!/bin/sh
#---------------------------------------------------------------#
#  A very simple script to capture the live radio broadcast of: #
#               'For the God Who Sings'                         #
#  Tested with FFmpeg N-102841-g041267b558 and eyeD3 0.9.6      #
#---------------------------------------------------------------#

# All of the variables:
DATE=$(date +"%Y-%m-%d")
STREAM=https://live-radio01.mediahubaustralia.com/2FMW/mp3/
DURATION=02:02:00.00
MUSIC_DIR=$HOME/ssd2/ftgws/

set -e

cd $MUSIC_DIR

# Download the stream and copy / save in mp3 format:
ffmpeg -i $STREAM -t $DURATION -c copy ftgws_$DATE.mp3

sleep 30

# Set some tags in place as well as embed a decent cover art image:
#    https://id3.org/id3v2.4.0-frames
#    https://www.andrews-corner.org/images/ftgws_300x300.jpg
      
eyeD3 --remove-all \
      --artist "Stephen Watkins" \
      --album-artist "Various" \
      --album "For the God Who Sings" \
      --track 1 \
      --track-total 1 \
      --title "Ftgws $DATE" \
      --genre "Classical" \
      --recording-date "$DATE" \
      --add-image "ftgws_300x300.jpg:FRONT_COVER" \
      --add-comment "Thanks to ABC Classic FM & Stephen Watkins..." \
      --text-frame TENC:"Andrew Strong" \
      --url-frame WORS:"http\\://www.abc.net.au/classic/program/forthegodwhosings/" \
      ftgws_$DATE.mp3

# Send an email to notify yourself of the successful download and encode!
# You will, Gentle Reader, have to setup mailx / s-nail etc to accomplish this:

echo "Start listening to: ftgws_$DATE.mp3!!" | mailx -s "For the God Who Sings..." \
      xxxxx.xxxxx.xxxxx@gmail.com

The script is run from cron as follows (after running crontab -e as an ordinary user):

# Runs the ftgws_download.sh script every Sunday:                               
59 21 * * sun /home/andrew/bin/ftgws_download.sh

So all that remains now is for you to open up your favourite command line player mpg123, mpv or simply load the file onto your iPod and then sit back and prepare to be enchanted for two beautiful hours as you listen to "For the God Who Sings" with Stephen Watkins.

And if this fails...

If for whatever reason the capture of the live stream fails it is still possible to catch the archived copy which is available as an HLS stream for 28 days. This requires a little more work but again, Gentle Reader, I have done this work already! The HLS stream that I have found for these archived copies of the broadcast seem to only be AAC (LC) with a bitrate of 96 kb/s. Playback is pretty straightforward:

ffplay https://abcradiomodhls-vh.akamaihd.net/i/classic/audio/fgs-2021-07-18.m4a/master.m3u8

Note that ABC ClassicFM appears to simply alter the naming convention for its archived and streamable files using the filename convention 'fgs-YYYY-MM-DD.m4a', meaning that you can simply alter the filename in the stream to download the newer or older archived programs. I have created a simple script that will accomplish this that only requires the filename to be altered each week to download a new archive. Note that this time AtomicParsley will be used to tag the output file:

#!/bin/sh
#---------------------------------------------------------------#
#  A simple script to capture the archived radio broadcast of:  #
#               'For the God Who Sings'                         #
#     FFmpeg N-102841-g041267b558 and AtomicParsley 20210715    #
#---------------------------------------------------------------#

# The date variable must be adjusted each week in the format: YYYY-MM-DD
DATE=2021-07-18

STREAM=https://abcradiomodhls-vh.akamaihd.net/i/classic/audio/fgs-$DATE.m4a/master.m3u8
MUSIC_DIR=$HOME/ssd2/ftgws/

set -e
cd $MUSIC_DIR

ffmpeg -i $STREAM -bsf:a aac_adtstoasc -c copy ftgws-$DATE.m4a

AtomicParsley ftgws-$DATE.m4a \
       --artist "Stephen Watkins" \
       --album "For the God Who Sings" \
       --albumArtist "Various" \
       --title "ftgws $DATE" \
       --genre "Classical" \
       --artwork ftgws_300x300.jpg \
       --overWrite

Some work still to do on this little script but this is the sort of work and research I enjoy! For the moment that is a task for another day and I am going to settle back now and listen to this glorious music one more time...