#!/usr/bin/env bash #< # Download chant recordings from the monks of Le Barroux Abbey. With no date or # hours given, download all the available hours for today. Files are named # 'YYYY-MM-DD-${hourname}.mp3', where '${hourname}' is 'lauds', 'prime', # 'terce', 'sext', 'none', 'vespers', or 'compline'. # # Usage: barroux [-d ] [...] # barroux -h # # Arguments: # # A combination of an optional date in YYMMDD format and optional hours # given by the first letter of their lowercased names. So '211231ptsn' # would indicate Prime, Terce, Sext, and None for December 31, 2021; # '220417' would indicate all the hours for April 17, 2022; and 'l' would # indicate Lauds for today. # # Options: # -d # Save recordings in instead of in the current directory. # # Commands: # -h # Show this help. # # Version: 1.0.0 (2025). # Written by Renee Margaret McConahy. #> declare -r BASE=https://cdn.barrouxchant.com declare tmp="" quit() { local r=$? trap "" INT QUIT TERM HUP PIPE USR1 USR2 trap - EXIT [[ -n ${1-} ]] && printf "%s\\n" "$1" >&2 [[ -n $tmp ]] && rm -f -- "$tmp" if [[ -n ${1-} ]]; then exit 1; else exit $r; fi } trap quit EXIT trap 'quit "Uncaught error at $(basename -- "$0"):$LINENO"' ERR set -Euo pipefail declare outdir=. while getopts d:h opt; do case $opt in d) outdir=$OPTARG ;; h|*) sed -ne '/^#/ { /^#\(<\|>\)/d; s/^# \?//; p; }' -- "$0" [[ $opt == "?" ]] && exit 1 exit 0 ;; esac done shift $((OPTIND - 1)) [[ -d $outdir ]] || quit "No such directory: ${outdir@Q}." # By default, download all the hours for today. ((!$#)) && set "" for spec; do if [[ ! $spec =~ ^(([0-9]{2})([0-9]{2})([0-9]{2}))?([l|p|t|s|n|v|c]*)$ ]] then echo "Bad arg." continue fi if [[ -n ${BASH_REMATCH[1]} ]]; then date=20${BASH_REMATCH[2]}-${BASH_REMATCH[3]}-${BASH_REMATCH[4]} else date=$(date +%Y-%m-%d) fi hours=${BASH_REMATCH[5]:-lptsnvc} for ((i = 0; i < ${#hours}; i++)); do case ${hours:i:1} in l) hourname=lauds ;; p) hourname=prime ;; t) hourname=terce ;; s) hourname=sext ;; n) hourname=none ;; v) hourname=vespers ;; c) hourname=compline ;; *) quit "Internal error at line $LINENO" esac file=$date-$hourname.mp3 if [[ -f $outdir/$file ]]; then echo "Already have $file." continue fi echo "Getting $file..." tmp=$(mktemp) if curl --disable -L --fail --progress-bar -o "$tmp" "$BASE/$file"; then mv -- "$tmp" "$outdir/$file" else rm -f -- "$tmp" fi tmp="" done done