2016-07-10 14:35:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2016-07-23 16:48:18 +02:00
|
|
|
SCRIPT=$(basename "${0}")
|
2016-07-25 17:56:10 +02:00
|
|
|
VERSION='2016-07-25'
|
2016-07-10 15:01:00 +02:00
|
|
|
AUTHOR='ffmprovisr'
|
2016-07-10 14:32:35 +02:00
|
|
|
RED='\033[1;31m'
|
|
|
|
BLUE='\033[1;34m'
|
|
|
|
NC='\033[0m'
|
|
|
|
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt() {
|
2016-07-10 14:32:35 +02:00
|
|
|
cat <<END_OF_MSG
|
2016-07-23 16:48:18 +02:00
|
|
|
Usage: ${SCRIPT} [-h | <av_file> <md5_file>]
|
2016-07-10 14:32:35 +02:00
|
|
|
END_OF_MSG
|
|
|
|
}
|
|
|
|
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_help() {
|
2016-07-10 14:32:35 +02:00
|
|
|
cat <<END_OF_MSG
|
|
|
|
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-07-10 14:32:35 +02:00
|
|
|
END_OF_MSG
|
|
|
|
}
|
|
|
|
|
2016-07-23 16:48:18 +02:00
|
|
|
if [[ $OSTYPE == "cygwin" ]] || [ ! $(which diff) ] ; then
|
2016-07-10 14:32:35 +02:00
|
|
|
echo -e "${RED}ERROR:${NC} diff is not installed by default. Please install diffutils from Cygwin."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-07-25 17:56:10 +02:00
|
|
|
if [ "${#}" -eq 0 ]; then
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 0
|
2016-07-25 17:56:10 +02:00
|
|
|
elif [ "${#}" -eq 1 ]; then
|
|
|
|
if [ "${1}" == '-h' ]; then
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_help
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo -e "${RED}ERROR:${NC} '$1' is an invalid argument."
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-07-25 17:56:10 +02:00
|
|
|
elif [ "${#}" -eq 2 ]; then
|
|
|
|
if ! [ -f "${1}" ]; then
|
|
|
|
echo -e "${RED}ERROR:${NC} There is no file '$(basename ${1})'."
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 1
|
2016-07-25 17:56:10 +02:00
|
|
|
elif ! [ -f "${2}" ]; then
|
|
|
|
echo -e "${RED}ERROR:${NC} There is no file '$(basename ${2})'."
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 1
|
|
|
|
else
|
2016-07-24 13:47:43 +02:00
|
|
|
unset md5_tmp
|
2016-07-10 14:32:35 +02:00
|
|
|
if [[ $OSTYPE == "cygwin" ]]; then
|
2016-07-25 17:57:37 +02:00
|
|
|
md5_tmp=""${USERPROFILE}/$(basename ${2}).tmp""
|
2016-07-10 14:32:35 +02:00
|
|
|
else
|
2016-07-25 17:56:10 +02:00
|
|
|
md5_tmp="${HOME}/$(basename ${2}).tmp"
|
2016-07-10 14:32:35 +02:00
|
|
|
fi
|
2016-07-23 16:48:18 +02:00
|
|
|
echo "Please wait..."
|
2016-07-25 17:56:10 +02:00
|
|
|
$(ffmpeg -y -i ${1} -loglevel 0 -f framemd5 -an ${md5_tmp})
|
|
|
|
old_file=$(grep -v '^#' ${2})
|
|
|
|
tmp_file=$(grep -v '^#' ${md5_tmp})
|
|
|
|
if [ "${old_file}" = "${tmp_file}" ]; then
|
|
|
|
echo -e "${BLUE}OK${NC} '$(basename ${1})' matches '$(basename ${2})'."
|
2016-07-24 13:47:43 +02:00
|
|
|
exit 0
|
2016-07-10 14:32:35 +02:00
|
|
|
else
|
2016-07-25 17:56:10 +02:00
|
|
|
echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${1})' and '$(basename ${2})':"
|
|
|
|
diff "${2}" "${md5_tmp}"
|
2016-07-24 13:47:43 +02:00
|
|
|
exit 1
|
2016-07-10 14:32:35 +02:00
|
|
|
fi
|
2016-07-25 17:56:10 +02:00
|
|
|
rm "${md5_tmp}"
|
2016-07-10 14:32:35 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e "${RED}ERROR:${NC} Too many arguments."
|
2016-07-24 13:47:43 +02:00
|
|
|
_output_prompt
|
2016-07-10 14:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|