sanitization, doc updates, push right repo

master
Jay 2 years ago
parent 2da8430d52
commit 8c13993308

@ -1,38 +1,19 @@
# Asterisk Jukebox & "Tape Cartridge" Player # ajw - Asteisk Jukebox Wizard
Asterisk Jukebox & "Tape Cartridge" Player is a pair of scripts that provides Builds a dialplan to make Asterisk function as a jukebox.
a jukebox like interface for playing songs/albums stored on the server, as well
as logic to perform this playback.
## About
Asterisk Jukebox & Player consist of two basic dialplans:
- a common set of logic for playback called from a jukebox interface
- a jukebox interface dialplan for music/album selection
There is no reason you cannot use the player outside of a jukebox, provided you
set all the variables and call the proper extensions in it's context.
tapecart-player.conf is provided as it's own .conf file. It should go without ## About
saying you only need to include this file in your extensions.conf. If you run a
big flat extensions.conf, then you probably already know to copy/paste it in.
Tracks are selected using a 4-digit code that consists of album number and An Asterisk Jukebox is a IVR that mimics the function of a CD jukebox. It
track number. Track "00" is special and will play the full album from the currently supports playing single tracks or full albums. Selections are made
beginning. During album playback; repeat, skip, and back controls are using a 4 digit code; album number and track number. Basic playback controls
provided. Pressing "0" will also take you back to the main menu. are available during album play to skip back, ahead, and repeat track.
Playback logic uses internal counters to request files. This requires your ## Requirements
files contain ONLY a track number, with or without leading zero. Only two
digits for a maximum of 99 tracks are supported. Playback logic's context is
called using extension pattern matching which dictates leading zero behavior
and passes some album information.
A related project, ajw - asterisk jukebox wizard, provides a bash script that You will need to have the `func_volume.so` and `func_logic.so` loaded in order
creates the jukebox interface for you. to use Asterisk Jukebox. Add these to `modules.conf`
## How To Use/Setup ## How To Use/Setup
@ -41,48 +22,68 @@ each album is it's own folder, all filenames are track numbers, and the jukebox
folder lives in Asterisk's sounds directory. folder lives in Asterisk's sounds directory.
``` ```
/var/lib/asterisk/sounds/en/jukeboxroot/album/[(0)1-99].ulaw /var/lib/asterisk/sounds/en/(optional-subfolder)/jukeboxroot/album/[(0)1-99].ulaw
``` ```
Include tapecart-player.conf (or tryinclude), or it's contents, in to your The 1.0 update to jaw sees it become ajw. The difference is that ajw now makes
extensions.conf. dialplans that do not include playback logic. This is now a seperate file.
tapecart-player.conf provides two contexts:
- [cart-player] - provides single track playback You no longer tell it how many albums you have, how many folders, or tracks.
- [8track-player] - provides album playback The script now automatically does all of this; and as a result, albums are added
in directory list order. If you want a specific order, prefix your folder names.
For both contexts, the following variables will need to be set before sending a The automatic nature of the script does require your folder/files to already be
channel to them: in place. By default, the script looks in `/var/lib/asterisk/sounds/en` for what
you specify to be the jukebox root. If they are one directory deeper in your
default sounds; you can specify that in the configuration. Example:
- c - the context you are sending from (used for returning from player) `/var/lib/asterisk/sounds/en/jukeboxroot/albums` - All jukeboxes live in $asd
- aa - the path relative to your asterisk sounds directory your files live. `/var/lib/asterisk/sounds/en/astjuke/jukeboxroot/albums` - Jukebox roots live
under another folder
Both contexts use pattern matching extensions to select behavior as well as You can modify the location of your Asterisk Sounds directory by modifying the
pass information. `asd=` line at the beginning of the script.
[cart-player] Once the files are in place and you have read access, run the script and answer
the prompts:
``` ```
#X - with X being 1 - 9 for files without leading zeros "Pick a name/identifier for this jukebox:" - name used for dialplan context
*XX - with XX being all tracks > 10 or with leading zeros
"Enter the folder your jukebox roots live under:" - if your roots live under another
folder (because network mount/symlink), enter it here. Blank means no addtional path.
"Enter the root folder name of your jukebox:" - folder in sounds that contain
all your albums
"Enter the filename of your menu/intro:" - name of file played when answered.
lives in juke root.
"How many times do you want it to play?" - how many times to play the intro
before hanging up
"How many seconds between intro play?" - how many seconds between intro
playback
"Enter the filename of your exit file:" - name of file played before hangup.
lives in juke root.
"Enter A Channel Volume:" - Tell the Volume function to set a volume. Defaults to -3
``` ```
[8track-player] The script now automatically enumerates sub-folders, counts tracks, determines
leading zero, and writes the appropiate dialplan. You must prefix your folders
with numbers if you want to ensure they are a specific order.
Make sure the conf file is included in your extensions.conf somehow; the same
for tapecart-player.conf.
``` ```
#XX - with XX being the number of tracks plus one. files without leading 0. [globals]
*XX - with XX being the same as above, but files with leading 0. #include $name-juke.conf
``` ```
The idea is to keep the 4-digit leading zero code compatible with files that
don't have leading zeros. Originally I just forced leading zeros. But,
naturally; setting a variable to "01" and adding one to it results in "2",
which is not equal to "02" and causes playback to fail. Some of the logic for
cart-player is done at the jukebox dialplan for dealing with lack of leading
zeros; because sometimes you EXTEN:-2 and sometimes you want to EXTEN:-1.
The ajw.sh script will generate the configuration dialplans for you.
Then it's just a matter of directing a call to it's context (usually s,$name-juke).
## Using The Jukebox ## Using The Jukebox
@ -111,20 +112,72 @@ pressing 0.
# History # History
``` ```
14-AUG-2022: Fix cartplayer extension fallthrough. Add HOWTHISWORKS.MD. Added ajw.sh 21-SEP-2022 - Add subfolder option - track sanitization for cart-player
06-MAY-2022: Update Readme. Add conf/examples. 14-AUG-2022 - Fixed missed (goodbye) label in setup context.
05-MAY-2022: Initial Commit to self-hosted git. 12-AUG-2022 - Doesn't write delay if you set Delay to 0.
11-MAY-2022 - Fatal error in accidently escaped character fixed.
07-MAY-2022 - Initial Commit
```
# Explanation of Generated Dialplan
The dialplan has undergone some extensive changes since last update. The
use of While has been eliminated as it caused some problems. The way some
things are done have been drastically changed (hopefully for the better). Some
of this was necessitated by the wizard; some of it was in spite of the wizard.
``` ```
[examplejuke-main]
exten = s,1,Answer()
same = n,Set(VOLUME(TX)=-3)
same = n,Set(c=examplejuke-main)
same = n(loop),Background(foobar/menu)
same = n,WaitExten(5)
same = n,Set(m=$[${m} + 1])
same = n,GoToIf($["${m}" < "5"]?loop)
same = n(goodbye),Background(foobar/bye)
same = n,Hangup()
# Explanation of Operation ```
A full breakdown is in HOWTHISWORKS.MD After being answered, we set not just the channel volume but the context name.
Most of this is just looping the intro.
```
exten = _00XX,1,Set(aa=foobar/00album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*11,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)
exten = _01XX,1,Set(aa=foobar/01album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*15,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)
exten = _02XX,1,Set(aa=foobar/02album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,#12,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoToIf($["${EXTEN:-2}" < "10"]?cart-player,#${EXTEN:-1},1) ; these files don't have a leading zero
same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)
```
We no longer write the last two of the extension to a variable, we just call it
directly from now on. We also now use that as the extension we dial in the
single playback routine. We call either an extension starting with # or *
depending on the leading zero situation. AJW handles writing all of this.
A full explanation of how the jukebox works, including explanation of
tapecart-player.conf is at the repository:
https://git.pickmy.org/dewdude/Asterisk_Jukebox/src/master/HOWITWORKS.MD
# License # License
Asterisk Jukebox ajw - Asterisk Jukebox Wizard
Copyright (C) 2022 Jay Moore - nq4tango@gmail.com Copyright (C) 2022 Jay Moore - nq4tango@gmail.com
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

