diff --git a/workflow/process_episode.bash b/workflow/process_episode.bash index 64c562f..9708e7f 100755 --- a/workflow/process_episode.bash +++ b/workflow/process_episode.bash @@ -290,6 +290,12 @@ function check_variable_is_correct() { echo_error "The \"license_url\" variable is missing." fi ;; + media) + if [ -z "${media}" ] + then + echo_error "The \"media\" variable is missing." + fi + ;; outro_flac) if [[ ! -d "${outro_flac}" || -z "${outro_flac}" ]] then @@ -571,7 +577,7 @@ function get_episode_metadata() { shownotes_edited="${working_dir}/shownotes_edited.html" hostid="$( jq --raw-output '.host.Host_ID' ${shownotes_json} )" - host_name="$( jq --raw-output '.host.Host_Name' ${shownotes_json} )" + artist="$( jq --raw-output '.host.Host_Name' ${shownotes_json} )" email="$( jq --raw-output '.host.Host_Email' ${shownotes_json} )" email_padded="$( echo $email | sed 's/@/.nospam@nospam./g' )" title="$( jq --raw-output '.episode.Title' ${shownotes_json} )" @@ -579,7 +585,7 @@ function get_episode_metadata() { series_id="$( jq --raw-output '.episode.Series' ${shownotes_json} )" series_name="$( jq --raw-output '.episode.Series_Name' ${shownotes_json} )" explicit="$( jq --raw-output '.episode.Explicit' ${shownotes_json} )" - episode_license="$( jq --raw-output '.episode.Show_License' ${shownotes_json} )" + license="$( jq --raw-output '.episode.Show_License' ${shownotes_json} )" ep_date="$( jq --raw-output '.metadata.Episode_Date' ${shownotes_json} )" ep_num="$( jq --raw-output '.metadata.Episode_Number' ${shownotes_json} )" key="$( jq --raw-output '.metadata.Key' ${shownotes_json} )" @@ -604,7 +610,7 @@ function get_episode_metadata() { ' ) | sponge "${shownotes_html}" - episode_variables=( shownotes_json shownotes_html hostid host_name email title summary series_id series_name explicit episode_license ep_date ep_num tags host_license host_profile remote_media shownotes_json_sanatised ) + episode_variables=( shownotes_json shownotes_html hostid artist email title summary series_id series_name explicit license ep_date ep_num tags host_license host_profile remote_media shownotes_json_sanatised ) for episode_variable in "${episode_variables[@]}" do @@ -932,13 +938,13 @@ function generate_initial_report() { hostid${hostid} -host_name${host_name} +host_name${artist} title${title} summary${summary} series_id${series_id} series_name${series_name} explicit${explicit} -episode_license${episode_license} +episode_license${license} tags${tags} host_license${host_license} host_profile${host_profile} @@ -1091,10 +1097,10 @@ function post_show_to_hpr_db() { series_id=${series_id} series_name=${series_name} explicit=${explicit} - episode_license=${episode_license} + episode_license=${license} tags=${tags} hostid=${hostid} - host_name=${host_name} + host_name=${artist} host_license=${host_license} host_profile=${host_profile_encoded} notes=REMOVED" @@ -1110,10 +1116,10 @@ function post_show_to_hpr_db() { \"series_id\": \"${series_id}\", \"series_name\": \"${series_name}\", \"explicit\": \"${explicit}\", - \"episode_license\": \"${episode_license}\", + \"episode_license\": \"${license}\", \"tags\": \"${tags}\", \"hostid\": \"${hostid}\", - \"host_name\": \"${host_name}\", + \"host_name\": \"${artist}\", \"host_license\": \"${host_license}\", \"host_profile\": \"${host_profile_encoded}\", \"notes\": \"${notes}\" @@ -1252,6 +1258,8 @@ function generate_parent_audio() { function generate_derived_media() { echo_debug "Generating derived audio. generate_derived_media()" + + check_variable_is_correct media working_dir ep_num title artist license if [[ ! -s "${working_dir}/processing/episode_final.flac" ]] then @@ -1259,8 +1267,10 @@ function generate_derived_media() { echo_error "The final cut is not available." fi - episode_comment="$( jq --raw-output '.comment' "${episode_summary_json}" )" - episode_year="$( echo "${ep_date}" | cut -c -4 )" + comment="$( jq --raw-output '.comment' "${episode_summary_json}" )" + year="$( echo "${ep_date}" | cut -c -4 )" + + check_variable_is_correct comment year # https://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata @@ -1269,18 +1279,18 @@ function generate_derived_media() { echo_debug "Generating \"hpr${ep_num}.${extension}\"." ffmpeg -hide_banner -loglevel error -y -i "${working_dir}/processing/episode_final.flac" \ -metadata title="${title}" \ - -metadata artist="${host_name}" \ - -metadata author="${host_name}" \ + -metadata artist="${artist}" \ + -metadata author="${artist}" \ -metadata album="Hacker Public Radio" \ - -metadata comment="${episode_comment} The license is ${episode_license}" \ - -metadata year="${episode_year}" \ + -metadata comment="${comment} The license is ${license}" \ + -metadata year="${year}" \ -metadata track="${ep_num}" \ -metadata genre="Podcast" \ -metadata language="English" \ - -metadata copyright="${episode_license}" \ + -metadata copyright="${license}" \ "${working_dir}/hpr${ep_num}.${extension}" - fix_tags -album="Hacker Public Radio" -artist="${host_name}" -comment="${episode_comment} The license is ${episode_license}" -genre="Podcast" -title="${title}" -track="${ep_num}" -year="${episode_year}" "${working_dir}/hpr${ep_num}.${extension}" + fix_tags -album="Hacker Public Radio" -artist="${artist}" -comment="${comment} The license is ${license}" -genre="Podcast" -title="${title}" -track="${ep_num}" -year="${year}" "${working_dir}/hpr${ep_num}.${extension}" if [[ ! -s "${working_dir}/hpr${ep_num}.${extension}" ]] then @@ -1290,12 +1300,21 @@ function generate_derived_media() { done + lengths=$( for extension in flac wav mp3 ogg opus + do + mediainfo --full --Output=XML "${working_dir}/hpr${ep_num}.${extension}" | xmlstarlet sel -T -t -m "_:MediaInfo/_:media/_:track[@type='Audio']/_:Duration[1]" -v "." -n - | awk -F '.' '{print $1}' + done | sort | uniq | wc -l ) + if [ "${lengths}" -ne "1" ] + then + echo_error "The duration of the derived media is not correct." + fi + cp -v "${media}" "${working_dir}/hpr${ep_num}_source.${media##*.}" if [[ ! -s "${working_dir}/hpr${ep_num}_source.${media##*.}" ]] then - echo_error "Failed to copy \"${working_dir}/hpr${ep_num}_source.${media##*.}\"." ls -al "${working_dir}/hpr${ep_num}_source.${media##*.}" + echo_error "Failed to copy \"${working_dir}/hpr${ep_num}_source.${media##*.}\"." fi }