Skip to content

Commit

Permalink
ADD video sorting code
Browse files Browse the repository at this point in the history
  • Loading branch information
andycon committed Dec 17, 2020
1 parent f06b288 commit b3374c7
Showing 1 changed file with 179 additions and 0 deletions.
179 changes: 179 additions & 0 deletions Parsing/repro-vidsort
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/usr/local/bin/bash

vidsroot=/inbox/VIDS
inbox=${vidsroot}/incoming
orphans=${vidsroot}/orphans
dcms=/inbox/DICOM
dflt_owner=root
dflt_bids=bids
accStem="A00"

process_video () {

v=$1

# If this is a stub exit
isstub=`grep -q '_.mkv' <<< $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
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 secs
# 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}
acqs=`ls -d $dcmdir/${accStem}* 2>/dev/null`

echo $acqs

if [ ${#acqs} == 0 ]
then
echo "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 "Found $nmatches "
for m in $matches
do
echo " $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

0 comments on commit b3374c7

Please sign in to comment.