@ -1,51 +1,68 @@
#!/bin/bash #!/bin/bash
#ajw v1.02 - jukebox for asterisk wizard #ajw v1.10 - jukebox for asterisk wizard
#Jay Moore/NQ4T - https://git.pickmy.org/dewdude/ajw #Jay Moore/NQ4T - https://git.pickmy.org/dewdude/ajw
#Twitter: @Music_OnHold #Twitter: @Music_OnHold
#Licensed under GPL-3.0-or-later #Licensed under GPL-3.0-or-later
# Works like this: # Works like this:
# Put all your albums in your Asterisk sounds directory: /jukebox root/album/track#.ulaw # Put all your albums in your Asterisk sounds directory: /var/lib/asterisk/sounds/en/(jukeboxesdir)/jukebox root/album/track#.ulaw
# Run script, enter prompts. # Run script, enter prompts. (jukeboxesdir) is an optional sub-folder in case your jukeboxes are in a extra subdirectory
# Copy .conf, include in extensions.conf, assign extension. # Copy .conf, include in extensions.conf, assign extension.
# asd defines the default location of your asterisk sounds
asd=/var/lib/asterisk/sounds/en/
# main context configuation
setup() { setup() {
printf "[$name-main]\nexten = s,1,Answer()\nsame =n,Set(VOLUME(TX)=$vol)\nsame = n,Set(c=$name-main)\nsame = n(return),Set(m=1)\nsame = n(loop),Background($rootfolder/$introfile)\n" printf "[$name-main]\nexten = s,1,Answer()\nsame =n,Set(VOLUME(TX)=$vol)\nsame = n,Set(c=$name-main)\nsame = n(return),Set(m=1)\nsame = n(loop),Background($rootfolder/$introfile)\n"
[ "$delay" -ne 0 ] printf "same = n,WaitExten($delay)\n" [ -n "$delay" ] && printf "same = n,WaitExten($delay)\n"
printf "same = n,Set(m=\$[\${m} + 1])\nsame = n,GoToIf(\$[\"\${m}\" > \"$loop\"]?loop)\nsame = n(goodbye),Background($rootfolder/$goodbye)\nsame = n,Hangup()\n\n" printf "same = n,Set(m=\$[\${m} + 1])\nsame = n,GoToIf(\$[\"\${m}\" > \"$loop\"]?loop)\nsame = n(goodbye),Background($rootfolder/$goodbye)\nsame = n,Hangup()\n\n"
} >> $name-juke.conf } >> $name-juke.conf
# album selections
album() { album() {
printf "exten = _%02dXX,1,Set(aa=$rootfolder/$folder)\n" $a printf "exten = _%02dXX,1,Set(aa=$rootfolder/$folder)\n" $a
[ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,#$tc,1)\n" || printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,*$tc,1)\n" [ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,#$tc,1)\n" || printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,*$tc,1)\n"
printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" > \"$limit\"]?9999)\n"
[ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" < \"10\"]?cart-player,#\${EXTEN:-1},1)\n" [ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" < \"10\"]?cart-player,#\${EXTEN:-1},1)\n"
printf "same = n,GoTo(cart-player,*\${EXTEN:-2},1)\n\n" printf "same = n,GoTo(cart-player,*\${EXTEN:-2},1)\nsame = 9999,Playback(option-is-invalid)\nsame =n,GoTo($name-main,s,1)\n\n"
} >> $name-juke.conf } >> $name-juke.conf
printf "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |a|j|w| - asterisk jukebox wizard\n version 1.02 - Jay Moore/NQ4T\n https://git.pickmy.org/dewdude/jaw\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n\n" # main
printf "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |a|j|w| - asterisk jukebox wizard\n version 1.10 - Jay Moore/NQ4T\n https://git.pickmy.org/dewdude/jaw\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n\n"
printf "Pick a name/identifier for this jukebox: " printf "Pick a name/identifier for this jukebox: "
read name read name
printf "\nEnter the root folder name of your jukebox: " printf "\nEnter the folder your jukebox roots live under. (Leave blank if they're under $ast): "
read sd
printf "\nEnter the name of the root folder your jukebox albums live under: "
read rootfolder read rootfolder
printf "\nEnter the filename of your menu/intro: " printf "\nEnter the filename of your menu/intro: "
read introfile read introfile
printf "\nHow many times do you want it to play? " printf "\nHow many times do you want it to play? "
read loop read loop
printf "\nHow many seconds between intro play? (Enter 0 for no delay)" printf "\nHow many seconds between intro play? (Leave blank for no delay): "
read delay read delay
printf "\nEnter the filename of your exit file: " printf "\nEnter the filename of your exit file: "
read goodbye read goodbye
printf "\nEnter a channel volume (I recommend -3): " printf "\nEnter a channel volume. (I recommend -3, also the default if you leave this blank): "
read vol read vol
[ -n "$vol" ] && vol="-3"
printf "\nWriting Basic Configuration.\n\nAuto-Generating Albums\n\n" printf "\nWriting Basic Configuration.\n\nAuto-Generating Albums\n\n"
[ -n "$sd" ] && rootfolder=$sd/$rootfolder
setup; setup;
asd=/var/lib/asterisk/sounds/en/astjuke
# album context loop
dir=$(ls $asd/$rootfolder -l | awk '/^d/ {print $9}') dir=$(ls $asd/$rootfolder -l | awk '/^d/ {print $9}')
a=0 a=0
for folder in $dir for folder in $dir
do do
tracks=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | wc -l) limit=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | wc -l)
tracks=$((tracks + 1)) tracks=$((limit + 1))
tc=$(printf "%02d" $tracks) tc=$(printf "%02d" $tracks)
ld=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | awk '{print $9}' | awk '/^0/') ld=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | awk '{print $9}' | awk '/^0/')
[ -z "$ld" ] && lz=0 || lz=1 [ -z "$ld" ] && lz=0 || lz=1

