#!/bin/bash ## Repeatedly choose (without replacement) a random radio station to ## play. The list of stations comes from the Internode. NOTE: when ## run from outside Internode, you will only get access to community ## radio stations (e.g. 3KND but not SKY.fm). ## ## Use mpg321 keys to switch channel (f/d) and quit (q). # NOTE: mpg123 has --title, which works in screen if you lie to mpg123 # and tell it that TERM=xterm or TERM=rxvt. However for this case it # is useless, as it prints the filename, not any kind of ID3 or ICY # info, and as a result all you see in the hardstatus is "4" or "24" # or whatever the last part of the URL is. none=(cat) shit=(grep -vE # By station -e "Absolute Radio|Triple M|Nova|Fox FM|Mix 94.5" -e "Triple J|Joy|Life|Swissgroove|Greek|Italiana" -e "Dogglounge|Newstalk" # By region -e "Adelaide|Brisbane|Canberra|Darwin|Perth|Sydney" -e "Hobart|Coast|Newcastle|Territory" # By genre -e "80's|80s|90s|Hitz|Hits|Jamz|Love|Christian|Country" -e "Bebop|Smooth|Bossa|Salsa|New Age|Grandstand|Sport" -e "Dance|House|Trance|Eurodance|Club|Industrial|Hardcore" -e "Ambient|Drone|Minimal|Chillout|Space|Mission Control" ) good=(grep -E # By station -e "PBS|Triple R|Three D|RTR FM|Radio Paradise|KCEA" -e "BBC World Service|ABC Classic|ABC Dig|Thistle" # By genre -e "70s|Oldies|Blues|New Orleans|Reggae|Ska|Dubstep" -e "American Songbook|Jazz Classics|Classic Rap" -e "Indie|Chiptunes|Illinois Street Lounge" -e "Beatles|Soundtracks|Lush|Seven Inch Soul" # Removed because it breaks my audio, even after changing station. #-e "Megarock" # Avoids "Absolute Classic Rock" and "Classic Rock 9x.y (City)". -e "Sky.FM - Classic Rock" ) norip=(grep -vE # no track IDs, or AAC (not MP3) -e 'ABC Classic|BBC|Dubstep.FM|New Orleans|WGLT' -e 'RTR|Three D|Triple R' ) rmjunk () { # Array is here so globs aren't expanded to early. junk=( # My PMP can only play MP3s. */*.aac # Incomplete tracks. */incomplete/* # Known advertising tracks. */*' - '{,-,BRUK?ID??,Lenco_*,*TargetSpot,Commercial}.mp3 */*' - '{Artist?Drop,Owned?And?Operated?ID}.mp3 */{CHX,CRX,CXR,ChroniX?Radio,Jay?Shields,Lenco_*_*}' - '*.mp3 */{Radio?Paradise,Sky.fm,SomaFM,Blues?Radio?UK}' - '*.mp3 */{OTR?Theme,JAM}' - '*.mp3 */Station?Ids' - '*.mp3 */*' - '*Station?ID*.mp3 */' - '*Promo.mp3 */' - 'AA[0-9]+' '*.mp3 */' - - '*Advert*.mp3 */' - Advert: '.mp3 */*{BU4B,BellyUp4Blues,Belly?Up?4?Blues}*.mp3 'GLT Blues Radio'/{' - ',}{BST,LIN,VTK,LUA,PRO,GEN}' '*.mp3 KCEA-FM*/'Dave - '*.mp3 *SomaFM*/*Somafm*.mp3 Punk*/*' - Commercial'.mp3 ) rm -vf "${junk[@]}" # Tidy up by removing any empty station folders. rmdir */incomplete/ 2>/dev/null || : rmdir */ 2>/dev/null || : } ###################################################################### set -eEu set -o pipefail trap 'echo >&2 "${0##*/}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): } unknown error"' ERR # Default settings. filter=shit[@] mode=listen jobs=8 duration=4h # CLI options override the defaults. while getopts gasplfj:d: opt do case "$opt" in g) filter=good[@];; # good only a) filter=none[@];; # all (good/okay/shit) s) filter=shit[@];; # no shit (good/okay only) p) mode=print;; l) mode=listen;; f) mode=fetch;; j) jobs=$OPTARG;; # how many stations to rip at once d) duration=$OPTARG;; # how long to rip each station for '?') exit 1;; esac done shift $((${OPTIND:-1}-1)) # If there are still arguments on the command line, the user wants to # play specific stations -- so do that instead. ((0 == $#)) || filter=this[@] this=(grep -iE "$@") # Actually get the station list and prune out undesirable entries. data=$(curl -sSf http://freezone.internode.on.net/freezone-radio-playlist.list | "${!filter}") # Do something with the result. case $mode in print) column -ts= <<<"$data";; listen) mpg123 -pnone -C --shuffle -@ <(cut -d= -f2 <<<"$data");; fetch) # Mount my PMP. grep -q /srv/music /proc/mounts || mount /srv/music cd /srv/music/Radio rmjunk # Useful when the last run ENOSPC'd. # Rip several stations concurrently. sort -R <<< "$data" | "${norip[@]}" | xargs -d\\n -n1 -P$jobs timeout $duration \ sh -c 'echo "${0%=*}"; exec streamripper "${0#*=}" -d . -o never --xs2' || : # To kill off streamrippers that aren't naming tracks, try this: # pgrep streamripper | while read i; do lsof -p "$i" | grep -qF '/ - .mp3' && kill "$i"; done rmjunk # ENOSPC will prevent this running. ;; esac