I don´t know whether it is posible to programnthe recording of specific short periods of the broadcasted signal. Some community radio stations have as only (or main) income money that comes from gouvernamental advertisings, and it is rather time consuming fabricating the proof it. Any advise will be greatly apreciate it
Since we’re a Canadian terrestrial radio station we have to keep audio logs for the CRTC (Canadian Radio-Telecommunications Commission). We use wget to grab the MP3 stream from icecast and save it as an MP3 file. Every hour a cronjob kills the current wget process and launches a new one with a new file. Using just ‘kill <pid>’ (sending the SIGTERM signal to shut down the process) seems to make wget close the MP3 file gracefully so it has proper header and data frames.
Below is the script we use, launched from crontab every hour. You could certainly run it more frequently and for shorter times.
In addition we grab from the LibreTime API http://libretime.soundfm.ca/api/item-history-feed the default analytics log (defined in LibreTime "Analytics, History Templates), and display them on a web page. This is still under development, but you can see what we’re planning: Track List History - Radio Waterloo
Hope this helps!
–Bob.
#! /bin/bash
# Program : audiolog
# Purpose : Capture audio logs on txer server (CRTC requirement)
# Author : Bob Jonkman bob@radiowaterloo.ca
# Date : 16 February 2023
# Notes : - This script is launched hourly at every 00 minutes from root's crontab
# and at startup from /usr/local/bin/startup
# - Logfile rotated with /etc/logrotate.d/audiolog.rotate
# - .mp3 cleanup done with audiologcleanup in cron.daily
# Modified : 14 July 2023 Bob Jonkman
# - Create index.html to list files.
# Using icecast as webserver, so full URL path to files is needed.
# Audiologs at https://txer.radiowaterloo.ca:18443/audiologs/index.html
# 28 December 2023 Bob Jonkman
# - Added default.css to index file;
# - added <div id="gutter"> and <div id="content"> for styling
# 21 July 2024 Bob Jonkman
# - Added stream URL to log
# - redirect wget STDERR to logfile
# 25 July 2024 Bob Jonkman
# - Added commandline paramter sleeptime
# Usage : audiolog [SLEEPNUMBER[SUFFIX]]
# eg. audiolog 10s
# set -x -v #####DEBUG##### v= print each line; x= print expanded line
## These should go in the .netrc file (where?)
user=XXXXX
password=YYYYY
if [ "" == "${1}" ] ; then
## Account for delay (lag) from LibreTime server
### determined by downloading some audiologs and using Audacity to see where the hour really starts
sleeptime=26s
else
sleeptime=${1}
fi
audiologbase=/srv/audiologs
##### stream=http://txer.soundfm.ca:18765/station.remote ##### Why doesn't this work?
stream=http://localhost:18765/station.remote
logfile=/var/log/audiolog.log
function writelog () {
# $0 is the current script name
# $$ is the PID of the current shell process
# $* is the complete parameter list
echo $(date "+%FT%T") $0 $$ $* | tee -a "${logfile}" ##### Needs to redirect STDERR too
}
writelog "Start audiolog (sleeping for ${sleeptime})"
sleep ${sleeptime}
## set audiolog filename YYYY-MM-DDThh:mm:ss
audiologname=${audiologbase}/audiolog-start-$(date +"%FT%T").mp3
## Check that a previous PID exists
if [[ -e /tmp/audiolog.pid ]] ; then {
audiologpid=$(cat /tmp/audiolog.pid)
## kill previous wget
if [ "" != "${audiologpid}" ] ; then {
writelog Killing wget, PID=${audiologpid}
kill ${audiologpid}
errorlevel=${?}
writelog Killed wget, errorlevel=${errorlevel}, PID=${audiologpid}
} fi ##### "" != ${audiologpid}
} else {
writelog /tmp/audiolog.pid does not exist
###### Check for other wget processes connecting to ${stream} and kill them here
} fi ##### previous PID
## launch wget in background
writelog Starting wget, stream ${stream}, output to ${audiologname}
## Output file, Append logfile, Not Verbose (no progress bar), redirect STDERR to append to logfile, run in background
### Note: & run in background (Can't use --background (-b) because bash can't pickup the pid with ${!} )
wget -O ${audiologname} -a ${logfile} -nv --user=${user} --password=${password} ${stream} 2>>${logfile} &
audiologpid=${!}
errorlevel=${?}
writelog Started wget, errorlevel=${errorlevel}, PID=${audiologpid}
## PID only needs to exist for current session
echo ${audiologpid} > /tmp/audiolog.pid
writelog Creating index.html
## Create index.html to list files
echo "<!DOCTYPE html>" > ${audiologbase}/index.html
echo "<html lang=\"en\">" >> ${audiologbase}/index.html
echo " <head>" >> ${audiologbase}/index.html
echo " <meta charset=\"UTF-8\">" >> ${audiologbase}/index.html
echo " <meta name=\"generator\" content=\"/usr/local/audiolog\">" >> ${audiologbase}/index.html
echo " <meta name=\"author\" content=\"Bob Jonkman bob@radiowaterloo.ca\">" >> ${audiologbase}/index.html
echo " <meta name=\"description\" content=\"list of audio logs aired on CKMS-FM 102.7 Radio Waterloo for CRTC compliance\">" >> ${audiologbase}/index.html
echo " <link rel=\"stylesheet\" href=\"https://radiowaterloo.ca/default.css\" type=\"text/css\">" >> ${audiologbase}/index.html
echo " <title>Audio Logs - Radio Waterloo CKMS-FM 102.7</title>" >> ${audiologbase}/index.html
echo " </head>" >> ${audiologbase}/index.html
echo " <body>" >> ${audiologbase}/index.html
echo " <div id=\"gutter\">" >> ${audiologbase}/index.html
echo " <a href=\"https://radiowaterloo.ca/\" title=\"CKMS 102.7 FM | Radio Waterloo\"><img id=\"featured-image\" src=\"https://storage.radiowaterloo.ca/cropped-ckmsLogoFeaturedImage-1138x256-2.png\" alt=\"CKMS 102.7FM Radio Waterloo (sunflower logo and black text on a teal background)\" /></a>" >> ${audiologbase}/index.html
echo " <div id=\"content\">" >> ${audiologbase}/index.html
echo " <h1>Audio Logs</h1>" >> ${audiologbase}/index.html
## CD to avoid full pathnames (which would point outside the webroot)
cd ${audiologbase}
audiologcount=0
## list files, sorted by Time
for i in $(ls -t audiolog*) ; do
## list file, show Size in Human-readable format, Quote filenames
echo " <a href=\"/audiologs/${i}\">$(ls -shQ ${i})</a><br>" >> ${audiologbase}/index.html
let audiologcount++
done
echo " <p>File count: ${audiologcount}</p>" >> ${audiologbase}/index.html
echo " <p>Total size: $(du -sh)</p>" >> ${audiologbase}/index.html
echo " </div> <!-- id=content -->" >> ${audiologbase}/index.html
echo " </div> <!-- id=gutter -->" >> ${audiologbase}/index.html
echo " </body>" >> ${audiologbase}/index.html
echo "</html>" >> ${audiologbase}/index.html
writelog Finish audiolog
# EOF: audiolog
#! /bin/bash
# Program : getlibretimehistory
# Purpose : Use the LibreTime API to retrieve the history of scheduled tracks in json format
# The content is similar to the WebUI "Analytics, Log Sheet" for the past 24 hours
# Author : Bob Jonkman bob@radiowaterloo.ca
# Date : 7 April 2022
# Modified : 17 April 2022 - Added deletion of old files (more than 62 days, should be enough for the CRTC)
# 24 April 2022 - switch rm to internal find to prevent 0 parameter errors on rm
# 2 November 2022 - Change destination filename to include hour in order to keep hourly logs
# (daily logs have been incomplete due to programmers deleting tracks before end-of-day)
# 13 July 2024 - Added function writelog
# - Changed crontab to run on the 00m of the hour, so now calculate the previous hour for filename
# 16 Oct 2024 - Changed $destinationpath to separate code from content
# - Added check and creation for $destinationpath
# - Added STDERR redirect to commands
# - Changed filename to "tracklist-YYYY-M-DDTHH.json"
# set -x
destinationpath=/home/soundfm/public_html/ckms-tracklist
logfile=/home/soundfm/logs/getlibretimehistory.log
function writelog () {
# $0 is the current script name
# $$ is the PID of the current shell process
# $* is the complete parameter list
echo $(date "+%FT%T") $0 $$ $* | tee -a "${logfile}" ##### Needs to redirect STDERR too
}
if ! [ -d ${destinationpath} ] ; then
writelog Creating ${destinationpath}
mkdir -vp ${destinationpath} >> ${logfile} 2>&1
errorlevel=${?}
writelog mkdir done, errorlevel= ${errorlevel}
fi
# Calculate datetime for previous hour (convert date to Unix timestamp, subtract 3600 seconds, convert back)
filename=tracklist-$(date -d "@$(($(date +"%s") -3600))" +"%FT%H").json
writelog Start, filename= ${filename}
# wget parameters: Quiet, Output file, URL
wget -q -O ${destinationpath}/${filename} http://libretime.soundfm.ca/api/item-history-feed >> ${logfile} 2>&1
errorlevel=${?}
writelog wget done, errorlevel= ${errorlevel}
# Delete stale files (greater than 62 days)
find ${destinationpath} -mtime +62 -print0 | xargs -0 rm -v >> ${logfile} 2>&1
errorlevel=${?}
writelog find done, errorlevel= ${errorlevel}
writelog Finish
# EOF: getlibretimehistory