Specify paths correctly
[GrooveNet.git] / Categorise.sh
1 #!/bin/bash
2
3 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4 source "$DIR/config.sh"
5
6 if [ -z $1 ]; then
7 exit
8 fi
9
10 songs_file=$(ls "$DIR" | grep songs | tail -n1)
11
12 if [ -z "$songs_file" ]; then
13 exit
14 fi
15
16 if [ "$1" = "apply" ]; then
17 if [ -f "$DIR"/footspeed.txt ]; then
18 IFS=$'\n' read -d '' -r -a lines < "$DIR"/footspeed.txt
19
20 rm -rf "$path_to_songs/$footspeed_folder"
21 mkdir "$path_to_songs/$footspeed_folder"
22 declare -A song_paths
23 song_paths=()
24 for i in "${lines[@]}"; do
25 if [ -z "${song_paths[$i]}" ]; then
26 song_paths["$i"]+=$(grep $i "${DIR}/${songs_file}" | cut -sd / -f5-6)
27 fi
28 done
29
30 for song_path in "${song_paths[@]}"; do
31 echo "$song_path"
32 just_song=$(echo "$song_path" | cut -sd / -f2)
33 original_folder=$(echo "$song_path" | cut -sd / -f1)
34 crc32="$(echo -n "/Songs/${footspeed_folder}/${just_song}/" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')"
35
36 echo "${just_song} -> footspeed"
37 echo -e "\t${path_to_song_cache}/${crc32}"
38
39 #rm "${path_to_song_cache}/${crc32}"
40 ln -s "$path_to_songs/$song_path" "$path_to_songs/$footspeed_folder/$original_folder - $just_song"
41 done <<< "$song_paths"
42 fi
43
44 if [ -f "$DIR"/stamina.txt ]; then
45 IFS=$'\n' read -d '' -r -a lines < "$DIR"/stamina.txt
46
47 rm -rf "$path_to_songs/$stamina_folder"
48 mkdir "$path_to_songs/$stamina_folder"
49 declare -A song_paths
50 song_paths=()
51 for i in "${lines[@]}"; do
52 if [ -z "${song_paths[$i]}" ]; then
53 song_paths["$i"]+=$(grep $i "${DIR}/${songs_file}" | cut -sd / -f5-6)
54 fi
55 done
56
57 for song_path in "${song_paths[@]}"; do
58 echo "$song_path"
59 just_song=$(echo $song_path | cut -sd / -f2)
60 original_folder=$(echo "$song_path" | cut -sd / -f1)
61 crc32="$(echo -n "/Songs/${stamina_folder}/${just_song}/" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')"
62
63 echo "${just_song} -> stamina"
64 echo -e "\t${path_to_song_cache}/${crc32}"
65
66 #rm "${path_to_song_cache}/${crc32}"
67 ln -s "$path_to_songs/$song_path" "$path_to_songs/$stamina_folder/$original_folder - $just_song"
68 done <<< "$song_paths"
69 fi
70 fi