-
Notifications
You must be signed in to change notification settings - Fork 2
/
repro-vidsort
executable file
·191 lines (153 loc) · 4.11 KB
/
repro-vidsort
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
#!/usr/bin/env bash
vidsroot=/inbox/VIDS
inbox=${vidsroot}/incoming
orphans=${vidsroot}/orphans
dcms=/inbox/DICOM
dflt_owner=root
dflt_bids=bids
#accStem="A00" # Trying without this
process_video () {
v=$1
# If this is a stub exit
isstub=`grep -q '_.mp4' <<< $v && echo $? || echo $?`
if [[ $isstub == 0 ]]
then
rm $inbox/$v
return 0
fi
# Get the details about when video was captured
sameyear=1
samemonth=1
sameday=1
a=`echo $v | awk -F _ '{print $1}'`
b=`echo $v | awk -F _ '{print $2}'`
ya=`echo $a | awk -F . '{print $1}'` # year
yb=`echo $b | awk -F . '{print $1}'`
ma=`echo $a | awk -F . '{print $2}'` # month
mb=`echo $b | awk -F . '{print $2}'`
da=`echo $a | awk -F . '{print $3}'` # day
db=`echo $b | awk -F . '{print $3}'`
# Check Day
# check_day function checks to see that beginning and end times are on the
# same day, and if they are not, ( which should only regularly happen when
# the video begins before midnight and ends after ), it changes the add24h
# variable from 0 to 1224
add24h=0
check_day () {
echo $1 $2
echo $(( 31 - "$1" ))
if [ $(( "$2" - "$1" )) -eq 1 ]
then
add24h=$(( 24 * 60 ))
elif [ $(( 31 - "$1" )) -lt 4 ] && [ "$2" = "01" ]
then
add24h=$(( 24 * 60 ))
else
# exists whenever there is more than a whole day
d=`date`
echo "$d: Incomprehensible dates for $3"
return 1
fi
}
if [ "$da" != "$db" ]; then check_day $da $db $v; fi
# get running time in minutes
# video time: $vt1 $vt2
vt1=`echo $a | awk -F . '{ print $4 * 60 + $5 }'`
vt2=`echo $b | awk -F . '{ print $4 * 60 + $5 }'`
vt2=$(( $vt2 + $add24h ))
viddir=${vidsroot}/${ya}/${ma}/${da}/
dcmdir=${dcms}/${ya}/${ma}/${da}
# This uses an acquisistion stem of "A00" which is almost definitely
# specific to Dartmouth. Its use is meant to reject possible test or quality
# assurance acquisitions from getting assigned an videos. I will try to
# avoid this. and revert back if it fails.
#acqs=`ls -d $dcmdir/${accStem}* 2>/dev/null`
acqs=`ls -d $dcmdir/* 2>/dev/null`
echo $acqs
if [ ${#acqs} == 0 ]
then
echo `date` :"\t"$v "--> Moving to Orphans"
mkdir -p $orphans
mv $inbox/$v $orphans
return 0
fi
x=0
matches=""
nmatches=0
for ac in $acqs
do
acbeg=`ls -l $ac | grep func | head -n 1| awk '{print $8}' | awk -F : '{t=$1*60+$2; print t}'`
acend=`ls -l $ac | grep func | tail -n 1| awk '{print $8}' | awk -F : '{t=$1*60+$2; print t}'`
if [ $(( "$vt1" )) -gt $(( "$acend" )) ]
then
x=1 # pass/continue
elif [ $(( "$acbeg" )) -gt $(( "$vt2" )) ]
then
x=2 # pass/continue
else
d=`date`
echo "$d $v: Found match --> $ac"
matches="$matches $ac"
nmatches=$(( $nmatches + 1 ))
fi
done
if [ $(( "$nmatches" )) -gt 0 ]
then
echo `date` "Found $nmatches "
for m in $matches
do
echo "\t ---> $m"
done
else
mv $inbox/$v $orphans
return 0
fi
if [[ "$nmatches" == 1 ]]
then
ac=`echo ${matches} | awk -F / '{print $7}'`
mkdir -p ${viddir}$ac
ownr=`ls -ld ${matches} | awk '{print $4}'`
chown ${dftl_owner}:${ownr} ${viddir}$ac
mv $inbox/$v ${viddir}$ac
chown -R ${dftl_owner}:${ownr} ${viddir}$ac
echo "-------------------------------------------------------------------"
else
acs=""
for match in $matches
do
ownr=`ls -ld ${match} | awk '{print $4}'`
ac=`echo ${match} | awk -F / '{print $7}'`
if [ ${#acs} == 0 ]
then
acs=${ac}
else
acs=${acs}_${ac}
fi
echo "===================================================================="
done
for match in $matches
do
own=`ls -ld ${match} | awk '{print $4}'`
if [ ${own} != ${ownr} ]
then
d=`date`
mkdir -p ${viddir}unassigned
mv $inbox/$v ${viddir}unassigned
echo "$d $inbox/$v --> ${viddir}unassigned"
chown -R ${dftl_owner}:${dflt_bids} ${viddir}unassigned
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
exit 0
else
x=3 # pass/continue
fi
done
mkdir -p ${viddir}${acs}
mv $inbox/$v ${viddir}${acs}
chown -R ${dflt_owner}:${ownr} ${viddir}${acs}
fi
}
vids=`ls $inbox`
for vid in $vids
do
process_video $vid
done