@ -1,23 +1,32 @@
[examplejuke-main] [examplejuke-main]
exten = s,1,Answer() exten = s,1,Answer()
same =n,Set(VOLUME(TX)=-3) same = n,Set(VOLUME(TX)=-3)
same = n,Set(c=examplejuke-main) same = n,Set(c=examplejuke-main)
same = n(loop),Background(foobar/menu) same = n(loop),Background(foobar/menu)
same = n,WaitExten(5) same = n,WaitExten(5)
same = n,Set(m=$[${m} + 1]) same = n,Set(m=$[${m} + 1])
same = n,GoToIf($["${m}" < "5"]?loop) same = n,GoToIf($["${m}" < "5"]?loop)
same = n,Background(foobar/bye) same = n(goodbye),Background(foobar/bye)
same = n,Hangup() same = n,Hangup()
exten = _00XX,1,Set(aa=foobar/00album) exten = _00XX,1,Set(aa=foobar/00album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*11,1) same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*11,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoTo(cart-player,*${EXTEN:-2},1) same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)
exten = _01XX,1,Set(aa=foobar/01album) exten = _01XX,1,Set(aa=foobar/01album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*15,1) same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,*15,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoTo(cart-player,*${EXTEN:-2},1) same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)
exten = _02XX,1,Set(aa=foobar/02album) exten = _02XX,1,Set(aa=foobar/02album)
same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,#12,1) same = n,GoToIf($["${EXTEN:-2}" = "00"]?8track-player,#12,1)
same = n,GoToIf($["${EXTEN:-2}" > "19"]?9999)
same = n,GoToIf($["${EXTEN:-2}" < "10"]?cart-player,#${EXTEN:-1},1) ; these files don't have a leading zero same = n,GoToIf($["${EXTEN:-2}" < "10"]?cart-player,#${EXTEN:-1},1) ; these files don't have a leading zero
same = n,GoTo(cart-player,*${EXTEN:-2},1) same = n,GoTo(cart-player,*${EXTEN:-2},1)
same = 9999,Playback(option-is-invalid)
same = n,GoTo(examplejuke-main,s,1)

@ -1,20 +1,11 @@
;tapeplayer.conf - Asterisk Jukebox - Version 1.something
;Jay Moore - NQ4T - Twitter: @Music_OnHold
;https://git.pickmy.org/dewdude/Asterisk_Jukebox
;https://git.pickmy.org/dewdude/ajw
[cart-player] [cart-player]
exten = _#X,1,Wait(.25) exten = _#X,1,Wait(.25)
same = n,Set(z=${EXTEN}) same= n,Background(${aa}/${EXTEN:-1})
same= n(replay),Background(${aa}/${EXTEN:-1})
same = n,Goto(${c},s,return) same = n,Goto(${c},s,return)
exten = _*XX,1,Wait(.25) exten = _*XX,1,Wait(.25)
same = n,Set(z=${EXTEN})
same= n,Background(${aa}/${EXTEN:-2}) same= n,Background(${aa}/${EXTEN:-2})
same = n,Goto(${c},s,return) same = n,Goto(${c},s,return)
exten = i,1,Goto(${c},s,return) exten = 0,1,Goto(${c},s,return)
exten = 2,1,Goto(cart-player,${z},1)
[8track-player] [8track-player]
exten = _*XX,1,Set(tt=${IF($[${EXTEN:-2} < 10]?${EXTEN:-1}:${EXTEN:-2})}) exten = _*XX,1,Set(tt=${IF($[${EXTEN:-2} < 10]?${EXTEN:-1}:${EXTEN:-2})})

Loading…
Cancel
Save