From 513631c80b81bdd9fb2892ed775035d0c825f469 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 8 Jul 2017 12:48:02 +0200 Subject: [PATCH] uniform --- scripts/check_audio_framemd5.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/scripts/check_audio_framemd5.sh b/scripts/check_audio_framemd5.sh index 27253ac..7b72fe3 100755 --- a/scripts/check_audio_framemd5.sh +++ b/scripts/check_audio_framemd5.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2017-04-17' + VERSION='2017-07-08' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' NC='\033[0m' -if [[ ${OSTYPE} = "cygwin" ]] || [ ! $(which diff) ]; then +if [[ "${OSTYPE}" = "cygwin" ]] || [ ! $(which diff) ]; then echo -e "${RED}Error: 'diff' is not installed by default. Please install 'diffutils' from Cygwin.${NC}" exit 1 fi _output_prompt(){ cat < -m +Usage: ${SCRIPT} -i -m | -h EOF exit 1 } @@ -21,13 +21,11 @@ EOF _output_help(){ cat < -m Pass to the script the audio-visual file and the corresponding MD5 file to check. + ${SCRIPT} -h + This help. Dependency: ffmpeg About: @@ -40,11 +38,11 @@ EOF unset input_file unset input_hash -while getopts ":hi:m:" opt; do +while getopts ":i:m:h" opt; do case "${opt}" in + i) input_file=${OPTARG} ;; + m) input_hash=${OPTARG} ;; h) _output_help ;; - i) input_file=$OPTARG ;; - m) input_hash=$OPTARG ;; :) echo -e "${RED}Error: option -${OPTARG} requires an argument${NC}" ; _output_prompt ;; *) echo -e "${RED}Error: bad option -${OPTARG}${NC}" ; _output_prompt ;; esac @@ -59,12 +57,12 @@ else md5_tmp="${HOME}/$(basename "${input_hash}").tmp" fi # Find audio frame size for hash calculation +unset sample_rate sample_rate=$(grep -v '^#' "${input_hash}" | head -n 1 | tr -d ' ' | cut -d',' -f4) ffmpeg -i "${input_file}" -loglevel 0 -af "asetnsamples=n='$sample_rate'" -f framemd5 -vn "${md5_tmp}" [[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error: '${input_file}' is not a valid audio-visual file.${NC}" ; _output_prompt ; } unset old_file unset tmp_file -unset sample_rate old_file=$(grep -v '^#' "${input_hash}") tmp_file=$(grep -v '^#' "${md5_tmp}") if [[ "${old_file}" = "${tmp_file}" ]]; then