-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhrb
executable file
·147 lines (119 loc) · 2.93 KB
/
dhrb
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set -u
VIDEO_EXTENSION=""
# nhrb = NOID, Handle, Runtime, BSN
#
# This script is meant to be run on HIDVL video objects in the R* repository
# the script assumes the standard "wip" directory structure
# foo/
# aux/
# data/6465441_marcxml.xml
# data/6465441_mods.xml
# data/foo_m.mov
# handle
#
# the script outputs the following information:
# <digitization id>,<handle URL>,<runtime>,<BSN>
#
# foo,http://hdl.handle.net/2333.1/foo,00:00:05.015,6465441
#
# this is initially designed for HIDVL objects.
err_exit() {
exit 1
}
print_usage() {
echo "usage: $0 <path to HIDVL WIP>"
echo " e.g., "
echo " $0 fasdlkf"
echo " $0 /path/to/wip/root/fasdlkf"
echo " "
echo "CSV header:"
echo "noid,handle,duration (hh:mm:ss.msec),bsn"
}
MEDIAINFO=$(which mediainfo 2>/dev/null)
if [[ "$?" != 0 ]]; then
echo "ERROR: mediainfo not found" >&2
err_exit
fi
init_runtime() {
runtime=$($MEDIAINFO -f ${wip_path}/data/*.${VIDEO_EXTENSION} | grep uration | head -5 | tail -1 | cut -d':' -f2- | sed -e 's/ //')
}
init_handle() {
handle="https://hdl.handle.net/$(cat $wip_path/handle)"
}
init_digi_id() {
digi_id=$(basename $wip_path)
}
init_bsn() {
local marcxml_path
local marcxml
marcxml_path=$(ls -1 ${wip_path}/data/*_marcxml.xml | head -1)
marcxml=$(basename $marcxml_path)
bsn=$(echo $marcxml | rev | cut -d'_' -f2 | rev)
}
assert_dir() {
if [[ ! -d "$1" ]]; then
echo "ERROR: $1 must be a directory"
print_usage
err_exit
fi
}
assert_handle() {
if [[ ! -f "${wip_path}/handle" ]]; then
echo "ERROR: handle file missing"
err_exit
fi
}
# assert that there is at least one .mov file in WIP
init_video_extension() {
VIDEO_EXTENSION=""
(ls -1 ${wip_path}/data/*.mov &>/dev/null)
if [[ "$?" == 0 ]]; then
VIDEO_EXTENSION="mov"
fi
(ls -1 ${wip_path}/data/*.mp4 &>/dev/null)
if [[ "$?" == 0 ]]; then
VIDEO_EXTENSION="mp4"
fi
if [[ "$VIDEO_EXTENSION" == "" ]]; then
echo "ERROR: no video (.mov, .mp4) files found in ${wip_path}/data" >&2
err_exit
fi
}
# assert that there is one _marcxml.xml file in WIP
assert_marcxml() {
local file_list
local file_count
file_list=$(ls -1 ${wip_path}/data/*_marcxml.xml 2>/dev/null)
if [[ "$?" != 0 ]]; then
echo "ERROR: no _marcxml.xml files found in ${wip_path}/data" >&2
err_exit
fi
if [[ $(echo "$file_list" | wc -l) -ne 1 ]]; then
echo "ERROR: too many _marcxml.xml files found in ${wip_path}/data" >&2
err_exit
fi
}
main() {
if [[ "$#" -ne 1 ]]; then
echo "ERROR: incorrect argument count"
print_usage
err_exit
fi
wip_path="$1"
assert_dir "$wip_path"
assert_handle
init_video_extension
assert_marcxml
digi_id=''
handle=''
runtime=''
bsn=''
init_digi_id
init_handle
init_runtime
init_bsn
echo "${digi_id},${handle},${runtime},${bsn}"
exit 0
}
main "$@"