-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudioaip
More file actions
executable file
·204 lines (170 loc) · 8.36 KB
/
audioaip
File metadata and controls
executable file
·204 lines (170 loc) · 8.36 KB
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
#!/bin/bash
config_file="$HOME/.$(basename "${0}").conf"
touch "${config_file}"
source "${config_file}"
_usage(){
echo
echo "usage: -h, -p, -e"
echo "(Help Mode, Photo Mode and Config mode)"
echo "This script will create an AIP from an input WAV file"
echo "To see this help type audioaip -h"
echo ""
echo "To configure syncing of files and delivery of additional access copy type audioaip -e"
echo ""
echo "To create AIP, type audioaip [dragyourfilehere] and press enter"
echo ""
echo "To create an AIP using the installed webcam to take pictures of the item's original container"
echo "type audioaip -p [dragyourfilehere] and press enter."
echo "Hold the item container in front of webcam and follow prompts."
echo "From the live preview window press Escape to take picture."
echo "There is a slight lag before the image is taken, don't move the item."
echo "After viewing your picture, press Escape to continue."
echo "If you need to retake a picture, enter r when prompted."
echo "This will allow you to retake the previous picture without while preserving filename order."
exit
}
_error_exit(){
echo -e "\033[1;32m$1\033[0m" 1>&2
exit 1
}
if [ "${*}" = "" ] ; then
_usage
fi
OPTIND=1
while getopts "hep" opt ; do
case "${opt}" in
h) _usage ;;
p) runtype="photo";;
e) runtype="edit";;
*) _usage
esac
done
shift "$(( ${OPTIND} - 1 ))"
if [[ "${runtype}" = "edit" ]] ; then
{
echo "#INSERT YOUR VALUES BETWEEN THE QUOTES AND SAVE FILE"
echo "#To control file sync change 'sync_choice' to either Y or N"
echo "#Then change destination to the file path of the desired destination"
echo "#Enter destinations (with no spaces in names) between the parentheses and separated them with spaces"
echo "sync_choice=\"$sync_choice\""
echo "destination=("${destination[@]}")"
echo ""
echo "#If you want to sync an additional access file to an extra location choose Y or N and enter file path of destination below"
echo "derivative_choice=\"${derivative_choice}\""
echo "derivative_destination=\"${derivative_destination}\""
echo ""
echo "#If you would like to append an mp3, such as a copright notice, to access copies, enter the file path for the notice here"
echo "copyright_location=\"${copyright_location}\""
echo ""
echo "#By default mediaconch verification is on. By default it will check for a 96kHz/24 bit BWF file."
echo "#To turn off type a # in front of the following line. To change policy, replace path to default policy."
echo "mediaconchsource=/usr/local/etc/audioaip_mediaconch_policy.xml"
} > "${config_file}"
mate "${config_file}" || nano "${config_file}"
exit
fi
while [ "${*}" != "" ] ; do
file_input="${1}"
shift
#Check if input exists
if [ ! -f "${file_input}" ]; then
_error_exit "Input could not be found. Please enter valid input."
fi
WAV_TEST=$(file "${file_input}" | grep "WAVE")
if [ -z "$WAV_TEST" ] ; then
_error_exit "Input is not a WAV file. Please enter valid input."
fi
#Check if input is valid (mediaconch)
if [ -n "${mediaconchsource}" ] ; then
mediaconchresult=$(mediaconch --policy="${mediaconchsource}" "${file_input}")
mediaconchresult_trim=$(echo "${mediaconchresult}" | cut -d' ' -f1 | tr -d '\n')
if [ "${mediaconchresult_trim}" = "fail!" ] ; then
echo -e "\033[1;31mWarning: Input does not conform to the audioaip policies for the following reasons:\033[0m"
echo "${mediaconchresult}"
echo -e "\033[1;32mEnter Y to proceed. Any other key to exit.\033[0m"
read exit_check
if ! [[ "${exit_check}" = [Yy] ]] ; then
_error_exit "Exiting"
fi
fi
fi
#create directory structure
orig_base=$(basename "${file_input}")
deriv_name="${file_input%.*}.flac"
mp3_name="${file_input%.*}.mp3"
appended_name="${file_input%.*}_appended.mp3"
mediaid="${orig_base%.*}"
targetdirectory=$(dirname "${file_input}")
mkdir "${targetdirectory}/${mediaid}" || _error_exit "Directory already exists. Exiting..."
mkdir "${targetdirectory}/${mediaid}/metadata"
mkdir "${targetdirectory}/${mediaid}/logs"
mkdir "${targetdirectory}/${mediaid}/logs/fileMeta"
mkdir "${targetdirectory}/${mediaid}/objects"
mkdir "${targetdirectory}/${mediaid}/objects/access"
#Photo Mode
if [[ "${runtype}" = "photo" ]] ; then
echo "How many pictures will you take?"
read pic_num
i=1
while [ "$i" -le "$pic_num" ]; do
echo "Press enter to activate camera, then press escape to take picture"
read null_response
ffplay -window_title "Press Escape When Ready To Take Picture" -f avfoundation -i "default"
ffmpeg -f avfoundation -i "default" "${targetdirectory}"/"${mediaid}"/objects/"${mediaid}"_0"$i".jpg && ffplay -window_title "Press Escape When Ready To Continue" "${targetdirectory}"/"${mediaid}"/objects/"${mediaid}"_0"${i}".jpg
echo "Enter q to quit, r to retake or enter continue"
read followquery
if [[ "${followquery}" == "q" ]] ; then
exit
fi
if [[ "${followquery}" == "r" ]] ; then
rm "$(dirname "${file_input}")"/"${mediaid}"/objects/"${mediaid}"_0"${i}".jpg
else
i=$(($i + 1))
fi
done
fi
#create metadata and derivative files
mediainfo --output=PBCore2 "${file_input}" > "${targetdirectory}/${mediaid}/logs/fileMeta/${mediaid}_pbcoreinstantiation.xml"
flac --best --keep-foreign-metadata --preserve-modtime --verify "${file_input}" 2>&1 | tee "${targetdirectory}/${mediaid}/logs/${mediaid}_flac.log"
#mp3 options
if [ -n "${copyright_location}" ] ; then
ffmpeg -i "${file_input}" -i "${copyright_location}" -filter_complex "[0:a:0]asplit=2[a][b];[a]dynaudnorm[aa];[b]afifo[bb];[1:a:0][bb]concat=n=2:v=0:a=1[c];[c]dynaudnorm=g=81[concatout]" -map "[aa]" -codec:a libmp3lame -dither_method triangular -metadata Normalization="ffmpeg dynaudnorm=g=81" -qscale:a 2 "${mp3_name}" -map "[concatout]" -codec:a libmp3lame -dither_method triangular -metadata Normalization="ffmpeg dynaudnorm=g=81" -qscale:a 2 "${appended_name}" 2>&1 | tee "${targetdirectory}/${mediaid}/logs/${mediaid}_ffmpeg.log"
else
ffmpeg -i "${file_input}" -codec:a libmp3lame -write_id3v1 1 -id3v2_version 3 -dither_method triangular -af dynaudnorm=g=81 -metadata Normalization="ffmpeg dynaudnorm=g=81" -qscale:a 2 "${mp3_name}" 2>&1 | tee "${targetdirectory}/${mediaid}/logs/${mediaid}_ffmpeg.log"
fi
#sync access mp3s if option selected
if [[ "${derivative_choice}" = "Y" ]] ; then
echo -e "\033[1;32mSyncing access copy to $destination \033[0m"
rsync -Pa "${mp3_name}" "${derivative_destination}"
if [ -f "${appended_name}" ] ; then
rsync -Pa "${appended_name}" "${derivative_destination}"
fi
fi
#create checksum
md5deep -b "${file_input}" > "${targetdirectory}/${mediaid}/metadata/${mediaid}.md5"
#move files
rsync "${file_input}" "${targetdirectory}/${mediaid}/objects"
rsync --remove-source-files "${deriv_name}" "${targetdirectory}/${mediaid}/objects"
rsync --remove-source-files "${mp3_name}" "${targetdirectory}/${mediaid}/objects/access"
if [ -f "$appended_name" ] ; then
rsync --remove-source-files "${appended_name}" "${targetdirectory}/${mediaid}/objects/access"
fi
package="${targetdirectory}/${mediaid}"
#Run Bagit
bagit baginplace "${package}"
#sync AIP to destination
if [[ "${sync_choice}" = "Y" ]] ; then
for i in "${destination[@]}" ; do
echo -e "\033[1;32mSyncing Files to ${i} \033[0m"
rsync -Pa "${package}" "${i}"
# check if destination is local. If local verify with bagit.
remote_test=$(echo "${destination}" | grep "@")
if [ -n "${remote_test}" ] ; then
echo -e "\033[1;32mAs Destination is not local audioaip is skipping bagit verification\033[0m"
else
echo -e "\033[1;32mVerifying checksums of package \033[0m"
bagit verifypayloadmanifests --excludehiddenfiles "${i}"/"${mediaid}"
fi
done
fi
done