2016-07-10 14:35:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2016-07-23 16:48:18 +02:00
|
|
|
SCRIPT=$(basename "${0}")
|
2016-12-31 11:04:15 +01:00
|
|
|
VERSION='2016-12-31'
|
2016-07-10 15:01:00 +02:00
|
|
|
AUTHOR='ffmprovisr'
|
2016-07-10 14:32:35 +02:00
|
|
|
RED='\033[1;31m'
|
2016-10-01 07:33:22 +02:00
|
|
|
BLUE='\033[1;34m'
|
2016-07-10 14:32:35 +02:00
|
|
|
NC='\033[0m'
|
|
|
|
|
2016-12-31 11:04:15 +01:00
|
|
|
if [[ ${OSTYPE} = "cygwin" ]] || [ ! $(which diff) ]; then
|
|
|
|
echo -e "${RED}Error: 'diff' is not installed by default. Please install 'diffutils' from Cygwin.${NC}"
|
2016-10-01 07:33:22 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
_output_prompt(){
|
|
|
|
cat <<EOF
|
2016-12-31 11:04:15 +01:00
|
|
|
Usage: ${SCRIPT} [-h] | [ -i <av_file> -m <md5_file> ]
|
2016-10-01 07:33:22 +02:00
|
|
|
EOF
|
|
|
|
exit 1
|
2016-07-10 14:32:35 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 07:33:22 +02:00
|
|
|
_output_help(){
|
|
|
|
cat <<EOF
|
2016-07-10 14:32:35 +02:00
|
|
|
Syntax:
|
2016-07-23 16:48:18 +02:00
|
|
|
${SCRIPT}
|
2016-07-10 14:32:35 +02:00
|
|
|
Prompts a short help message.
|
2016-07-23 16:48:18 +02:00
|
|
|
${SCRIPT} -h
|
2016-07-10 14:32:35 +02:00
|
|
|
This help.
|
2016-10-08 11:47:43 +02:00
|
|
|
${SCRIPT} -i <av_file> -m <md5_file>
|
2016-07-10 14:32:35 +02:00
|
|
|
Pass to the script the audio-visual file and the corresponding MD5
|
|
|
|
file to check.
|
|
|
|
Dependency:
|
|
|
|
ffmpeg
|
2016-07-23 16:48:18 +02:00
|
|
|
About:
|
|
|
|
Version: ${VERSION}
|
|
|
|
Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/check_framemd5.sh
|
2016-10-01 07:33:22 +02:00
|
|
|
EOF
|
|
|
|
exit 0
|
2016-07-10 14:32:35 +02:00
|
|
|
}
|
|
|
|
|
2016-10-09 11:07:24 +02:00
|
|
|
unset input_file
|
|
|
|
unset input_hash
|
|
|
|
|
2016-10-08 11:47:43 +02:00
|
|
|
while getopts ":hi:m:" opt; do
|
2016-12-31 11:04:15 +01:00
|
|
|
case "${opt}" in
|
|
|
|
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
|
2016-10-08 11:47:43 +02:00
|
|
|
done
|
|
|
|
|
2016-10-09 11:07:24 +02:00
|
|
|
[[ -z "${#}" || ! ${input_file} || ! ${input_hash} ]] && _output_prompt
|
2016-10-08 11:47:43 +02:00
|
|
|
echo -e "${BLUE}Please wait...${NC}"
|
|
|
|
unset md5_tmp
|
|
|
|
if [[ $OSTYPE = "cygwin" ]]; then
|
2016-12-31 11:04:15 +01:00
|
|
|
md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp""
|
2016-10-08 11:47:43 +02:00
|
|
|
else
|
2016-12-31 11:04:15 +01:00
|
|
|
md5_tmp="${HOME}/$(basename ${input_hash}).tmp"
|
2016-10-08 11:47:43 +02:00
|
|
|
fi
|
|
|
|
$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp})
|
2016-12-31 11:04:15 +01:00
|
|
|
[[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error: '${input_file}' is not a valid audio-visual file.${NC}" ; _output_prompt ; }
|
2016-10-09 11:07:24 +02:00
|
|
|
unset old_file
|
|
|
|
unset tmp_file
|
2016-10-08 11:47:43 +02:00
|
|
|
old_file=$(grep -v '^#' ${input_hash})
|
|
|
|
tmp_file=$(grep -v '^#' ${md5_tmp})
|
|
|
|
if [[ "${old_file}" = "${tmp_file}" ]]; then
|
2016-12-31 11:04:15 +01:00
|
|
|
echo -e "${BLUE}'$(basename ${input_file})' matches '$(basename ${input_hash})'${NC}"
|
|
|
|
rm "${md5_tmp}"
|
2016-10-08 11:47:43 +02:00
|
|
|
else
|
2016-12-31 11:04:15 +01:00
|
|
|
echo -e "${RED}The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':${NC}"
|
|
|
|
diff "${input_hash}" "${md5_tmp}"
|
|
|
|
rm "${md5_tmp}"
|
2016-10-08 11:47:43 +02:00
|
|
|
fi
|