239 lines
9.8 KiB
Bash
Executable File
239 lines
9.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
|
|
#============================================================
|
|
|
|
echoerr()
|
|
{
|
|
echo "$@" 1>&2;
|
|
}
|
|
|
|
TEMP_DIR="/var/tmp/"
|
|
CHANNELS="1"
|
|
FIXAUDIO="1"
|
|
ARTIST="EMPTY"
|
|
TITLE="EMPTY"
|
|
YEAR="EMPTY"
|
|
SLOT="EMPTY"
|
|
basedir="/var/IA"
|
|
upload_dir="${basedir}/uploads"
|
|
intro="${basedir}/short.flac"
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echoerr "Please enter the source file and episode number"
|
|
exit
|
|
fi
|
|
|
|
mediafile=${1}
|
|
ep_num=${2}
|
|
|
|
ep_num=$(echo $ep_num | sed 's/hpr//g')
|
|
re='^[0-9]+$'
|
|
if ! [[ $ep_num =~ $re ]] ; then
|
|
echoerr "error: episode \"${ep_num}\" is not a number"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "${mediafile}" ]; then
|
|
echoerr "sorry, media file \"${mediafile}\" does not exist"
|
|
exit
|
|
fi
|
|
|
|
if [ ! -r "${mediafile}" ]; then
|
|
echoerr "sorry, media file \"${mediafile}\" is not readable"
|
|
exit
|
|
fi
|
|
|
|
if [ $(ffprobe "${mediafile}" 2>&1 | grep "Audio:" | wc -l ) -eq 0 ]; then
|
|
echoerr "sorry, media file \"${mediafile}\" has no audio track"
|
|
exit
|
|
fi
|
|
|
|
# extract file name and extension
|
|
media_dir=$(dirname ${mediafile})
|
|
fname=${mediafile%.*}
|
|
ext=${mediafile/*./}
|
|
|
|
if [[ -e hpr${ep_num}.wav ]] || [[ -e hpr${ep_num}.mp3 ]] || [[ -e hpr${ep_num}.ogg ]] || [[ -e hpr${ep_num}.spx ]] || [[ -e hpr${ep_num}_summary.wav ]] || [[ -e hpr${ep_num}.wav ]] || [[ -e ${fname}_mez.wav ]] || [[ -e ${fname}_sox_norm.wav ]] || [[ -e ${fname}_mezzanine.wav ]] || [[ -e ${fname}_tmp.pcm ]] || [[ -e ${fname}_tmp.log ]]
|
|
then
|
|
echoerr "Files for this episode already exist."
|
|
ls -1 hpr${ep_num}* ${fname}_* 2>/dev/null
|
|
exit 1
|
|
fi
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Geting metadata for hpr${ep_num}"
|
|
|
|
while read -r line
|
|
do
|
|
field=$(echo $line | awk -F ':' '{print $1}')
|
|
case $field in
|
|
"HPR_summary")
|
|
HPR_summary=$(echo $line | grep "HPR_summary: " | cut -c 14- )
|
|
continue
|
|
;;
|
|
"HPR_album")
|
|
HPR_album=$(echo $line | grep "HPR_album: " | cut -c 12- )
|
|
continue
|
|
;;
|
|
"HPR_artist")
|
|
HPR_artist=$(echo $line | grep "HPR_artist: " | cut -c 13- )
|
|
continue
|
|
;;
|
|
"HPR_comment")
|
|
HPR_comment=$(echo $line | grep "HPR_comment: " | cut -c 14- )
|
|
continue
|
|
;;
|
|
"HPR_genre")
|
|
HPR_genre=$(echo $line | grep "HPR_genre: " | cut -c 12- )
|
|
continue
|
|
;;
|
|
"HPR_title")
|
|
HPR_title=$(echo $line | grep "HPR_title: " | cut -c 12- )
|
|
continue
|
|
;;
|
|
"HPR_track")
|
|
HPR_track=$(echo $line | grep "HPR_track: " | cut -c 12- )
|
|
continue
|
|
;;
|
|
"HPR_year")
|
|
HPR_year=$(echo $line | grep "HPR_year: " | cut -c 11- )
|
|
continue
|
|
;;
|
|
"HPR_duration")
|
|
HPR_duration=$(echo $line | grep "HPR_duration: " | cut -c 15- )
|
|
continue
|
|
;;
|
|
"HPR_explicit")
|
|
HPR_explicit=$(echo $line | grep "HPR_explicit: " | cut -c 15- )
|
|
continue
|
|
;;
|
|
"HPR_license")
|
|
HPR_license=$(echo $line | grep "HPR_license: " | cut -c 14- )
|
|
continue
|
|
;;
|
|
esac
|
|
done < <( wget --timeout=10 --tries=1 --quiet http://hackerpublicradio.org/say.php?id=${ep_num} -O - )
|
|
|
|
if [[ -z "$HPR_album" || -z "$HPR_artist" || -z "$HPR_comment" || -z "$HPR_genre" || -z "$HPR_title" || -z "$HPR_track" || -z "$HPR_year" || -z "$HPR_summary" || -z "$HPR_duration" || -z "$HPR_explicit" || -z "$HPR_license" ]]
|
|
then
|
|
echoerr "Could not find information on ${ep_num}. Has the show been posted ?"
|
|
exit;
|
|
fi
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "album : $HPR_album"
|
|
echo "artist : $HPR_artist"
|
|
echo "comment : $HPR_comment"
|
|
echo "genre : $HPR_genre"
|
|
echo "title : $HPR_title"
|
|
echo "track : $HPR_track"
|
|
echo "year : $HPR_year"
|
|
echo "summary : $HPR_summary"
|
|
echo "duration : $HPR_duration"
|
|
echo "explicit : $HPR_explicit"
|
|
echo "license : $HPR_license"
|
|
|
|
if [[ $HPR_duration == "0" ]]
|
|
then
|
|
echoerr "The duration is set to 0. Please update the show with the correct time."
|
|
exit;
|
|
fi
|
|
|
|
#============================================================
|
|
# Preproc`s the source file
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Prepare mezzanine file"
|
|
ffmpeg -i ${mediafile} -ar 44100 -ac $CHANNELS hpr${ep_num}.wav > ${fname}_tmp.log 2>&1
|
|
|
|
echo "Normalizing the wav files"
|
|
sox --temp "${TEMP_DIR}" --norm hpr${ep_num}.wav hpr${ep_num}_norm.wav
|
|
mv -v hpr${ep_num}_norm.wav ${upload_dir}/hpr${ep_num}.wav >> ${fname}_tmp.log 2>&1
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "File information"
|
|
ffprobe ${upload_dir}/hpr${ep_num}.wav 2>&1 | grep Audio:
|
|
mediainfo ${upload_dir}/hpr${ep_num}.wav
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Convert to opus"
|
|
opusenc ${upload_dir}/hpr${ep_num}.wav ${upload_dir}/hpr${ep_num}.opus 2>> ${fname}_tmp.log 1>&2
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Convert to flac"
|
|
sox --temp "${TEMP_DIR}" -S ${upload_dir}/hpr${ep_num}.wav ${upload_dir}/hpr${ep_num}.flac 2>> ${fname}_tmp.log 1>&2
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Convert to mp3"
|
|
sox --temp "${TEMP_DIR}" -S ${upload_dir}/hpr${ep_num}.wav ${upload_dir}/hpr${ep_num}.mp3 2>> ${fname}_tmp.log 1>&2
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Convert to ogg"
|
|
sox --temp "${TEMP_DIR}" -S ${upload_dir}/hpr${ep_num}.wav ${upload_dir}/hpr${ep_num}.ogg 2>> ${fname}_tmp.log 1>&2
|
|
|
|
echo "--------------------------------------------------------------------------------"
|
|
echo "Convert to spx"
|
|
sox --temp "${TEMP_DIR}" -S ${upload_dir}/hpr${ep_num}.wav -c 1 -r 16000 -t wav - | speexenc - ${upload_dir}/hpr${ep_num}.spx 2>> ${fname}_tmp.log 1>&2
|
|
|
|
if [[ ! -s ${upload_dir}/hpr${ep_num}.wav ]] || [[ ! -s ${upload_dir}/hpr${ep_num}.opus ]] || [[ ! -s ${upload_dir}/hpr${ep_num}.flac ]] || [[ ! -s ${upload_dir}/hpr${ep_num}.mp3 ]] || [[ ! -s ${upload_dir}/hpr${ep_num}.ogg ]] || [[ ! -s ${upload_dir}/hpr${ep_num}.spx ]]
|
|
then
|
|
echoerr "ERROR: Something went wrong encoding the files"
|
|
exit 1
|
|
fi
|
|
|
|
fix_tags -album="$HPR_album" -artist="$HPR_artist" -comment="${HPR_comment} The license is ${HPR_license}" -genre="$HPR_genre" -title="$HPR_title" -track="$HPR_track" -year="$HPR_year" ${upload_dir}/hpr${ep_num}* 2>> ${fname}_tmp.log 1>&2
|
|
|
|
fix_tags ${upload_dir}/hpr${ep_num}*
|
|
|
|
#echo "Changing the file dates to the time of upload"
|
|
touch -r ${mediafile} hpr${ep_num}*
|
|
touch -r ${mediafile} ${upload_dir}/hpr${ep_num}*
|
|
|
|
ls -al hpr${ep_num}* ${upload_dir}/hpr${ep_num}*
|
|
|
|
rsync -ave ssh --partial --progress --ignore-existing ${upload_dir}/hpr${ep_num}.mp3 ${upload_dir}/hpr${ep_num}.ogg ${upload_dir}/hpr${ep_num}.spx hpr:www/eps/
|
|
|
|
firefox http://hackerpublicradio.org/local/hpr${ep_num}.mp3
|
|
firefox http://hackerpublicradio.org/local/hpr${ep_num}.ogg
|
|
firefox file://${upload_dir}/hpr${ep_num}.mp3
|
|
firefox file://${upload_dir}/hpr${ep_num}.ogg
|
|
mpv "http://hackerpublicradio.org/local/hpr${ep_num}.spx" "http://hackerpublicradio.org/local/hpr${ep_num}.ogg" "http://hackerpublicradio.org/local/hpr${ep_num}.mp3" "file://${upload_dir}/hpr${ep_num}.spx" "file://${upload_dir}/hpr${ep_num}.opus" "file://${upload_dir}/hpr${ep_num}.ogg" "file://${upload_dir}/hpr${ep_num}.mp3" "file://${upload_dir}/hpr${ep_num}.flac"
|
|
|
|
echo "Source: $( mediainfo --Output=XML --Full "${mediafile}" | xmlstarlet sel -T -t -m '/_:MediaInfo/_:media/_:track[@type="Audio"]' -v '_:Duration' -n | awk -F '.' '{print $1}' )"
|
|
mediainfo --Output=XML --Full hpr${ep_num}* ${upload_dir}/hpr${ep_num}* | xmlstarlet sel -T -t -m '/_:MediaInfo/_:media/_:track[@type="Audio"]' -v '_:Duration' -n | awk -F '.' '{print $1}' | sort | uniq -c
|
|
|
|
read -p "Remove files for \"${fname}\" (y|N) ? " -n 1 -r
|
|
echo # (optional) move to a new line
|
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
then
|
|
mediafilename=$(basename "${mediafile}")
|
|
mediaextension="${mediafilename##*.}"
|
|
|
|
ssh hpr -t "mkdir /home/hpr/www/eps/hpr${ep_num}" >/dev/null 2>&1
|
|
rsync -ave ssh --partial --progress --ignore-existing "${mediafile}" hpr:www/eps/hpr${ep_num}/hpr${ep_num}_source.${mediaextension}
|
|
ssh hpr -t "ls -al /home/hpr/www/eps/hpr${ep_num}*"
|
|
cp -v "${mediafile}" "${upload_dir}/hpr${ep_num}_source.${mediaextension}"
|
|
|
|
#echo "Remove temp files"
|
|
rm -v ${fname}_mezzanine.wav ${fname}_tmp*.pcm ${fname}_tmp.log ${fname}_mez.wav
|
|
mv -v ${fname}* hpr${ep_num}* *_${ep_num}_* /var/IA/done/
|
|
wget --timeout=0 -q "http://hackerpublicradio.org/hpr_ogg_rss.php?gomax=1" -O - | xmlstarlet val --err -
|
|
wget --timeout=0 -q "http://hackerpublicradio.org/hpr_mp3_rss.php?gomax=1" -O - | xmlstarlet val --err -
|
|
wget --timeout=0 -q "http://hackerpublicradio.org/hpr_spx_rss.php?gomax=1" -O - | xmlstarlet val --err -
|
|
wget --timeout=0 -q "http://hackerpublicradio.org/rss-future.php" -O - | xmlstarlet val --err -
|
|
|
|
#rsync -ave ssh --partial --progress ${upload_dir}/ hpr:/home/hpr/upload/processed/
|
|
rsync -ave ssh --partial --progress ${upload_dir}/ borg:/data/IA/uploads/
|
|
echo "$( ssh borg -t "ls -al /data/IA/uploads/hpr${ep_num}*" ; ls -al ${upload_dir}/hpr${ep_num}* )" | grep "hpr${ep_num}" | awk '{print $5, $NF}' | sort
|
|
find /var/IA/done/ -empty -delete
|
|
else
|
|
echo "skipping...."
|
|
echo "cp -v \"${mediafile}\" \"${upload_dir}/hpr${ep_num}_source.${mediaextension}\""
|
|
echo "rm -v ${fname}_mezzanine.wav ${fname}_tmp*.pcm ${fname}_tmp.log ${fname}_mez.wav"
|
|
echo "mv -v ${fname}* hpr${ep_num}* *_${ep_num}_* /var/IA/done/"
|
|
echo "wget --timeout=0 -q \"http://hackerpublicradio.org/hpr_ogg_rss.php?gomax=1\" -O - | xmlstarlet val --err -"
|
|
echo "wget --timeout=0 -q \"http://hackerpublicradio.org/hpr_mp3_rss.php?gomax=1\" -O - | xmlstarlet val --err -"
|
|
echo "wget --timeout=0 -q \"http://hackerpublicradio.org/hpr_spx_rss.php?gomax=1\" -O - | xmlstarlet val --err -"
|
|
echo "rsync -ave ssh --partial --progress ${upload_dir}/ borg:/data/IA/uploads/"
|
|
fi
|