-
Notifications
You must be signed in to change notification settings - Fork 0
/
retag.sh
executable file
·50 lines (43 loc) · 1.41 KB
/
retag.sh
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
#!/bin/bash
args=("$@")
if [ $# -eq 0 ] || [ $# -eq 1 ]; then
echo "Correct usage:"
echo " scriptname [output directory] [file list]"
else
numOfElems=${#args[@]}
outputDir=${args[0]}
for (( i=1;i<$numOfElems;i++ )); do
size="$(stat --format="%s" "${args[${i}]}")"
if [ "$size" = "0" ];then
# echo "size 0: ${args[${i}]}"
rm "${args[${i}]}"
continue
fi
name="$(mediainfo "${args[${i}]}"|grep -e 'Track name *: '|sed 's/Track name *: //')" 2>/dev/null
name="$(sed 's,/,-,g'<<<$name)"
# echo "$name"
artist="$(mediainfo "${args[${i}]}"|grep -e '^Performer *: '|sed 's/^Performer *: //')" 2>/dev/null
artist="$(sed 's,/,-,g'<<<$artist)"
# echo "$artist"
album="$(mediainfo "${args[${i}]}"|grep -e 'Album *: '|sed 's/Album *: //')" 2>/dev/null
album="$(sed 's,/,-,g'<<<$album)"
# echo "$album"
track="$(mediainfo "${args[${i}]}"|grep -e 'Track name/Position *: '|sed "s,Track name/Position *: ,,")" 2>/dev/null
printf -v track "%02d" $track
# echo "$track"
ext="$(sed 's/.*\(\..\{3,4\}\)$/\1/'<<<${args[${i}]})"
# echo "$ext"
fpath="$artist/$album"
fname="$track - $name$ext"
# echo "Path: $fpath"
# echo "Name: $fname"
if [ -z "$name" ];then
echo "couldn't get info for ${args[${i}]}"
else
mkdir -p "$outputDir/$fpath"
mv "${args[${i}]}" "$fname" 2>/dev/null
mv "$fname" "$outputDir/$fpath/"
echo "${args[${i}]} >>>> $outputDir/$fpath/$fname"
fi
done
fi