forked from NMAAHC/nmaahcmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restructureDPX
executable file
·335 lines (320 loc) · 16.1 KB
/
restructureDPX
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/env bash
# a script to create a the desired directory structure and filenames for DPX packages received from VFS
# load nmaahcmmfunctions into this script
SCRIPT_PATH="${0%/*}"
. "${SCRIPT_PATH}/nmaahcmmfunctions"
[[ -f "${SCRIPT_PATH}/nmaahcmmfunctions" ]] || { echo "Missing '${SCRIPT_PATH}/nmaahcmmfunctions'. Exiting." ; exit 1 ;};
_initialize_make # safe script termination process defined in nmaahcmmfunctions
RSYNC_ERROR_COUNT=0
RSYNC_ERROR_FILES=""
LOG="${LOGDIR%/}/$(basename "${0}")_$(date +%F-%H%M%S).log"
### USAGE
_usage(){
echo
echo "$(basename "${0}")"
echo "This application will create a the desired directory structure and filenames for DPX packages received from VFS."
echo "The options below are optional; simply run '$(basename ${0})' if you would prefer to be prompted for each input."
echo "Usage: $(basename ${0}) [ -d /path/to/deliver/to/ ] [ -i DPX_Object_ID ] [ -t DPX_Object_Title ] [ -r (number of reels) ] [ -c ] dpxpackage"
echo " -d directory (directory to deliver the resulting package to)"
echo " -i DPX_Object_ID (ex. 2012_79_1_54)"
echo " -t DPX_Object_Title (ex. Something_to_Build_On)"
echo " -r number (number of reels in the package, up to 3)"
echo " -c cleanup source files (remove all source files after script runs)"
echo " -h (display this help)"
echo
exit
}
# getopts loop
OPTIND=1
while getopts ":d:i:t:r:ch" OPT; do
case "${OPT}" in
d) DELIVERDIR="${OPTARG}" && _check_deliverdir ;; # _check_DELIVERDIR defined in nmaahcmmfunctions
i) DPXID="${OPTARG}" ;;
t) TITLE="${OPTARG}" ;;
r) REELNUMBER="${OPTARG}" ;;
c) CLEANUPDECISION="Y" ;;
h) _usage ;; # if the operator runs "[scriptname] -h" then the _usage text above will display in the terminal
*) echo "Invalid option -${OPTARG}" ; _usage ;; # if the operator tries to use an option other than the ones listed above, the _usage text will display in the terminal
esac
done
shift $(( ${OPTIND} - 1 ))
### FUNCTIONS
# if rsync output code indicates a failed transfer, increment the total number of failed transfers; rsync -v will also report this information in the terminal
_restructureDPX(){
INPUT="${1}"
if [[ -z "${REELNUMBER}" ]] ; then
_report -b "Please enter the number of reels your DPX package has:"
read -r REELNUMBER
echo
fi
if [[ -z "${DPXID}" ]] ; then
_report -b "Please enter DPX_Object_ID_Number with underscores:"
_report -b "ex. 2015_167_10_1"
read -r DPXID
echo
fi
if [[ -z "${TITLE}" ]] ; then
_report -b "Please enter DPX_Object_Title with underscores:"
_report -b "ex. Juke_Joint"
read -r TITLE
echo
fi
if [[ -z "${DELIVERDIR}" ]] ; then
_report -b "Please drag in the full path to the destination (where the new directory should be created):"
read -r DELIVERDIR
echo
fi
if [[ -z "${INPUT}" ]] ; then
_report -b "Please drag in the full path to the input directory:"
read -r INPUT
echo
fi
MEDIAID="${DPXID}__${TITLE}"
OUTPUTDIR="${DELIVERDIR}/${MEDIAID}"
mkdir "${OUTPUTDIR}"
# record variables in ingest log
_writelog "DPX ID" "${DPXID}"
_writelog "TITLE" "${TITLE}"
_writelog "MEDIAID" "${MEDIAID}"
_writelog "REELS" "${REELNUMBER}"
_writelog "INPUT" "${INPUT}"
_writelog "START TIME" "$(date +%FT%T)"
case "${REELNUMBER}" in
1 )
if [[ -d "${OUTPUTDIR}" ]] ; then
# remove any .DS_Store files to begin
"${SCRIPTDIR}/removeDSStore" "${OUTPUTDIR}"
# move wav directory and rename in standard format
for WAVPATH in "${INPUT}"/*WAV ; do
if [[ ! -d "${WAVPATH}" ]]; then
_report -rt "No .wav directory found."
else
AUDPATH=("${OUTPUTDIR}/${DPXID}__${TITLE}__Audio")
_report -g "Found .wav directory ${WAVPATH}"
mkdir -p "${AUDPATH}"
fi
done
# move mov directory and rename in standard format
for MOVPATH in "${INPUT}"/*MOV ; do
if [[ ! -d "${MOVPATH}" ]] ; then
_report -rt "No .mov directory found."
else
DER=("${OUTPUTDIR}/${DPXID}__${TITLE}__Derivatives")
_report -g "Found .mov directory ${MOVPATH}"
mkdir -p "${DER}"
fi
done
# move dpx directory and rename in standard format
for DPXPATH in "${INPUT}"/*DPX ; do
if [[ ! -d "${DPXPATH}" ]] ; then
_report -rt "No DPX directory found."
else
DPX=("${OUTPUTDIR}/${DPXID}__${TITLE}__DPX")
_report -g "Found DPX directory ${DPXPATH}"
mkdir -p "${DPX}"
fi
done
else
_report -rt "ERROR: ${OUTPUTDIR} does not exist. Exiting..."
_log -a "Process terminated by script (no directory at requested location)."
exit 1
fi
# find and move audio, derivatives, and DPX files. Finds files based on filenaming + extension; assumes each file will have reel # in filename + regular extension.
_report -g "Moving files from ${INPUT} to ${OUTPUTDIR}"
for file in $(find "${INPUT}" -iname "*.wav") ; do
rsync -avch --progress "${file}" "${AUDPATH}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*.mov") ; do
rsync -avch --progress "${file}" "${DER}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*.dpx") ; do
rsync -avch --progress "${file}" "${DPX}"
_check_rsync_output
done
# find the .wav and .mov files and rename them according to NMAAHC naming structures. Finds files based on filenaming + extension; assumes each file will have descriptive filename + regular extension.
_report -g "Renaming files in ${OUTPUTDIR}"
if [[ -d "${AUDPATH}" ]] ; then
find "${AUDPATH}" -iname "*.wav" -exec mv -i "{}" "${AUDPATH}/${DPXID}_AUD.wav" \;
WAV="${AUDPATH}/${DPXID}_AUD.wav"
_report -g "Renamed audio file to ${WAV}"
fi
if [[ -d "${DER}" ]] ; then
find "${DER}" -iname "*ProRes*.mov" -exec mv -i "{}" "${DER}/${DPXID}_DER_01.mov" \;
DER1="${DER}/${DPXID}_DER_01.mov"
_report -g "Renamed ProRes file to ${DER1}"
fi
if [[ -d "${DER}" ]] ; then
find "${DER}" -iname "*Uncompressed.mov" -exec mv -i "{}" "${DER}/${DPXID}_DER_02.mov" \;
DER2="${DER}/${DPXID}_DER_02.mov"
_report -g "Renamed uncompressed file to ${DER2}"
echo
fi
;;
2 )
# make separate subdirectories for R1 and R2, with further subdirectories for the different components
R1=("${OUTPUTDIR}/${MEDIAID}_R1")
AUD_R1="${R1}/${MEDIAID}_R1__Audio"
DER_R1="${R1}/${MEDIAID}_R1__Derivatives"
DPXR1="${R1}/${MEDIAID}_R1__DPX"
R2=("${OUTPUTDIR}/${MEDIAID}_R2")
AUD_R2="${R2}/${MEDIAID}_R2__Audio"
DER_R2="${R2}/${MEDIAID}_R2__Derivatives"
DPXR2="${R2}/${MEDIAID}_R2__DPX"
mkdir -p "${R1}" "${AUD_R1}" "${DER_R1}" "${DPXR1}" "${R2}" "${AUD_R2}" "${DER_R2}" "${DPXR2}"
MKDIR_ERR="${?}"
if [[ "${MKDIR_ERR}" -gt 0 ]] ; then
_report -rt "Not all directories were created. Please double check that you have write permission to output directory ${OUTPUTDIR}"
exit 1
_log -a "Process terminated by script (directories not created)."
else
echo
# find and move audio, derivatives, and DPX files for each reel in turn. Finds files based on filenaming + extension; assumes each file will have reel # in filename + regular extension.
_report -g "Moving files from ${INPUT} to ${OUTPUTDIR}"
for file in $(find "${INPUT}" -iname "*R1*.wav") ; do
rsync -avch --progress "${file}" "${AUD_R1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R1*.mov") ; do
rsync -avch --progress "${file}" "${DER_R1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R1*.dpx") ; do
rsync -avch --progress "${file}" "${DPXR1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.wav") ; do
rsync -avch --progress "${file}" "${AUD_R2}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.mov") ; do
rsync -avch --progress "${file}" "${DER_R2}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.dpx") ; do
rsync -avch --progress "${file}" "${DPXR2}"
_check_rsync_output
done
echo
# rename files according to NMAAHC filenaming guidelines
_report -g "Renaming files in ${OUTPUTDIR}"
find "${AUD_R1}" -iname "*R1*.wav" -exec mv -vi {} "${AUD_R1}/${DPXID}_R1_AUD.wav" \;
find "${DER_R1}" -iname "*R1*ProRes*.mov" -exec mv -vi {} "${DER_R1}/${DPXID}_R1_DER_01.mov" \;
find "${DER_R1}" -iname "*R1*Uncompressed*.mov" -exec mv -vi {} "${DER_R1}/${DPXID}_R1_DER_02.mov" \;
find "${AUD_R2}" -iname "*R2*.wav" -exec mv -vi {} "${AUD_R2}/${DPXID}_R2_AUD.wav" \;
find "${DER_R2}" -iname "*R2*ProRes*.mov" -exec mv -vi {} "${DER_R2}/${DPXID}_R2_DER_01.mov" \;
find "${DER_R2}" -iname "*R2*Uncompressed*.mov" -exec mv -vi {} "${DER_R2}/${DPXID}_R2_DER_02.mov" \;
fi
;;
3 )
# make separate subdirectories for R1, R2, and R3, with further subdirectories for the different components
R1=("${OUTPUTDIR}/${MEDIAID}_R1")
AUD_R1="${R1}/${MEDIAID}_R1__Audio"
DER_R1="${R1}/${MEDIAID}_R1__Derivatives"
DPXR1="${R1}/${MEDIAID}_R1__DPX"
R2=("${OUTPUTDIR}/${MEDIAID}_R2")
AUD_R2="${R2}/${MEDIAID}_R2__Audio"
DER_R2="${R2}/${MEDIAID}_R2__Derivatives"
DPXR2="${R2}/${MEDIAID}_R2__DPX"
R3=("${OUTPUTDIR}/${MEDIAID}_R3")
AUD_R3="${R3}/${MEDIAID}_R3__Audio"
DER_R3="${R3}/${MEDIAID}_R3__Derivatives"
DPXR3="${R3}/${MEDIAID}_R3__DPX"
mkdir -p "${R1}" "${AUD_R1}" "${DER_R1}" "${DPXR1}" "${R2}" "${AUD_R2}" "${DER_R2}" "${DPXR2}" "${R3}" "${AUD_R3}" "${DER_R3}" "${DPXR3}"
MKDIR_ERR="${?}"
if [[ "${MKDIR_ERR}" -gt 0 ]] ; then
_report -rt "Not all directories were created. Please double check that you have write permission to output directory ${OUTPUTDIR}"
exit 1
_log -a "Process terminated by script (directories not created)."
else
true
echo
# find and move audio, derivatives, and DPX files for each reel in turn. Finds files based on filenaming + extension; assumes each file will have reel # in filename + regular extension.
_report -g "Moving files from ${INPUT} to ${OUTPUTDIR}"
for file in $(find "${INPUT}" -iname "*R1*.wav") ; do
rsync -avch --progress "${file}" "${AUD_R1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R1*.mov") ; do
rsync -avch --progress "${file}" "${DER_R1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R1*.dpx") ; do
rsync -avch --progress "${file}" "${DPXR1}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.wav") ; do
rsync -avch --progress "${file}" "${AUD_R2}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.mov") ; do
rsync -avch --progress "${file}" "${DER_R2}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R2*.dpx") ; do
rsync -avch --progress "${file}" "${DPXR2}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R3*.wav") ; do
rsync -avch --progress "${file}" "${AUD_R3}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R3*.mov") ; do
rsync -avch --progress "${file}" "${DER_R3}"
_check_rsync_output
done
for file in $(find "${INPUT}" -iname "*R3*.dpx") ; do
rsync -avch --progress "${file}" "${DPXR3}"
_check_rsync_output
done
echo
# rename files according to NMAAHC filenaming guidelines
_report -g "Renaming files in ${OUTPUTDIR}"
find "${AUD_R1}" -iname "*R1*.wav" -exec mv -vi {} "${AUD_R1}/${DPXID}_R1_AUD.wav" \;
find "${DER_R1}" -iname "*R1*ProRes*.mov" -exec mv -vi {} "${DER_R1}/${DPXID}_R1_DER_01.mov" \;
find "${DER_R1}" -iname "*R1*Uncompressed*.mov" -exec mv -vi {} "${DER_R1}/${DPXID}_R1_DER_02.mov" \;
find "${AUD_R2}" -iname "*R2*.wav" -exec mv -vi {} "${AUD_R2}/${DPXID}_R2_AUD.wav" \;
find "${DER_R2}" -iname "*R2*ProRes*.mov" -exec mv -vi {} "${DER_R2}/${DPXID}_R2_DER_01.mov" \;
find "${DER_R2}" -iname "*R2*Uncompressed*.mov" -exec mv -vi {} "${DER_R2}/${DPXID}_R2_DER_02.mov" \;
find "${AUD_R3}" -iname "*R3*.wav" -exec mv -vi {} "${AUD_R3}/${DPXID}_R3_AUD.wav" \;
find "${DER_R3}" -iname "*R3*ProRes*.mov" -exec mv -vi {} "${DER_R3}/${DPXID}_R3_DER_01.mov" \;
find "${DER_R3}" -iname "*R3*Uncompressed*.mov" -exec mv -vi {} "${DER_R3}/${DPXID}_R3_DER_02.mov" \;
fi
;;
* )
_report -rt "ERROR. Presently, this script can only handle DPX packages of 1 or 2 or 3 reels. Check back later."
echo
cowsay "SORRY!"
_log -w "Attempt to run restructureDPX with >3 reels in package."
;;
esac
}
## SCRIPT ACTIONS
# log script beginning
_log -b
_restructureDPX "${@}"
# remove input files - HARDCODED OFF DURING TESTING
# if [[ -z "${CLEANUPDECISION}" ]] ; then
# _report -b "Remove input directory? Type Y or y for yes, any other key for no: "
# read CLEANUPDECISION
# fi
# don't allow removal of input directory if there were any rsync errors
if [[ "${CLEANUPDECISION}" == [Yy] ]] ; then
if [[ "${RSYNC_ERROR_COUNT}" -eq 0 ]] ; then
true
#_report -g "Deleting input directory..."
# rm -vr "${INPUT}" # remove input directory. -v=verbose, -r=recursive - HARDCODED OFF DURING TESTING
else
_report -rt "ERROR: Not all rsync processes completed successfully. Cancelling requested deletion of input directory."
fi
fi
# summarize rsync errors for operator
if [[ "${RSYNC_ERROR_COUNT}" -gt 0 ]] ; then
_report -rt "ERROR: ${RSYNC_ERROR_COUNT} file/s experienced issues during the rsync process. Please review the rsync output in the terminal window."
fi
# log script ending
_log -e
_writelog "END TIME" "$(date +%FT%T)"
_report -g "restructureDPX process complete."
exit $?