forked from vermaden/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoto-rename-movies.sh
executable file
·71 lines (67 loc) · 1.9 KB
/
photo-rename-movies.sh
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
#! /bin/sh
NUMBER=96
for EXTENSIONS in MP4 mkv
do
COUNT="-1"
COUNT=$( ls *.${EXTENSIONS} 2> /dev/null | wc -l | tr -d ' ' )
if [ "${COUNT}" = "0" ]
then
COUNT="-1"
continue
fi
for FILE in *.${EXTENSIONS}
do
SHORT=$( echo "${FILE}" | awk -F '.' '{print $1}' )
EXT=$( echo "${FILE}" | sed 's/.*\.//' )
# UNHASH FOR DEBUG
# echo "FILE: ${FILE}"
# echo "SHORT: ${SHORT}"
# echo "EXT: ${EXT}"
for TRY in ${SHORT}M01.XML \
${SHORT}m01.xml \
${SHORT}.XML \
${SHORT}.xml
do
if [ -f "${TRY}" ]
then
# UNHASH FOR DEBUG
# echo "TRY: ${TRY}"
# 2017-01-29T18:00:08Z
NEW=$( cat ${TRY} | grep CreationDate )
NEW=$( echo ${NEW} | awk -F '"' '{print $2}' )
NEW=$( echo ${NEW} | awk -F 'T' '{print $1}' )
NEW=$( echo ${NEW} | tr '-' '.' )
NEWTIME=$( cat ${TRY} | grep CreationDate )
NEWTIME=$( echo ${NEWTIME} | awk -F '"' '{print $2}' )
NEWTIME=$( echo ${NEWTIME} | awk -F 'T' '{print $2}' )
NEWTIME=$( echo ${NEWTIME} | awk -F ':' '{print $1 "" $2}' )
# UNHASH FOR DEBUG
# echo NEW: ${NEW}
# echo NEWTIME: ${NEWTIME}
# echo PREVIOUS: ${PREVIOUS}
if [ "${NEW}.${NEWTIME}" != "${PREVIOUS}" ]
then
NUMBER=96
PREFIX=0
else
PREFIX=1
NUMBER=$(( ${NUMBER} + 1 ))
fi
PRINTABLE=$( printf "\\$(printf %o ${NUMBER})\n" )
case ${PREFIX} in
(0)
mv -v "${FILE}" "${NEW}.${NEWTIME}.${EXT}"
mv -v "${TRY}" "${NEW}.${NEWTIME}.XML"
;;
(1)
mv -v "${FILE}" "${NEW}.${NEWTIME}${PRINTABLE}.${EXT}"
mv -v "${TRY}" "${NEW}.${NEWTIME}${PRINTABLE}.XML"
;;
esac
PREVIOUS="${NEW}.${NEWTIME}"
break
fi
done
done
done
echo '1' >> ~/scripts/stats/${0##*/}