forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makemetadata
executable file
·68 lines (63 loc) · 2.52 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
#!/bin/bash
# make metadata
version="0.2"
scriptdir=$(dirname $(which "${0}"))
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffprobe mediainfo 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)"
exit
}
[ "${#}" = 0 ] && usage
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":h" opt ; do
case "${opt}" in
h) usage ;;
*) echo "bad option -${OPTARG}" ; usage ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
_log -b
outputdir="./metadata/submissionDocumentation/fileMeta"
if [ ! -d "${outputdir}" ] ; then
_run mkdir -p "${outputdir}"
fi
while [ "${*}" != "" ] ; do
package_path="${1}"
pwd=$(pwd)
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"
FFPROBEJSON="$fileoutput/${filenameroot%.*}_ffprobe.json"
MEDIAINFOXML="${fileoutput}/${filenameroot%.*}_mediainfo.xml"
MEDIAINFOTRACE="${fileoutput}/${filenameroot%.*}_mediainfo_trace.txt"
EXIFTOOLXML="${fileoutput}/${filenameroot%.*}_exiftool.xml"
EXIFTOOLTXT="${fileoutput}/${filenameroot%.*}_exiftool.txt"
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}"
ffprobe 2> /dev/null "${file}" -show_format -show_streams -show_data -show_error -show_versions -show_chapters -of json > "${FFPROBEJSON}"
mediainfo --language=raw -f --output=XML "${file}" > "${MEDIAINFOXML}"
mediainfo --inform="Details;1" "$file" > "${MEDIAINFOTRACE}"
exiftool -X "${file}" > "${EXIFTOOLXML}"
exiftool "${file}" > "${EXIFTOOLTXT}"
done < "${FILELIST}"
cd "${pwd}"
_run rm -r -f "${FILELIST}"
shift
_log -e
done