summaryrefslogtreecommitdiff
path: root/audioconversion.sh
blob: b70f1d0f4020a1ae6cf3dede1f1f86d1bd166f25 (plain)
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
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]
then
echo "Enter an input directory followed by an output directory!"
exit 1
else
echo "Copying Directories..."
fi

find "$1" -mindepth 1 -type d -print0| while read -d '' -r dir; 
do
d1=${dir#"$1"}
mkdir -v "$2$d1" 2> /dev/null
done

#Link to all pictures, lyric files, etcetera.
echo "Creating Links for non-audio files..."
find "$1" -iname '*.png' -o -iname '*.jpg' -o -iname '*html' -o -iname '*.lrc' -o -iname '*.txt' -o -iname '*.cue' -o -iname '*.exe' -o -iname '*.mpg'  -o -iname '*.bmp' -o -iname '*.ico' | while read -r file;
do
ln -P "$file" "$2${file#"$1"}" 2> /dev/null
done

echo "Copying pre-existing mp3s and unlinkable files..."
find "$1" -iname '*.mp3' -o -iname '*.log' -o -iname '*.m3u' -o -iname '*.m3u8' -o -iname '*.accurip' -o -iname '*pdf' -o -iname '*.rtf'| while read -r file;
do
cp "$file" "$2${file#"$1"}" 2> /dev/null
done

find "$1" -iname 'desktop.ini' -o -iname 'Thumbs.db' -o -iname '*nfo'| while read -r file;
do
rm "$file"
done

echo "Converting audio... Please be Patient!"
find "$1" -type f -iname '*.flac' -printf '%h\n' | sort -u | while read -r dir
 do	
	if [ $(( $(find "$dir"/*.flac | wc -l) )) -gt $(( $(find "$2${dir#"$1"}"/*.mp3 2> /dev/null | wc -l) )) ]
	then
	track2track -t mp3 -q extreme -j 20 -d "$2${dir#"$1"}" "$dir"/*.flac
	#ffmpeg -i "$track" -vn -n -loglevel panic -threads 20 -map 0:a "${path%.*}".mp3
	else
	echo "$2${dir#"$1"} Contains an equal number of mp3s..."
	fi
 done
 
 find "$1" -type f -iname '*.m4a' -printf '%h\n' | sort -u | while read -r dir
 do	
	if [ $(( $(find "$dir"/*.m4a | wc -l) )) -gt $(( $(find "$2${dir#"$1"}"/*.mp3 2> /dev/null | wc -l) )) ]
	then
	track2track -t mp3 -q extreme -j 20 -d "$2${dir#"$1"}" "$dir"/*.m4a
	else
	echo "$2${dir#"$1"} Contains an equal number of mp3s..."
	fi
 done
 
  find "$1" -type f -iname '*.mp4' -printf '%h\n' | sort -u | while read -r dir
 do	
	if [ $(( $(find "$dir"/*.mp4 | wc -l) )) -gt $(( $(find "$2${dir#"$1"}"/*.mp3 2> /dev/null | wc -l) )) ]
	then
	track2track -t mp3 -q extreme -j 20 -d "$2${dir#"$1"}" "$dir"/*.mp4
	else
	echo "$2${dir#"$1"} Contains an equal number of mp3s..."
	fi
 done
 
 find "$1" -type f -iname '*.wav' -printf '%h\n' | sort -u | while read -r dir
 do	
	if [ $(( $(find "$dir"/*.wav | wc -l) )) -gt $(( $(find "$2${dir#"$1"}"/*.mp3 2> /dev/null | wc -l) )) ]
	then
	track2track -t mp3 -q extreme -j 20 -d "$2${dir#"$1"}" "$dir"/*.wav
	else
	echo "$2${dir#"$1"} Contains an equal number of mp3s..."
	fi
 done
 echo "File Conversion Done! Starting renaming process..."
 #Rename files in accordance with our template
find "$2" -mindepth 1 -iname '*.flac' -o -iname '*.m4a' -o -iname '*.wav' -o -iname '*.mp4' -o -iname '*.mp3' | while read -r track;
do
  trackrename "--format=%(track_number)2.2d - %(track_name)s.%(suffix)s" "$track"
done

echo "Resolving character conflicts..."
#Remove potential charset conflicts
find "$2" -type f -iname '*.flac' -o -iname '*.m4a' -o -iname '*.wav' -o -iname '*.mp4' -o -iname '*.mp3' | while read -r track;
do
   song=$(basename "$track")
   path=$(dirname "$track")
   mv "$track" "$path/$(echo "$song" | sed -e 's/[^A-Za-z0-9._-]/\ /g')"
done