-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert
executable file
·61 lines (47 loc) · 1.21 KB
/
convert
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
#!/bin/bash
# > convert <
# Uses ffmpeg to convert audio files to different codecs.
# Written by parisminton for Concrete Daydreams.
# <parisminton@da.ydrea.ms>
# Usage: `convert <source> <destination> <codec>`
vrs='v 0.1'
lastchange='12/27/17'
echo -e "\n--> Convert $vrs $lastchange <--"
# change IFS to newline
OLD_IFS=$IFS
IFS=$'\n'
# if no arguments, exit -1 and warn the user she needs to choose a source, destination and codec
# if only one argument, exit -1 and warn the user she needs to choose a destination
# if only two arguments, exit -1 and warn the user she needs to choose a codec
src="$1"
destination="$2"
codec="$3"
i=0
function filter () {
if [ -d "$1" ]; then
# make breadcrumb trail of destinations
old_dest[$i]=$destination
i=$(($i+1))
mkdir "$destination/$1"
destination="$destination/$1"
echo "All destinations are ${old_dest[*]}"
echo "$destination"
# drill down to files
cd "$1"
for new_path in $(ls -1); do
filter $new_path
done
cd ..
destination="${old_dest[($i-1)]}"
unset old_dest[$i]
i=$(($i-1))
else
# conversion happens here
cp $1 $destination
echo $1
fi
}
for path in $(ls -1 $src); do
filter $path
i=0
done