diff --git a/workflow/process_episode.bash b/workflow/process_episode.bash index 73b0929..e77aa45 100755 --- a/workflow/process_episode.bash +++ b/workflow/process_episode.bash @@ -22,9 +22,12 @@ piper_voice="/opt/bin/piper/piper/piper-voices/en/en_US/lessac/medium/en_US-less working_dir_bypass="false" skip_post_show="false" +skip_media_encoding="false" + acceptable_duration_difference="2" # Seconds unsafe_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 ) audio_formats=( flac wav mp3 ogg opus spx ) +episode_formats=( flac wav mp3 ogg opus spx srt txt ) ################################################# # Display Error message, display help and exit @@ -133,7 +136,6 @@ function argument_override() { if [ "${this_key}" == "working_dir" ] then working_dir_bypass="true" - set_working_processing_dir fi fi done @@ -174,6 +176,10 @@ function check_variable_is_correct() { then echo_error "The \"assets_csv\" variable has not a valid \"text/csv\" mime type." fi + if [ "$( wc --lines ${assets_csv} | awk '{print $1}' )" -le "1" ] + then + echo_error "The \"${assets_csv}\" file is empty." + fi ;; assets_json) if [[ ! -s "${assets_json}" || -z "${assets_json}" ]] @@ -230,6 +236,72 @@ function check_variable_is_correct() { echo_error "The \"email_unpadded\" variable is missing." fi ;; + episode_body_flac) + if [ -z "${episode_body_flac}" ] + then + echo_error "The \"episode_body_flac\" variable is missing." + fi + ;; + episode_body_srt) + if [ -z "${episode_body_srt}" ] + then + echo_error "The \"episode_body_srt\" variable is missing." + fi + ;; + episode_final_flac) + if [ -z "${episode_final_flac}" ] + then + echo_error "The \"episode_final_flac\" variable is missing." + fi + ;; + episode_intro_flac) + if [ -z "${episode_intro_flac}" ] + then + echo_error "The \"episode_intro_flac\" variable is missing." + fi + ;; + episode_intro_srt) + if [ -z "${episode_intro_srt}" ] + then + echo_error "The \"episode_intro_srt\" variable is missing." + fi + ;; + episode_outro_srt) + if [ -z "${episode_outro_srt}" ] + then + echo_error "The \"episode_outro_srt\" variable is missing." + fi + ;; + episode_sandwitch_flac) + if [ -z "${episode_sandwitch_flac}" ] + then + echo_error "The \"episode_sandwitch_flac\" variable is missing." + fi + ;; + episode_srt) + if [ -z "${episode_srt}" ] + then + echo_error "The \"episode_srt\" variable is missing." + fi + ;; + episode_summary_flac) + if [ -z "${episode_summary_flac}" ] + then + echo_error "The \"episode_summary_flac\" variable is missing." + fi + ;; + episode_tts_flac) + if [ -z "${episode_tts_flac}" ] + then + echo_error "The \"episode_tts_flac\" variable is missing." + fi + ;; + episode_tts_wav) + if [ -z "${episode_tts_wav}" ] + then + echo_error "The \"episode_tts_wav\" variable is missing." + fi + ;; episode_summary_json) if [[ ! -s "${episode_summary_json}" || -z "${episode_summary_json}" ]] then @@ -261,6 +333,12 @@ function check_variable_is_correct() { echo_error "The \"ep_num\" variable is not a valid number between 1 and 9999." fi ;; + expected_duration) + if [ -z "${expected_duration}" ] + then + echo_error "The \"expected_duration\" variable is missing." + fi + ;; explicit) if [[ -z "${explicit}" || "${explicit}" == "null" ]] then @@ -315,6 +393,12 @@ function check_variable_is_correct() { echo_error "The \"hostid\" variable is missing." fi ;; + intro_duration) + if [ -z "${intro_duration}" ] + then + echo_error "The \"intro_duration\" variable is missing." + fi + ;; intro_srt) if [[ ! -d "${intro_srt}" || -z "${intro_srt}" ]] then @@ -346,11 +430,35 @@ function check_variable_is_correct() { fi ;; media_basename) - if [[ ! -d "${media_basename}" || -z "${media_basename}" ]] + if [[ ! -s "${media_basename}" || -z "${media_basename}" ]] then echo_error "The \"media_basename\" variable is missing or is not a directory." fi ;; + media_ffprobe) + if [ -z "${media_ffprobe}" ] + then + echo_error "The \"media_ffprobe\" variable is missing." + fi + ;; + media_file_mime) + if [ -z "${media_file_mime}" ] + then + echo_error "The \"media_file_mime\" variable is missing." + fi + ;; + media_file_mime_type) + if [ -z "${media_file_mime_type}" ] + then + echo_error "The \"media_file_mime_type\" variable is missing." + fi + ;; + outro_duration) + if [ -z "${outro_duration}" ] + then + echo_error "The \"outro_duration\" variable is missing." + fi + ;; outro_flac) if [[ ! -s "${outro_flac}" || -z "${outro_flac}" ]] then @@ -422,6 +530,12 @@ function check_variable_is_correct() { echo_error "The \"silence\" variable is missing or file \"${silence}\" does not exist." fi ;; + source_duration) + if [ -z "${source_duration}" ] + then + echo_error "The \"source_duration\" variable is missing." + fi + ;; summary) if [[ -z "${summary}" || "${summary}" == "null" ]] then @@ -470,12 +584,6 @@ function check_variable_is_correct() { echo_error "The \"working_dir\" variable is missing or is not a directory." fi ;; - working_processing_dir) - if [[ ! -d "${working_processing_dir}" || -z "${working_processing_dir}" ]] - then - echo_error "The \"working_processing_dir\" variable is missing or is not a directory." - fi - ;; year) if [[ -z "${year}" || "${year}" == "null" ]] then @@ -538,16 +646,7 @@ function get_next_show_from_hpr_hub() { ssh hpr -t "detox -v ${hpr_upload_dir}/" rsync -ave ssh --partial --progress ${source_dir}/ ${working_dir}/ - - if [ ! -s "${working_dir}/shownotes.json" ] - then - echo_error "The working dir is missing the shownotes file \"${working_dir}/shownotes.json\"" - fi - - if [ "$( file --brief --mime-type "${working_dir}/shownotes.json" | grep --count "application/json" )" -eq 0 ] - then - echo_error "The \"${working_dir}/shownotes.json\" is not a \"application/json\" file" - fi + check_variable_is_correct shownotes_json } @@ -560,7 +659,7 @@ function get_ep_num_from_local_dir() { check_variable_is_correct working_dir - if [ ! -s "${working_dir}/shownotes.json" ] + if [ ! -s "${shownotes_json}" ] then echo_debug "Could not find a \"shownotes.json\" in the working directory \"${working_dir}/\"" @@ -578,22 +677,19 @@ function get_ep_num_from_local_dir() { echo_debug "Attempting to download information for episode \"${ep_num}\"" - if [ "$( curl --silent --netrc-file ${HOME}/.netrc --write-out '%{http_code}' https://hub.hackerpublicradio.org/cms/shownotes.php?id=${ep_num} --output "${working_dir}/shownotes.json" )" != 200 ] + if [ "$( curl --silent --netrc-file ${HOME}/.netrc --write-out '%{http_code}' https://hub.hackerpublicradio.org/cms/shownotes.php?id=${ep_num} --output "${shownotes_json}" )" != 200 ] then echo_error "The Episode hpr${ep_num} has not been posted." fi - if [ ! -s "${working_dir}/shownotes.json" ] + if [ ! -s "${shownotes_json}" ] then echo_error "The Episode information for hpr${ep_num} failed to download." fi fi - if [[ -s "${working_dir}/shownotes.json" && "$( file --brief --mime-type "${working_dir}/shownotes.json" | grep --count "application/json" )" -eq 0 ]] - then - echo_error "\"${working_dir}/shownotes.json\" is not a \"application/json\" file" - fi + check_variable_is_correct shownotes_json } @@ -618,32 +714,34 @@ function get_working_dir() { check_variable_is_correct ep_num fi - if [ ! -s "${working_dir}/shownotes.json" ] - then - echo_error "The working dir \"${working_dir}\" could not be found." - fi - echo_debug "Found working directory as \"${working_dir}\"" } + ################################################# -# Create a sub dir to store technical data. +# Once the working_dir is known, set the other variables -function set_working_processing_dir() { +function set_working_dir_variables() { - echo_debug "Checking the processing directory in the current working directory. set_working_processing_dir()" + echo_debug "Setting the other working directory and variables. set_working_dir_variables()" check_variable_is_correct working_dir - - working_processing_dir="${working_dir}/processing" - if [ ! -d "${working_processing_dir}/" ] - then - mkdir -v "${working_processing_dir}/" - fi - - check_variable_is_correct working_processing_dir + shownotes_json="${working_dir}/shownotes.json" + shownotes_html="${working_dir}/shownotes.html" + shownotes_edited="${working_dir}/shownotes_edited.html" + episode_tts_wav="${working_dir}/episode_tts.wav" + episode_tts_flac="${working_dir}/episode_tts.flac" + episode_summary_flac="${working_dir}/episode_summary.flac" + episode_intro_flac="${working_dir}/episode_intro.flac" + episode_body_flac="${working_dir}/episode_body.flac" + episode_sandwitch_flac="${working_dir}/episode_sandwitch.flac" + episode_final_flac="${working_dir}/episode_final.flac" + episode_intro_srt="${working_dir}/episode_intro.srt" + episode_body_srt="${working_dir}/episode_body.srt" + episode_outro_srt="${working_dir}/episode_outro.srt" + episode_srt="${working_dir}/episode.srt" } ################################################# @@ -659,17 +757,10 @@ function get_episode_metadata() { return fi - check_variable_is_correct working_dir + check_variable_is_correct working_dir shownotes_json - if [[ -s "${working_dir}/shownotes.json" && "$( file --brief --mime-type "${working_dir}/shownotes.json" | grep --count "application/json" )" -eq 0 ]] - then - echo_error "\"${working_dir}/shownotes.json\" is not a \"application/json\" file" - fi + set_working_dir_variables - shownotes_json="${working_dir}/shownotes.json" - shownotes_html="${working_dir}/shownotes.html" - shownotes_edited="${working_dir}/shownotes_edited.html" - check_variable_is_correct shownotes_json hostid="$( jq --raw-output '.host.Host_ID' ${shownotes_json} )" @@ -884,7 +975,7 @@ function media_checks() { echo_debug "Running media checks. media_checks()" - check_variable_is_correct working_dir working_processing_dir + check_variable_is_correct working_dir if [[ -n "${remote_media}" && "${remote_media}" != "null" ]] then @@ -912,15 +1003,23 @@ function media_checks() { if [ "$( echo "${media}" | wc --lines )" -ne 1 ] then echo "Multiple files found. Which one do you want to use ?" - select this_media in $( echo "${media}" ) + select this_media in "Skip asset creation" $( echo "${media}" ) do + if [ "${this_media}" == "Skip asset creation" ] + then + echo_debug "Skip asset creation" + check_derived_assets + skip_media_encoding="true" + return + fi ls -al "${this_media}" media="${this_media}" break done fi - echo_debug "You selected \"${media}\"." + echo_debug "You selected \"${media}\"." + if [[ -z "${media}" || ! -s "${media}" ]] then echo_error "Could not find the media \"${media}/\"" @@ -955,32 +1054,28 @@ function media_checks() { echo_debug "The number of audio channels is \"${supplied_channels}\" from \"${media}\" ." # Gernerate the Spectrum and Waveform image - ffmpeg -hide_banner -loglevel error -y -i "${media}" -lavfi "showspectrumpic=s=960x540" "${working_processing_dir}/${media_basename%.*}_spectrum.png" - audio2image.bash "${media}" && mv -v "${media%.*}.png" "${working_processing_dir}/${media_basename%.*}_waveform.png" + ffmpeg -hide_banner -loglevel error -y -i "${media}" -lavfi "showspectrumpic=s=960x540" "${working_dir}/${media_basename%.*}_spectrum.png" + audio2image.bash "${media}" && mv -v "${media%.*}.png" "${working_dir}/${media_basename%.*}_waveform.png" # Getting metadata - mediainfo "${media}" > "${working_processing_dir}/${media_basename%.*}_mediainfo.txt" + mediainfo "${media}" > "${working_dir}/${media_basename%.*}_mediainfo.txt" - exiftool "${media}" > "${working_processing_dir}/${media_basename%.*}_exiftool.txt" + exiftool "${media}" > "${working_dir}/${media_basename%.*}_exiftool.txt" for check_file in spectrum.png waveform.png mediainfo.txt exiftool.txt do - if [ ! -s "${working_processing_dir}/${media_basename%.*}_${check_file}" ] + if [ ! -s "${working_dir}/${media_basename%.*}_${check_file}" ] then - echo_error "The ${check_file} file was not generated for the \"${working_processing_dir}/${media_basename%.*}_${check_file}\"" >&2 + echo_error "The ${check_file} file was not generated for the \"${working_dir}/${media_basename%.*}_${check_file}\"" >&2 fi done - ffprobe="$( ffprobe ${media} 2>&1 | grep Audio: | sed 's/^.\s//g' )" - file_mime="$( file --brief --mime ${media} )" - file_mime_type="$( file --brief --mime-type ${media} )" - - if [[ -z "${ffprobe}" || -z ${file_mime} || -s ${file_mime_type} ]] - then - echo "ffprobe: ${ffprobe}, file_mime: ${file_mime},file_mime_type: ${file_mime_type}" - echo_error "Wasn't able to find mime metadata from \"${media}/\"" - fi + media_ffprobe="$( ffprobe ${media} 2>&1 | grep Audio: | sed 's/^.\s//g' )" + media_file_mime="$( file --brief --mime ${media} )" + media_file_mime_type="$( file --brief --mime-type ${media} )" + + check_variable_is_correct media_ffprobe media_file_mime media_file_mime_type } @@ -991,11 +1086,11 @@ function generate_initial_report() { echo_debug "Generating the initial report. generate_initial_report()" - if [[ -n "${skip_post_show}" && "${skip_post_show}" == "true" ]] - then - echo_debug "The Episode hpr${ep_num} has already been posted. Skipping generate_initial_report()" - return - fi +# if [[ -n "${skip_post_show}" && "${skip_post_show}" == "true" ]] +# then +# echo_debug "The Episode hpr${ep_num} has already been posted. Skipping generate_initial_report()" +# return +# fi # TODO list the images. @@ -1059,35 +1154,35 @@ ${shownotes_json_sanatised}
-$( cat "${working_processing_dir}/${media_basename%.*}_mediainfo.txt" )
+$( cat "${working_dir}/${media_basename%.*}_mediainfo.txt" )
-$( cat "${working_processing_dir}/${media_basename%.*}_exiftool.txt" )
+$( cat "${working_dir}/${media_basename%.*}_exiftool.txt" )
-
+
-
+
-${ffprobe} -${file_mime} +${media_ffprobe} +${media_file_mime}
${media}
@@ -1101,7 +1196,7 @@ $(cat "${shownotes_srt}" )