2016-07-10 14:35:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2016-07-23 16:48:18 +02:00
|
|
|
SCRIPT=$(basename "${0}")
|
2016-10-02 21:02:31 +02:00
|
|
|
VERSION='2016-10-02'
|
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-10-01 07:33:22 +02:00
|
|
|
if [[ $OSTYPE = "cygwin" ]] || [ ! $(which diff) ]; then
|
2016-10-01 16:32:29 +02:00
|
|
|
echo -e "${RED}ERROR:${NC} 'diff' is not installed by default. Please install 'diffutils' from Cygwin."
|
2016-10-01 07:33:22 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
_output_prompt(){
|
|
|
|
cat <<EOF
|
2016-07-23 16:48:18 +02:00
|
|
|
Usage: ${SCRIPT} [-h | <av_file> <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-07-23 16:48:18 +02:00
|
|
|
${SCRIPT} <av_file> <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-02 20:58:17 +02:00
|
|
|
while getopts ":hi:c:" opt; do
|
|
|
|
case $opt in
|
|
|
|
h) output_help ;;
|
|
|
|
i) input_file=$OPTARG ;;
|
|
|
|
c) input_hash=$OPTARG ;;
|
|
|
|
*) echo "bad option -${OPTARG}" ; output_prompt ;;
|
|
|
|
:) echo "Option -${OPTARG} requires an argument" ; output_prompt ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -z "$@" ] && output_prompt
|
|
|
|
|
|
|
|
echo -e "${BLUE}Please wait...${NC}"
|
|
|
|
unset md5_tmp
|
|
|
|
if [[ $OSTYPE = "cygwin" ]]; then
|
|
|
|
md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp""
|
|
|
|
else
|
|
|
|
md5_tmp="${HOME}/$(basename ${input_hash}).tmp"
|
|
|
|
fi
|
|
|
|
$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp})
|
|
|
|
if [[ ! -f ${md5_tmp} ]]; then
|
|
|
|
echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file."
|
|
|
|
output_prompt
|
|
|
|
fi
|
|
|
|
old_file=$(grep -v '^#' ${input_hash})
|
|
|
|
tmp_file=$(grep -v '^#' ${md5_tmp})
|
|
|
|
if [[ "${old_file}" = "${tmp_file}" ]]; then
|
|
|
|
echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'."
|
|
|
|
rm "${md5_tmp}"
|
|
|
|
exit 0
|
2016-07-10 14:32:35 +02:00
|
|
|
else
|
2016-10-02 20:58:17 +02:00
|
|
|
echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':"
|
|
|
|
diff "${input_hash}" "${md5_tmp}"
|
|
|
|
rm "${md5_tmp}"
|
|
|
|
exit 1
|
2016-07-10 14:32:35 +02:00
|
|
|
fi
|