4 # description: Sorts simfiles in to footspeed and stamina folders
5 # based on user defined thresholds.
6 # Input is tailored to suit dialog's gauge widget.
9 while getopts ":d:f:s:r:" opt
; do
15 footspeed_cutoff
=$OPTARG
18 stamina_cutoff
=$OPTARG
24 echo "Invalid option: -$OPTARG" >&2
28 echo "Option -$OPTARG requires an argument." >&2
34 if [[ -z
"$songs_dir" ]] ||
[[ "${songs_dir}xxx" = "xxx" ]]; then
35 echo "Songs directory not supplied.";
39 if [[ -z
"$footspeed_cutoff" ]] ||
[[ "${footspeed_cutoff}xxx" = "xxx" ]]; then
40 echo "Footspeed cutoff not supplied.";
44 if [[ -z
"$stamina_cutoff" ]] ||
[[ "${stamina_cutoff}xxx" = "xxx" ]]; then
45 echo "Stamina cutoff not supplied.";
49 if [[ -z
"$rating_cutoff" ]] ||
[[ "${rating_cutoff}xxx" = "xxx" ]]; then
50 echo "Rating cutoff not supplied.";
54 [[ ! $footspeed_cutoff =~ ^
-?
[0-9]+$
]] && echo "Footspeed cutoff must be integer" && exit 1
55 [[ ! $stamina_cutoff =~ ^
-?
[0-9]+$
]] && echo "Stamina cutoff must be integer" && exit 1
56 [[ ! $rating_cutoff =~ ^
-?
[0-9]+$
]] && echo "Rating cutoff must be integer" && exit 1
58 [[ ! -d
"$songs_dir" ]] && echo 100 && exit 0
60 num
=$
(wc -l
< /tmp
/newsongs.txt
)
62 [[ ! $num -gt
0 ]] && echo 100 && exit 0
67 function extract_key
()
69 key
=$
(grep $2 $1 | cut
-d
':' -f
2 | cut
-d
';' -f
1 |
tr -d $
'\r')
73 function song_length_minutes
()
76 music_file
=$
(extract_key
$1 "MUSIC")
79 length
=$
(ffmpeg
-i
"$music_path/$music_file" 2>&1 |
grep Duration |
awk '{print $2}' | cut
-d
':' -f
2 |
tr -d
,)
87 bpms
=$
(extract_key
$1 "BPMS")
88 IFS
=',' read -a array
<<< "$bpms"
91 for bpm
in "${array[@]}"
93 bpm
=$
(cut
-d
'=' -f
2 <<< "$bpm")
94 comp
=$
(echo "$bpm > $max300" |
bc)
95 ((comp
> 0)) && max300
=$bpm
101 function difficulty
()
103 noteslines
=$
(grep -n
"NOTES" $1)
104 readarray
-t array
<<<"$noteslines"
107 for noteline
in "${array[@]}"
109 linenum
=$
(cut
-d
':' -f
1 <<< "$noteline")
110 linenum
=$
((linenum
+4))
111 line
=$
(sed -n
"${linenum}p" $1 | cut
-d
':' -f
1)
112 diff="$(echo -e "${line}" | tr -d '[[:space:]]')"
113 comp
=$
(echo "$diff > $max300" |
bc)
114 ((comp
> 0)) && max300
=$diff
120 rm -rf
"${songs_dir}/Footspeed"
121 rm -rf
"${songs_dir}/Stamina"
123 mkdir
-p
"${songs_dir}/Footspeed"
124 mkdir
-p
"${songs_dir}/Stamina"
126 total_charts
=$
(find "$songs_dir" -name
*.sm |
wc -l
)
129 for file in $
(find "$songs_dir" -name
*.sm
)
131 difficulty
=$
(difficulty
$file)
132 maxbpm
=$
(max_bpm
$file)
133 songlength
=$
(song_length_minutes
$file)
135 if [[ "$difficulty" > $rating_cutoff ]]; then
136 path_to_chart
="$(dirname "$file")"
137 folder_name
="$(basename "$path_to_chart")"
138 [[ "$maxbpm" > "$footspeed_cutoff" ]] && ln -s
"${path_to_chart}" "${songs_dir}/Footspeed/${folder_name}" > /dev
/null
2>&1
139 [[ "$songlength" > "$stamina_cutoff" ]] && ln -s
"${path_to_chart}" "${songs_dir}/Stamina/${folder_name}" > /dev
/null
2>&1
143 printf '%i %i' $num_processed $total_charts | mawk
-Winteractive
'{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }'