transcode/transcode.sh

45 lines
1 KiB
Bash
Raw Normal View History

#!/bin/bash
2017-12-30 17:44:19 +01:00
input_directory=/data/music
2017-12-30 17:44:19 +01:00
2019-10-21 14:40:55 +02:00
tmp_directory=/data/tmp/transcode
lock_file=/tmp/music-transcode.lock
2019-10-21 14:40:55 +02:00
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function die()
{
printf '%s\n' "$1" >&2
exit "${2-1}"
}
if [ -f "$lock_file" ] ; then
2017-12-30 17:44:19 +01:00
echo "Another instance is already running. Exiting."
echo "If you are certain this is the only instance, you can delete the lock file $lockfile"
2019-10-21 14:40:55 +02:00
exit 2
2017-12-30 17:44:19 +01:00
else
touch "$lock_file" || die "Could not create lock file."
2017-12-30 17:44:19 +01:00
fi
2019-10-21 14:40:55 +02:00
function cleanup()
{
2019-10-21 14:40:55 +02:00
rm -f "$lock_file"
2019-10-21 14:40:55 +02:00
rm -rf "$tmp_directory"
}
2019-10-21 14:40:55 +02:00
trap cleanup EXIT SIGTERM SIGKILL
2019-10-21 14:40:55 +02:00
if [ ! -d "$tmp_directory" ] ; then
mkdir -p "$tmp_directory" || die "Could not create temporary directory \"$tmp_directory\"."
fi
SAVEIFS=$IFS
IFS=`echo -ne "\n\b"`
for file in `find "$input_directory" -name '*.flac' -or -name '*.mp3' | sort`; do
2019-10-21 14:40:55 +02:00
bash ${__dir}/transcode_to_mp3.sh "$file" "$input_directory" "/data/mp3" || break
bash ${__dir}/transcode_to_ogg.sh "$file" "$input_directory" "/data/ogg" || break
2017-12-30 17:44:19 +01:00
done
echo "Done Transcoding."
IFS=$SAVEIFS