-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathingestfile
executable file
·223 lines (192 loc) · 7.62 KB
/
ingestfile
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
#!/bin/bash
# ingestfile
# select an audiovisual file, package it, and transcode it
version="1.0"
makeaccesscopies="Y" # use 'Y' for yes or any other character for no
blackframetest="Y" # use 'Y' for yes or any other character for no
deliverytoomneon="Y" # use 'Y' for yes or any other character for no
deliveraccesscopies="Y" # use 'Y' for yes or any other character for no
deliverytoaipstorage="Y" # use 'Y' for yes or any other character for no
scriptdir=`dirname "$0"`
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
usage(){
echo
echo "$(basename $0) ${version}"
echo "This script may be run interactively by running it with no arguments or may be used with the following options."
echo "Usage: $(basename $0) [ -m mediaid ] [ -f input] [ -p processing_directory ] [-a AIP_storage_directory ] [-w podcast_delivery ] [-y youtube_delivery ] [-x Regex ] [ -l audiodecision ] [ -c cleanupdecision ] [ -o operator ] [ -q priority ]"
echo " -m mediaid"
echo " -f input"
echo " -p processing directory. Transcoding will happen here."
echo " -a Archive Information Package storage directory. Final package delivery location."
echo " -w podcast delivery"
echo " -y youtube delivery"
echo " -x Regex will identify applicability of various services."
echo " -l Use only left channel of source video in transcoding."
echo " -c Remove source file after successful ingest."
echo " -q Put in queue."
exit
}
# command-line options to set mediaid and original variables
while getopts ":hm:f:p:a:w:y:xlco:q" opt; do
case "$opt" in
h) usage ;;
m) mediaid="$OPTARG";;
f) input="$OPTARG";;
p) OUTDIR_INGESTFILE="$OPTARG" ;;
a) AIP_STORAGE="$OPTARG" ;;
w) PODCASTDELIVER="$OPTARG" ;;
y) YOUTUBEDELIVER="$OPTARG" ;;
x) REGEX4PODCAST ;;
l) audiodecision="left" ;;
c) cleanupdecision="Y" ;;
o) op="$OPTARG" ;;
q) priority="put in queue" ;;
\?) echo "Invalid option: -$OPTARG" ; exit 1 ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
[ ! -d "$OUTDIR_INGESTFILE" ] && echo "The processing directory must be set. Use [ -p /path/to/processing/directory ]." && exit 1
[ ! -d "$AIP_STORAGE" ] && echo "The AIP Storage directory must be set. Use [ -a /path/to/AIP/storage/directory ]." && exit 1
[ ! -d "$PODCASTDELIVER" ] && echo "An access file for podcast delivery must be set. Use [ -w /path/to/objects/access/podcast]." && exit 1
[ ! -d "$YOUTUBEDELIVER" ] && echo "An access file for youtube delivery must be set. Use [ -y /path/to/objects/access/youtube_up/]." && exit 1
[ -n "$mediaid" ] && op="batch process"
report "starting $SCRIPTNAME"
ask_operator
ask_mediaid
ask_input
log -b
if [ "$audiodecision" = "" ] ; then
report -q "Select an audio strategy? "
PS3="Selection? "
select audiodecision in "Default audio mapping [first audio track used for stereo output]" "Only use left of the first audio track [for 21st Century]"
do
break
done
fi
if [ "$cleanupdecision" = "" ] ; then
report -q "Select an cleanup strategy? "
PS3="Selection? "
select cleanupdecision in "Leave source file where it is." "Remove source file after successful ingest"
do
break
done
if [ "$cleanupdecision" = "Remove source file after successful ingest" ] ; then
cleanup="Y"
fi
fi
if [ "$priority" = "" ] ; then
report -q "Select an multitasking strategy? "
PS3="Selection? "
select priority in "put in queue" "start now"
do
break
done
fi
# blackframe analysis
if [ "$blackframetest" = "Y" ] ; then
black_at_ends "$input"
if [ "$head_black" -gt "30" ] ; then
report -wt "WARNING - There are at least $head_black frames of black at the beginning of ${input}"
report -qn "Enter q to quit, any other key to continue: "
read a1
[ "$a1" == "q" ] && exit 0
fi
if [ "$tail_black" -gt "30" ] ; then
report -wt "WARNING - There are at least $tail_black frames of black at the end of ${input}"
report -qn "Enter q to quit, any other key to continue: "
read a2
[ "$a2" == "q" ] && exit 0
fi
fi
objectsdir="$OUTDIR_INGESTFILE/$mediaid/objects"
# check for existing output
[ -d "$OUTDIR_INGESTFILE/$mediaid" ] && report -wt "It looks like $mediaid was already ingested. If you want to overwrite the existing one please delete $OUTDIR_INGESTFILE/$mediaid first and then try again." && exit 1
[ -d "$AIP_STORAGE/$mediaid" ] && report -wt "It looks like $mediaid was already ingested. If you want to overwrite the existing one please delete $AIP_STORAGE/$mediaid first and then try again." && exit 1
# queue handling
if [ "$priority" = "put in queue" ] ; then
echo "$mediaid" >> /tmp/queue.txt
next=$(head -n 1 /tmp/queue.txt)
while [ "$mediaid" != "$next" ] ; do
newnext=$(head -n 1 /tmp/queue.txt)
echo -n "This process is waiting behind these identifiers: "
cat /tmp/queue.txt | tr '\n' ' '
echo
while [ "$next" = "$newnext" ] ; do
sleep 10
newnext=$(head -n 1 /tmp/queue.txt)
done
next="$newnext"
done
fi
mkdir -p "$objectsdir"
logdir="$OUTDIR_INGESTFILE/$mediaid/metadata/submissionDocumentation/logs"
mkdir -p "$logdir"
submissiondocdir="$OUTDIR_INGESTFILE/$mediaid/metadata/submissionDocumentation"
mkdir -p "$submissiondocdir"
start=`get_iso8601`
# rsync
report -dt "STATUS Copying the original file to library storage at $objectsdir."
rsync -rtv --progress --log-file="$logdir/rsync_$(get_iso8601_c)_$(basename $0)_${version}.txt" "$input" "$objectsdir/"
rsync_err="$?"
[ "$rsync_err" -gt "0" ] && report -wt "rsync failed with error ${rsync_err}" && exit 1
# transcode
if [ "$audiodecision" == "Only use left of the first audio track [for 21st Century]" -o "$audiodecision" == "left" ] ; then
"$scriptdir/makebroadcast" -l "$OUTDIR_INGESTFILE/$mediaid"
else
"$scriptdir/makebroadcast" "$OUTDIR_INGESTFILE/$mediaid"
fi
# upload to omneon
if [ "$deliverytoomneon" == "Y" ] ; then
report -dt "STATUS Uploading $servicefile to the OMNEON."
"$scriptdir/uploadomneon" "$objectsdir/service/${mediaid%.*}.mov"
fi
# access copies
if [ "$makeaccesscopies" == "Y" ] ; then
report -dt "STATUS Making access copies."
"$scriptdir/makedvd" "$OUTDIR_INGESTFILE/$mediaid"
"$scriptdir/makeyoutube" "$OUTDIR_INGESTFILE/$mediaid"
if [ "$deliveraccesscopies" = "Y" ] ; then
cp -av "$OUTDIR_INGESTFILE/$mediaid/objects/access/youtube_up/" "$YOUTUBEDELIVER/"
fi
if [ `echo "$mediaid" | grep "$REGEX4PODCAST"` ] ; then
report -dt "${media} qualifies for podcast creation."
sh "$scriptdir/makepodcast" "$OUTDIR_INGESTFILE/$mediaid"
if [ "$deliveraccesscopies" == "Y" ] ; then
cp -av "$OUTDIR_INGESTFILE/$mediaid/objects/access/podcast/" "$PODCASTDELIVER/"
fi
else
report -dt "${media} does NOT qualify for podcast creation, skipping."
fi
fi
end=`get_iso8601`
# start reporting to operator log
echo -e "$log" >> "$logdir/capture.log"
echo "datetime_start: ${start}" >> "$logdir/capture.log"
echo "datetime_end: ${end}" >> "$logdir/capture.log"
# move and cleanup
if [ "$deliverytoaipstorage" == "Y" ] ; then
rsync -rtv --progress --remove-source-files "$OUTDIR_INGESTFILE/$mediaid" "$AIP_STORAGE/"
[ `du -s "$OUTDIR_INGESTFILE/$mediaid" | awk '{print $1}'` = "0" ] && rm -r "$OUTDIR_INGESTFILE/$mediaid"
report -dt "STATUS Done. Final package has been delivered to $AIP_STORAGE/${mediaid}"
fi
if [ "$cleanup" == "Y" ] ; then
if [ "$rsync_err" -gt "0" ] ; then
report -wt "Cancelling requested deletion of source file, not looking safe."
else
report -dt "Removing the source file from ${input} as requested."
rm -f "$input"
fi
fi
# clean up queue
if [ "$priority" == "put in queue" ] ; then
tail -n +2 /tmp/queue.txt > /tmp/queue2.txt
rm /tmp/queue.txt
mv /tmp/queue2.txt /tmp/queue.txt
fi
done
log -e