Hello Guys,
i want to move my old CONTENT TAF’s to the new LIBRARY schema. Due to i have lots of TAF’s i wrote a smal bash script, which does the job for me. Maybe it will help somebody else, too.
What it does?
- It will go through all folders in CONTENT directory.
- If TAF with name ‘500304E0’ exists, it extracts the AudioID from TAF using opus2tonie.py.
- If file is not already in LIBRARY folder, it will be copied and renamed there and deleted from CONTENT.
- Afterwards the 'source" field is linked to the new location inside the JSON file.
- If ‘500304E0’ is not found, it will be validated, if a linked source exists. If not exitst(→missing) is written to console.
- Using
./_move2lib.sh -t
switch will run in “Test only” mode which does not move or change anything.
How to use it?
- Create new file and copy code.
- Grant file execution permissions
- Adjust the follwoing three variables to your setup:
CONENT → TeddyCloud content directory, e.g. “/teddycloud/content/default/”
LIBRARY→ TeddyCloud library directory, e.g. “/teddycloud/library/by/audioID/”
OPUS2TONIE → path to Opus2Tonie python script which is used to extract the AudioID from TAF
!!!PLEASE MAKE A BACKUP OF YOUR CONTENT AND LIBRARY DIRECTORY BEFORE USING THIS SCRIPT!!!
Prerequisites
- Opus2Tonie must be downloaded. It requires Python3
- Opus2Tonie requires
python3-protobuf
to decoce protobuf. Please install it viapip
orapt
Bash script
./_move2lib.sh -t
#!/bin/bash
# PLEASE ADJUST HERE TO YOUR ENVIRONMENT!
OPUS2TONIE="/srv/Transfer/TAF_CONVERTER/opus2tonie-main/opus2tonie.py"
CONTENT="/teddycloud/content/default/"
LIBRARY="/teddycloud/library/by/audioID/"
# Init
VERSION=1.0
TEST=0
FORCE=0
SPLIT=1
echo
echo -e "\e[1mMigrate CONTENT TAF's to LIBRARY v$VERSION\e[0m"
echo
# Check environment
[ ! -d $CONTNET ] && exit 101
[ ! -d $LIBRARY ] && exit 102
[ ! -f $OPUS2TONIE] && exit 103
while getopts "h?t" opt; do
case "$opt" in
t )
TEST=1
;;
h|\?|* )
usage
;;
esac
done
for DIR in $CONTENT*; do
PROCESS=0
VALIDATE=0
echo -en "Processing dir \"$DIR\": "
# Check if TAF was already moved to LIBRARY
if [ -f "${DIR}/500304E0" ] ; then PROCESS=1; fi
if [ -f "${DIR}/500304E0.json" ] && [ ! -f "${DIR}/500304E0" ] ; then VALIDATE=1; fi
if [ $VALIDATE -eq "1" ] ; then
SOURCE=$(cat ${DIR}/500304E0.json | grep source | awk -F '/' '{print $5}' | awk -F '"' '{print $1}')
if [ ! -f ${LIBRARY}${SOURCE} ] ; then
echo -e "\e[31mTAF not found!\e[0m"
continue
fi
fi
if [ ! -f "${DIR}/500304E0" ] ; then
echo -e "\e[34mDone\e[0m."
continue
elif [ ! -f "${DIR}/500304E0.json" ] ; then
PROCESS=0
echo -e "\e[33mJSON not found\e[0m."
continue
fi
if [ $PROCESS -eq "1" ] ; then
# Extraxt AUDIO_ID from TAF. Use date command with UTC time!
DATE_TIME=$($OPUS2TONIE --info ${DIR}/500304E0 | grep Timestamp | awk -F ']' '{print $3}' | xargs)
AUDIO_ID=$(date -u --date "$DATE_TIME" +"%s")
# Indicate when TAF already exists (e.g. Custom Tonie linked to original)
[ -f ${LIBRARY}${AUDIO_ID}.taf ] && echo -en "!"
if [ $TEST -eq "0" ] ; then
# Copy TAF to Library
cp -n ${DIR}/500304E0 ${LIBRARY}${AUDIO_ID}.taf
# Link source to new location
sed -i "s|\"source\": \"\",|\"source\": \"lib://by/audioID/$AUDIO_ID.taf\",|g" "${DIR}/500304E0.json"
#remove TAF if found at new location
[ -f ${LIBRARY}${AUDIO_ID}.taf ] && rm ${DIR}/500304E0
else
echo -en "% "
fi
echo -e "\e[32mOk\e[0m."
fi
done
exit 0
Hope this wil help.
Cheers.