2023-11-17_10-51-19Z_Friday

This commit is contained in:
Ken Fallon 2023-11-17 11:51:19 +01:00
parent c038e3c10a
commit 261398e09f
2 changed files with 677 additions and 0 deletions

425
bin/hprtranscode.bash Executable file
View File

@ -0,0 +1,425 @@
#!/bin/bash
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
#============================================================
# Check input
usage="usage: $(basename $0 ) [ -i ] [ -o ] <fname>, -i to add intro and -o outro, fname is a file with audio for HPR"
# Argument = -t test -r server -p password -v
echoerr()
{
echo "$@" 1>&2;
}
usage()
{
cat << EOF
usage: $0 [options] {media file to encode} {episode number}
OPTIONS:
-h Show this message
-p add a promo
-i add the intro
-s Automatically generate the summary
-o add the outro
-b add the intro and outro ( and summary default)
-2 encode to 2 channels
-n no audio normalization
-x eXclude sponsor mention
EOF
}
TEMP_DIR="/var/tmp/"
CHANNELS="1"
FIXAUDIO="1"
ADDSUMMARY="n"
ADDINTRO="n"
ADDPROMO="n"
ADDOUTRO="n"
ADDSPONSOR="y"
ARTIST="EMPTY"
TITLE="EMPTY"
YEAR="EMPTY"
SLOT="EMPTY"
basedir="/var/IA"
intro="${basedir}/intro.flac"
promo="${basedir}/promo.flac"
outro="${basedir}/outro.flac"
anhonesthost="${basedir}/sponsor-anhonesthost.com-hpr15.flac"
internetarchive="${basedir}/sponsor-archive.org.flac"
while getopts "hipsob2nx" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
s)
ADDSUMMARY="y"
;;
i)
ADDINTRO="y"
;;
p)
ADDPROMO="y"
;;
o)
ADDOUTRO="y"
;;
b)
ADDINTRO="y"
ADDOUTRO="y"
;;
2)
CHANNELS="2"
;;
n)
FIXAUDIO="0"
;;
x)
ADDSPONSOR="n"
;;
?)
usage
exit
;;
esac
done
shift $(($OPTIND - 1))
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 "${anhonesthost}" ]; then
echoerr "sorry, file \"${anhonesthost}\" does not exist"
exit 1
fi
if [ ! -f "${internetarchive}" ]; then
echoerr "sorry, file \"${internetarchive}\" does not exist"
exit 1
fi
if [ ! -f "${intro}" ]; then
echoerr "sorry, file \"intro.flac\" does not exist"
exit 1
fi
if [ "$ADDPROMO" = 'y' ]; then
if [ ! -f "${promo}" ]; then
echoerr "sorry, file \"promo.flac\" does not exist"
exit 1
fi
fi
if [ ! -f "${outro}" ]; then
echoerr "sorry, file \"outro.flac\" does not exist"
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 [ "$ADDSUMMARY" = 'n' ]; then
if [ ! -e "${media_dir}/summary.wav" ]
then
echoerr "ERROR: Can not find the summary file \"${media_dir}/summary.wav\""
wget -O- --timeout=10 --tries=1 --quiet http://hackerpublicradio.org/say.php?id=${ep_num} | grep HPR_summary
exit 1
fi
fi
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 ${fname}_mez_norm.wav ]] || [[ -e ${fname}_mez.wav ]] || [[ -e ${fname}_sox_norm.wav ]] || [[ -e ${fname}_sox.wav ]] || [[ -e ${fname}_tmp_hh.pcm ]] || [[ -e ${fname}_tmp_ia.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 "$ADDINTRO" || -z "$ADDPROMO" || -z "$ADDSUMMARY" || -z "$ADDOUTRO" || -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 "Add intro : $ADDINTRO"
echo "Add promo : $ADDPROMO"
echo "Add Summary : $ADDSUMMARY"
echo "Add outro : $ADDOUTRO"
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 ${fname}_sox.wav > ${fname}_tmp.log 2>&1
if [ "$FIXAUDIO" = "1" ];then
echo "normalizing audio"
sox --temp "${TEMP_DIR}" --norm ${fname}_sox.wav ${fname}_sox_norm.wav
mv -v ${fname}_sox_norm.wav ${fname}_sox.wav >> ${fname}_tmp.log 2>&1
# normalize -a 0.5 ${fname}_sox.wav >> ${fname}_tmp.log 2>&1
fi
echo "--------------------------------------------------------------------------------"
echo "Add HPR Branding"
if [ "$ADDSUMMARY" = 'y' ]; then
echo "Creating the summary"
#echo "$HPR_summary" - | espeak -w hpr${ep_num}_summary.wav
echo "$HPR_summary" - | text2wave - -o hpr${ep_num}_summary.wav #festival --tts
#echo "${HPR_summary}" | gtts-cli - --output hpr${ep_num}_summary.mp3
#ffmpeg -i hpr${ep_num}_summary.mp3 hpr${ep_num}_summary.wav
#rm -v hpr${ep_num}_summary.mp3
else
echo "Copying the supplied summary"
if [ ! -e "${media_dir}/summary.wav" ]
then
echoerr "ERROR: Can not find the summary file \"${media_dir}/summary.wav\""
exit 1
fi
cp -v "${media_dir}/summary.wav" hpr${ep_num}_summary.wav
fi
ffmpeg -i hpr${ep_num}_summary.wav -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i hpr${ep_num}_summary.wav -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
rm hpr${ep_num}_summary.wav
if [ "$ADDSPONSOR" = 'y' ]; then
echo "Adding the sponsor"
ffmpeg -i "$anhonesthost" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i "$internetarchive" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
else
echo "NOT Adding the sponsor"
fi
if [ "$ADDPROMO" = 'y' ]; then
echo "Adding the promo"
ffmpeg -i "$promo" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i "$promo" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
fi
if [ "$ADDINTRO" = 'y' ]; then
echo "Adding the intro"
ffmpeg -i "$intro" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i "$intro" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
fi
echo "convert the uploaded episode and add it to the temp pcm file"
ffmpeg -i ${fname}_sox.wav -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i ${fname}_sox.wav -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
if [ "$ADDOUTRO" = 'y' ]; then
echo "Adding the outro"
ffmpeg -i "$outro" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_hh.pcm 2>> ${fname}_tmp.log
ffmpeg -i "$outro" -ar 44100 -ac $CHANNELS -acodec pcm_s16le -f s16le - >> ${fname}_tmp_ia.pcm 2>> ${fname}_tmp.log
fi
echo "Convert the pcm file to a know wav format"
ffmpeg -f s16le -ar 44100 -ac $CHANNELS -acodec pcm_s16le -i ${fname}_tmp_hh.pcm ${fname}_mez.wav 2>> ${fname}_tmp.log
ffmpeg -f s16le -ar 44100 -ac $CHANNELS -acodec pcm_s16le -i ${fname}_tmp_ia.pcm hpr${ep_num}.wav 2>> ${fname}_tmp.log
echo "Normalizing the wav files"
sox --temp "${TEMP_DIR}" --norm ${fname}_mez.wav ${fname}_mez_norm.wav
mv -v ${fname}_mez_norm.wav ${fname}_mez.wav >> ${fname}_tmp.log 2>&1
# normalize -a 0.5 ${fname}_mez.wav >> ${fname}_tmp.log 2>&1
sox --temp "${TEMP_DIR}" --norm hpr${ep_num}.wav hpr${ep_num}_norm.wav
mv -v hpr${ep_num}_norm.wav /var/IA/uploads/hpr${ep_num}.wav >> ${fname}_tmp.log 2>&1
# normalize -a 0.5 hpr${ep_num}.wav >> ${fname}_tmp.log 2>&1
echo "--------------------------------------------------------------------------------"
echo "File information"
ffprobe ${fname}_mez.wav 2>&1 | grep Audio:
mediainfo ${fname}_mez.wav
echo "--------------------------------------------------------------------------------"
echo "Convert to opus for IA"
opusenc hpr${ep_num}.wav /var/IA/uploads/hpr${ep_num}.opus
echo "--------------------------------------------------------------------------------"
echo "Convert to flac for IA"
sox --temp "${TEMP_DIR}" -S hpr${ep_num}.wav /var/IA/uploads/hpr${ep_num}.flac
echo "--------------------------------------------------------------------------------"
echo "Convert to mp3 for HPR"
sox --temp "${TEMP_DIR}" -S ${fname}_mez.wav hpr${ep_num}.mp3
echo "Convert to mp3 for IA"
sox --temp "${TEMP_DIR}" -S hpr${ep_num}.wav /var/IA/uploads/hpr${ep_num}.mp3
echo "--------------------------------------------------------------------------------"
echo "Convert to ogg for HPR"
sox --temp "${TEMP_DIR}" -S ${fname}_mez.wav hpr${ep_num}.ogg
echo "Convert to ogg for IA"
sox --temp "${TEMP_DIR}" -S hpr${ep_num}.wav /var/IA/uploads/hpr${ep_num}.ogg
echo "--------------------------------------------------------------------------------"
echo "Convert to spx for HPR"
sox --temp "${TEMP_DIR}" -S ${fname}_mez.wav -c 1 -r 16000 -t wav - | speexenc - hpr${ep_num}.spx
echo "Convert to spx for IA"
sox --temp "${TEMP_DIR}" -S hpr${ep_num}.wav -c 1 -r 16000 -t wav - | speexenc - /var/IA/uploads/hpr${ep_num}.spx
if [[ ! -s /var/IA/uploads/hpr${ep_num}.wav ]] || [[ ! -s /var/IA/uploads/hpr${ep_num}.mp3 ]] || [[ ! -s /var/IA/uploads/hpr${ep_num}.ogg ]] || [[ ! -s /var/IA/uploads/hpr${ep_num}.spx ]] || [[ ! -s hpr${ep_num}.mp3 ]] || [[ ! -s hpr${ep_num}.ogg ]] || [[ ! -s 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" hpr${ep_num}* 2>> ${fname}_tmp.log 1>&2
fix_tags -album="$HPR_album" -artist="$HPR_artist" -comment="$HPR_comment" -genre="$HPR_genre" -title="$HPR_title" -track="$HPR_track" -year="$HPR_year" /var/IA/uploads/hpr${ep_num}* 2>> ${fname}_tmp.log 1>&2
fix_tags hpr${ep_num}*
fix_tags /var/IA/uploads/hpr${ep_num}*
#echo "Changing the file dates to the time of upload"
touch -r ${mediafile} hpr${ep_num}*
touch -r ${mediafile} /var/IA/uploads/hpr${ep_num}*
rsync -ave ssh --partial --progress --ignore-existing hpr${ep_num}.mp3 hpr${ep_num}.ogg 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:///var/IA/uploads/hpr${ep_num}.mp3
firefox file:///var/IA/uploads/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:///var/IA/uploads/hpr${ep_num}.spx" "file:///var/IA/uploads/hpr${ep_num}.opus" "file:///var/IA/uploads/hpr${ep_num}.ogg" "file:///var/IA/uploads/hpr${ep_num}.mp3" "file:///var/IA/uploads/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}* /var/IA/uploads/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}" "/var/IA/uploads/hpr${ep_num}_source.${mediaextension}"
#echo "Remove temp files"
rm -v ${fname}_sox.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 /var/IA/uploads/ hpr:/home/hpr/upload/processed/
rsync -ave ssh --partial --progress /var/IA/uploads/ borg:/data/IA/uploads/
echo "$( ssh borg -t "ls -al /data/IA/uploads/hpr${ep_num}*" ; ls -al /var/IA/uploads/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}\" \"/var/IA/uploads/hpr${ep_num}_source.${mediaextension}\""
echo "rm -v ${fname}_sox.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 /var/IA/uploads/ borg:/data/IA/uploads/"
fi

252
bin/postshow.bash Executable file
View File

@ -0,0 +1,252 @@
#!/usr/bin/env bash
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
#============================================================
processing_dir="/home/ken/tmp/hpr/processing"
git_image_dir="/home/ken/sourcecode/hpr/HPR_Public_Code/www/images/hosts"
echo "Processing the next HPR Show in the queue"
###################
# Get the show
#
#
response=$( curl --silent --netrc-file ${HOME}/.netrc "https://hub.hackerpublicradio.org/cms/status.php" | \
grep 'METADATA_PROCESSED' | \
head -1 | \
sed 's/,/ /g' )
if [ -z "${response}" ]
then
echo "INFO: There appear to be no more shows with the status \"METADATA_PROCESSED\"."
echo "Getting a list of all the reservations."
curl --silent --netrc-file ${HOME}/.netrc "https://hub.hackerpublicradio.org/cms/status.php"
exit 3
fi
timestamp_epoc="$( echo ${response} | awk '{print $1}' )"
ep_num="$( echo ${response} | awk '{print $2}' )"
ep_date="$( echo ${response} | awk '{print $3}' )"
key="$( echo ${response} | awk '{print $4}' )"
status="$( echo ${response} | awk '{print $5}' )"
email="$( echo ${response} | awk '{print $6}' )"
email_unpadded="$( echo $email | sed 's/.nospam@nospam./@/g' )"
source_dir="hpr:/home/hpr/upload/${timestamp_epoc}_${ep_num}_${ep_date}_${key}"
dest_dir="${timestamp_epoc}_${ep_num}_${ep_date}_${key}"
echo "INFO: Downloading hpr${ep_num} from ${email_unpadded}"
echo ""
echo rsync -ave ssh --partial --progress ${source_dir}/ ${processing_dir}/${dest_dir}/
rsync -ave ssh --partial --progress ${source_dir}/ ${processing_dir}/${dest_dir}/
echo ""
echo "INFO: Working directory is \"${processing_dir}/${dest_dir}/\""
echo ""
shownotes_json="${processing_dir}/${dest_dir}/shownotes.json"
if [ ! -s "${shownotes_json}" ]
then
echo "ERROR: \"${shownotes_json}\" is missing"
exit 2
fi
jq '.' "${shownotes_json}" | sponge "${shownotes_json}"
###################
# Get the media
#
remote_media="$( jq --raw-output '.metadata.POST.url' "${processing_dir}/${dest_dir}/shownotes.json" )"
if [ -n "${remote_media}" ]
then
echo "INFO: Fetching remote media from \"${remote_media}\""
wget --timestamping --directory-prefix="${processing_dir}/${dest_dir}/" "${remote_media}"
if [ $? -ne 0 ]
then
echo "ERROR: Could not get the remote media"
exit 5
fi
fi
shownotes_html="${processing_dir}/${dest_dir}/shownotes.html"
if [ ! -s "${shownotes_html}" ]
then
echo "ERROR: \"${shownotes_html}\" is missing"
exit 4
fi
shownotes_txt="${processing_dir}/${dest_dir}/shownotes.txt"
if [ ! -s "${shownotes_txt}" ]
then
echo "ERROR: \"${shownotes_txt}\" is missing"
exit 7
fi
xdg-open "${shownotes_txt}" >/dev/null 2>&1 &
xdg-open "${shownotes_json}" >/dev/null 2>&1 &
xdg-open "${shownotes_html}" >/dev/null 2>&1 &
read -p "Does the metadata 'look ok ? (N|y) ? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[yY]$ ]]
then
echo "skipping...."
exit 22
fi
media=$( find "${processing_dir}/${dest_dir}/" -type f -exec file {} \; | grep -Ei 'audio|mpeg|video|MP4' | awk -F ': ' '{print $1}' )
if [ -z "${media}" ]
then
echo "ERROR: Can't find any media in \"${processing_dir}/${dest_dir}/\""
find "${processing_dir}/${dest_dir}/" -type f
exit 1
fi
the_show_media=""
if [ "$( echo "${media}" | wc -l )" -ne 1 ]
then
echo "Multiple files found. Which one do you want to use ?"
select this_media in $( echo "${media}" )
do
echo "INFO: You selected \"${this_media}\"."
ls -al "${this_media}"
the_show_media="${this_media}"
break
done
else
echo "INFO: Selecting media as \"${media}\"."
the_show_media="${media}"
fi
duration=$( \date -ud "1970-01-01 $( ffprobe -i "${the_show_media}" 2>&1| awk -F ': |, ' '/Duration:/ { print $2 }' )" +%s )
###################
# Gather episode information
#
if [ "$( curl --silent --write-out '%{http_code}' http://hackerpublicradio.org/say.php?id=${ep_num} --output /dev/null )" == 200 ]
then
echo "ERROR: The Episode hpr${ep_num} has already been posted"
exit 6
fi
if [ "$( jq --raw-output '.metadata.Episode_Number' ${shownotes_json} )" != "${ep_num}" ]
then
echo "ERROR: The Episode_Number: \"${ep_num}\" was not found in \"${shownotes_json}\""
exit 10
fi
if [ "$( jq --raw-output '.metadata.Episode_Date' ${shownotes_json} )" != "${ep_date}" ]
then
echo "ERROR: The Episode_Date: \"${ep_date}\" was not found in \"${shownotes_json}\""
exit 8
fi
if [ "$( jq --raw-output '.host.Host_Email' ${shownotes_json} )" != "${email_unpadded}" ]
then
echo "ERROR: The Host_Email: \"${email_unpadded}\" was not found in \"${shownotes_json}\""
exit 9
fi
###################
# Assemble the components
#
# https://newbedev.com/how-to-urlencode-data-for-curl-command/
hostid="$( jq --raw-output '.host.Host_ID' ${shownotes_json} | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
host_name="$( jq --raw-output '.host.Host_Name' ${shownotes_json} | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
#TODO title=$( grep -P "Title:\t" ${shownotes_txt} | awk -F "\t" '{print $2}' | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )
title=$( jq --raw-output '.episode.Title' ${shownotes_json} )
#TODO summary="$( grep -P "Summary:\t" ${shownotes_txt} | awk -F "\t" '{print $2}' | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
summary="$( jq --raw-output '.episode.Summary' ${shownotes_json} )"
#TODO jq --raw-output '.episode.Show_Notes' ${shownotes_json}
series="$( jq --raw-output '.episode.Series' ${shownotes_json} )"
series_name="$( jq --raw-output '.episode.Series_Name' ${shownotes_json} | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
explicit="$( jq --raw-output '.episode.Explicit' ${shownotes_json} )"
episode_license="$( jq --raw-output '.episode.Show_License' ${shownotes_json} )"
#TODO tags="$( grep -P "Tags:\t" ${shownotes_txt} | awk -F "\t" '{print $2}' | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
tags="$( jq --raw-output '.episode.Tags' ${shownotes_json} )"
host_license=$( jq --raw-output '.host.Host_License' ${shownotes_json} | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )
host_profile=$( jq --raw-output '.host.Host_Profile' ${shownotes_json} | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )
# notes="$( grep -P ":\t" ${shownotes_txt} | awk -F "\t" '{print $2}' )"
notes="$( cat "${shownotes_html}" | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
if [ $# -gt 0 ]
then
declare -A hash
for argument
do
if [[ $argument =~ ^[^=]+=.*$ ]]
then
this_key="${argument%=*}" # "${} Kate format hack
this_value="${argument#*=}" # "${} Kate format hack
this_value="$( echo "${this_value}" | jq --slurp --raw-input @uri | sed -e 's/%0A"$//g' -e 's/^"//g' )"
eval "${this_key}=${this_value}"
echo "INFO: Replacing \"${this_key}\" with \"${this_value}\"."
fi
done
fi
if [ "${hostid}" == '0' ]
then
echo "ERROR: The hostid is 0. Create the host and use \"hostid=???\" to override"
exit 11
fi
# # # # has to be done here as we need to know the hostid
# # # host_photo="$( jq --raw-output '.metadata.FILES.host_photo.name' ${shownotes_json} )"
# # # if [ -n "${host_photo}" ]
# # # then
# # # host_photo="${processing_dir}/${dest_dir}/photo"
# # # host_avatar="${git_image_dir}/${hostid}.png"
# # # echo "INFO: Found host photo \"${host_photo}\""
# # # gm convert "${host_photo}" -resize x80 "${host_avatar}"
# # # xdg-open "${host_avatar}"
# # # read -p "Does the avatar 'look ok ? (N|y) ? " -n 1 -r
# # # echo # (optional) move to a new line
# # # if [[ ! $REPLY =~ ^[yY]$ ]]
# # # then
# # # echo "ERROR: Problem with avatar...."
# # # exit 12
# # # else
# # # echo "INFO: Copying avatar to the server."
# # # scp "${host_avatar}" hpr:www/images/hosts/
# # # fi
# # # fi
###################
# Post show to HPR
#
post_show="${processing_dir}/${dest_dir}/post_show.txt"
post_show_response="${processing_dir}/${dest_dir}/post_show_response.txt"
echo "key=${key}&ep_num=${ep_num}&ep_date=${ep_date}&email=${email}&title=${title}&duration=${duration}&summary=${summary}&series=${series}&series_name=${series_name}&explicit=${explicit}&episode_license=${episode_license}&tags=${tags}&hostid=${hostid}&host_name=${host_name}&host_license=${host_license}&host_profile=${host_profile}&notes=${notes}" > ${post_show}
echo "Sending:"
cat "${post_show}"
echo "key=${key}
ep_num=${ep_num}
ep_date=${ep_date}
email=${email}
title=${title}
duration=${duration}
summary=${summary}
series=${series}
series_name=${series_name}
explicit=${explicit}
episode_license=${episode_license}
tags=${tags}
hostid=${hostid}
host_name=${host_name}
host_license=${host_license}
host_profile=${host_profile}
notes=${notes}"
wget --post-file="${post_show}" "https://hub.hackerpublicradio.org/cms/add_show.php" -O - #"${post_show_response}"
# /home/ken/sourcecode/personal/bin/hpr-publish.bash
#
# xdg-open "https://hackerpublicradio.org/eps/hpr${ep_num}/index.html" >/dev/null 2>&1 &