Play ARNewsline direct as MP3 and automate *HOWTO*

Some background to many of my scripts and workarounds.

app_rpt is like a walled garden.
It forces limitations sometimes that are necessary for local node and network integrity.

Riding on asterisk, which is very very powerful, sometimes our software seemingly limits what we do in lessor than asterisk capability.

I have spent more than a decade working around these barriers to get what I wanted or needed and increasing my systems capabilities. I would call it ‘adding some windows to that walled garden’. And have begun to share some of these to help others where I can and have time to do where they are not to complex and do not require me to write a long HOWTO.

So first, speaking on this one, I do not do this and almost do not agree with it to some extents, but it is a good example of work-around for increased capability. At least take some of the concepts forward for making things better and be thoughtful to what you are doing and not make a mess of our network or hobby.

While app_rpt has a hard time making use of MP3 format files, Asterisk has provisions for it and easily handles it. So the problem is how to create a bridge to asterisk to make use of the full flavor of asterisk.

Keep in mind, with asterisk, there is always more than one way to do anything. I will demonstrate just one here for our task of playing native MP3 format files on our nodes with ease. Using a popular playback of ARNewsline for example.

2 requirements before you start.
1st install mpg123
apt-get install mpg123

and 2nd, in modules.conf this line will need to be enabled.

load => app_mp3.so ; Silly MP3 Application

The player will be a extension in a special stanza we will call media-player
So in extensions.conf, place this outside of existing stanzas

[media-player]
exten => 600,1,Answer()
exten => 600,2,MP3Player(/etc/asterisk/media/arnews.mp3) ; arnews player
exten => 600,3,Hangup

Save, exit and open rpt.conf and place the following where it makes sense to you. Make the command your own and non-conflicting to other commands in your system.

8909=autopatchup,context=media-player,noct=1,farenddisconnect=1,dialtime=25000,quiet=1,exten=600

save, exit

This command basically makes a quite phone patch to ext 600 in our separate stanza of ‘media player’ where we can easily run our asterisk MP3Player and play our file back to the dialing node.

To cancel the playback midstream, just hang-up the patch
So use whatever you have programmed for hang-up
0=autopatchdn ; Autopatch down, some may be using 60/61

Now for ARNewsline playback, I took a moment to write a automated script, but it is unpolished.
Read all the notes in the file! My script is named arnews.sh and I place my scripts in /etc/asterisk/myscripts
And the process uses /etc/asterisk/media to hold files for this.
Keeping all config stuff in sub-directories of asterisk makes for a convenient back-up.
More explanation is in the file. Read all comments.

I have updated this to be a bit more straight forward but still could be better if you want to publish something here.

////////////////////////////////////////////////////////////////////////////////////
#!/bin/bash

#arnewsline automatic mp3 downloader and rotation - m.mays kb8jnm

#READ ALL THE COMMENTS SO YOU KNOW WHAT IS GOING ON - I will not support the script, you are on your own.
#This is a script to build on. Not a polished product. The script only automates the download with the latest. You still need to macro/sched your playback as needed.

#For first time use, find the report number from ar news website
#Mouse hover on the link from AR newsline website to see it.

#put this number in the arnews.txt file or use the number
#touch /etc/asterisk/media/arnews.txt -to create the file.
#edit the file and insert only the one line of the broadcast number only ie 2374

#Make it work ‘as is’ before you make custom changes
#Depending on your exact setup, you may need to check/change ownership and permissions of files created.

bnum=$(head -n 1 /etc/asterisk/media/arnews.txt) # read the current broadcast number from file

while [ -f /etc/asterisk/media/Report$bnum.mp3 ]
do
bnum=$((bnum+1)) # increment the number for next
echo $bnum > /etc/asterisk/media/arnews.txt # write the next number broadcast to file for next

done
if [ ! -f /etc/asterisk/media/Report$bnum.mp3 ]
then

wget -P /etc/asterisk/media/ https://www.arnewsline.org/s/Report$bnum.mp3 # download the latest not downloaded
cp /etc/asterisk/media/Report$bnum.mp3 /etc/asterisk/media/arnews.mp3 # change the name for generic loading for player
bnum=$((bnum+1)) # increment the number for next
echo $bnum > /etc/asterisk/media/arnews.txt # write the next number broadcast to file for next

dnum=$((bnum-3)) # create a number to delete report 3 broadcasts ago
rm /etc/asterisk/media/Report$dnum.mp3 # delete older report

fi

#You may want to run this manually a few times to be sure you are up to date before allowing sched/macro use.

#The script will need to be run from macro / scheduler to be automatic once a week just after ar newsline is updated (I don’t know when this happens)

#Then you can macro /sched your playback time and nodes as well.

#NOTE: as is, the file is to long for the average time-out setting so you will need to temporarily extend or disable it for playback.

People may be interested in this: Allstar Amateur Radio Newsline Player | MFamily