-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnes-rename.bash
executable file
·56 lines (51 loc) · 1.28 KB
/
snes-rename.bash
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
#!/bin/bash
extract-songs() {
for f in ./*.rsn
do
mkdir "${f%.rsn}"
unrar e "$f" "${f%.rsn}/"
rm -f "$f"
done
}
rename-folders() {
for D in ./*
do
if [ -d "${D}" ]; then
files=($D/*.spc)
f="${files[0]}"
# Ensure we only rename folders containing music
if [[ "$f" ]]; then
# final substitution fixes games like "Ranma 1/2", which are invalid file names
sng=$(java -jar spctag/spctag.jar "$f" | grep "Game title" | sed 's/Game title\: //' | sed 's/\//_/g')
rootdn=$(dirname ${D})
echo "${rootdn}/${sng}"
mv "${D}" "${rootdn}/${sng}"
fi
fi
done
}
rename-songs() {
for f in ./**/*.spc
do
dn=$(dirname "$f")
fn=$(basename "$f" ".spc")
sng=$(java -jar spctag/spctag.jar -v "$f" | grep "Song title" | sed 's/Song title\: //')
# Ensure we don't clobber already renamed files
if [[ $fn != *$sng* ]]; then
nn=$(echo "$fn" | sed -e 's/.*-//')
if [[ "$nn" ]]; then
newf="${dn}/${nn} - ${sng}.spc"
echo "${newf}"
mv "$f" "${newf}"
else
# handle names without track numbers, like "Unused"
newf="${dn}/${sng}.spc"
echo "${newf}"
mv "$f" "${newf}"
fi
fi
done
}
extract-songs
rename-folders
rename-songs