-
Notifications
You must be signed in to change notification settings - Fork 27
/
makemetadata
executable file
·76 lines (71 loc) · 2.86 KB
/
makemetadata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# make metadata creates a set of metadata reports for an archival information package on all files in the objects subdirectory.
VERSION="0.2"
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
DEPENDENCIES=(ffprobe mediaconch exiftool)
_initialize_make
_usage(){
echo
echo "$(basename "${0}") ${VERSION}"
echo "Produces a set of metadata reports for an archival information package on all files in the objects subdirectory."
echo "Usage: $(basename "${0}") [ -h ] package1 [ package2 ... ]"
echo " -h (show usage)"
echo " -r deletes existing metadata files"
exit
}
[ "${#}" = 0 ] && _usage
# command-line option to remove existing metadata files
OPTIND=1
while getopts ":rh" OPT ; do
case "${OPT}" in
h) _usage ;;
r) DELETEFILEMETA="Y" ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
:) echo "Option -${OPTARG} requires an argument" ; _writeerrorlog "makemetadata" "The option selected required an argument and none was provided. The script had to exit." ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
_set_up_filemeta(){
_log -b
if [[ -d "${PACKAGE_PATH}/${OUTPUTDIR}" && "${DELETEFILEMETA}" != "Y" ]] ; then
_report -wt "WARNING ${PACKAGE_PATH}/${OUTPUTDIR} already exists, not making metadata."
continue
fi
_mkdir2 "${PACKAGE_PATH}/${OUTPUTDIR}"
}
_log -b
OUTPUTDIR="./metadata/fileMeta"
while [ "${*}" != "" ] ; do
PACKAGE_PATH="${1}"
MMPWD=$(pwd)
shift
_set_up_filemeta
if [[ "${DELETEFILEMETA}" = "Y" && -d "${PACKAGE_PATH}/${OUTPUTDIR}" ]] ; then
rm -rv "${PACKAGE_PATH}/${OUTPUTDIR}"
fi
cd "${PACKAGE_PATH}"
FILELIST=$(_maketemp)
find "./objects" -type f ! -name ".*" ! -path "*/access/images/*" > "${FILELIST}"
_report -dt "Making metadata reports for ${PACKAGE_PATH}."
while read FILE ; do
FILENAMEROOT=$(basename "${FILE}")
PARENTDIR=$(dirname "${FILE}")
FILEOUTPUT="${OUTPUTDIR}/${PARENTDIR}"
if [ ! -d "${FILEOUTPUT}" ] ; then
_run mkdir -p "${FILEOUTPUT}"
fi
FFPROBEXML="${FILEOUTPUT}/${FILENAMEROOT}_ffprobe.xml"
MEDIAINFOXML="${FILEOUTPUT}/${FILENAMEROOT}_mediainfo.xml"
MEDIAINFOTRACE="${FILEOUTPUT}/${FILENAMEROOT}_mediatrace.xml"
EXIFTOOLXML="${FILEOUTPUT}/${FILENAMEROOT}_exiftool.xml"
ffprobe 2> /dev/null "${FILE}" -show_format -show_streams -show_data -show_error -show_versions -show_chapters -noprivate -of xml="q=1:x=1" > "${FFPROBEXML}"
mediaconch -mi -fx "${FILE}" | xmlstarlet fo > "${MEDIAINFOXML}"
mediaconch -mi -mt -fx "${FILE}" | xmlstarlet fo > "${MEDIAINFOTRACE}"
exiftool -X "${FILE}" > "${EXIFTOOLXML}"
done < "${FILELIST}"
cd "${MMPWD}"
"${SCRIPTDIR}/makemets" "${PACKAGE_PATH}"
_run rm -r -f "${FILELIST}"
_log -e
done