-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatchenc
More file actions
executable file
·62 lines (53 loc) · 1.5 KB
/
Copy pathbatchenc
File metadata and controls
executable file
·62 lines (53 loc) · 1.5 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
#!/bin/bash
# Set codec options
if [ "$3" = opus ]; then
export CODEC="opus -q 128"
elif [ "$3" = ogg ]; then
export CODEC="ogg -q 6"
elif [ "$3" = mp3 ]; then
export CODEC="mp3"
elif [ "$3" = flac ]; then
export CODEC="flac"
else
echo "Syntax: batchenc INPUTDIR OUTPUTDIR {opus,ogg,flac,mp3}"
exit 1
fi
read -p "Source directory is \""$1"\". Is this correct? > " yn
case $yn in
[Yy]* ) : ;;
[Nn]* ) exit ;;
* ) echo "Please answer yes or no.";;
esac
read -p "Target directory is \""$2"\". Is this correct? > " yn
case $yn in
[Yy]* ) : ;;
[Nn]* ) exit ;;
* ) echo "Please answer yes or no.";;
esac
OPWD="$PWD"
inputDir=$(echo "$1" | sed 's/\/$//')
outputDir=$(echo "$2" | sed 's/\/$//')
if [ ! -d "$inputDir" ]; then
echo "Error: $inputDir: no such directory" 1>&2
exit 1
elif [ ! -d "$outputDir" ]; then
echo "Error: $outputDir: no such directory" 1>&2
exit 1
fi
cd "$outputDir"
while IFS= read -d $'\0' directory; do
if [ ! -d "${inputDir}/${directory}" ]; then
echo "Deleting \"${outputDir}/${directory}\""
rm -rf "${outputDir}/${directory}"
fi
done < <( find . -type d -print0 2>/dev/null )
cd "$inputDir"
while IFS= read -d $'\0' directory; do
if [ ! -d "${outputDir}/${directory}" ]; then
ls "${directory}"/*.flac >/dev/null 2>&1 || continue
echo "Transcoding \"${directory}\""
# transcode to CODEC
caudec -O "${outputDir}/${directory}" -K -s -c $CODEC "${directory}"/*.flac
fi
done < <( find . -type d -print0 2>/dev/null )
cd "$OPWD"