"command": "./rsync-adapter.sh -ia --delete --exclude 'A is for Cool Shit' /home/cameron/PreComTestRepo/Songs /home/cameron/Games/OpenITG",
"title": "Syncing songs..."
},
+ {
+ "command": "./simlink-adapter.sh -d /home/cameron/Games/OpenITG/Songs/ -f 240 -s 5 -r 13",
+ "title": "Sorting songs..."
+ },
{
"command": "./cache-update-adapter.sh -d /itg/Cache/Songs/",
"title": "Updating cache..."
"description": "Run presets",
"items": [
{
- "name": "Sync and Launch",
+ "name": "Sync_and_Launch",
"type": "preset",
"description": "Sync songs and launch ITG",
"itemsToRun": [
function debug()
{
>&2 echo "$1"
+ sleep 2
}
function get_key_from_line()
echo "$1"
else
re="${2//./\\.}\.items\.([0-9]+?)\.name"
- debug "$re"
while read -r line; do
if [[ "$line" =~ $re ]]; then
sub_path=${BASH_REMATCH[1]}
path_so_far="${path_so_far}.${relative_path}"
fi
done
- done <<< "$1"
+ done <<< "${1//_/\ }"
echo "$path_so_far"
}
key=$(get_key_from_line "$line")
desc=$(get_value_from_key "${key%.*}.description")
name=$(get_value_from_key "${key%.*}.name")
- options+=("$name" "$desc")
+ options+=("${name//_/\ }" "$desc")
fi
fi
done <<< "$menu_json"
#I tried $(short_path_to_full_path $1).commands
#but it produced a weird result.
local full_path=$(short_path_to_full_path $1)
+
while read -r line; do
if is_child_of "$line" "${full_path}.commands"; then
command_re=".\/(.+.sh)"
title=$(get_value_from_key "${key%.*}.title")
case "$widget" in
- gauge) eval "$command" | dialog --clear --backtitle "$backtitle" --title "Running $1" --gauge "$title" "$box_height" "$box_width";;
- msgbox) eval "$command" | dialog --clear --backtitle "$backtitle" --title "$title" --msgbox "$(eval \"$command\")" "$box_height" "$box_width";;
+ gauge) eval "$command" | dialog --clear --backtitle "$backtitle" --title "Running $1" --gauge "$title" 6 60;;
+ msgbox) eval "$command" | dialog --clear --backtitle "$backtitle" --title "$title" --msgbox "$(eval \"$command\")" 8 40;;
esac
fi
fi
if is_child_of "$line" "${full_path}.itemsToRun"; then
key=$(get_key_from_line "$line")
item=$(get_value_from_key "$key")
- debug "$item"
- sleep 3
process_item "$item"
fi
done <<< "$menu_json"
function process_item()
{
type=$(get_item_type $1)
+
case $type in
menu) render_menu $1 $2;;
service) toggle_service $1 $2;;
case $selection in
Quit) break;;
Back) current_item="${current_item%.*}";;
- *) current_item="$current_item.$selection";;
+ *) current_item="$current_item.${selection//\ /_}";;
esac
done
# with dialog's --progress option
#XXX: Some versions of rsync say to-chk instead of to-check, be careful
-rsync --progress "$@" | tee >(grep -v "*deleting" | grep -i ".sm" > /tmp/newsongs.txt) | mawk -Winteractive '{ if (index($0, "to-check=") > 0) { split($0, pieces, "to-check="); split(pieces[2], term, ")"); split(term[1], division, "/"); print (1-(division[1]/division[2]))*100 } }' \
+rsync --progress "$@" | tee >(grep -v "*deleting" | grep -i ".sm" > /tmp/newsongs.txt) | mawk -Winteractive '{ if (index($0, "to-chk=") > 0) { split($0, pieces, "to-chk="); split(pieces[2], term, ")"); split(term[1], division, "/"); print (1-(division[1]/division[2]))*100 } }' \
| sed --unbuffered 's/\([0-9]*\).*/\1/'
--- /dev/null
+#!/bin/bash
+#
+# widget: gauge
+# description: Sorts simfiles in to footspeed and stamina folders
+# based on user defined thresholds.
+# Input is tailored to suit dialog's gauge widget.
+#
+
+while getopts ":d:f:s:r:" opt; do
+ case $opt in
+ d)
+ songs_dir=$OPTARG
+ ;;
+ f)
+ footspeed_cutoff=$OPTARG
+ ;;
+ s)
+ stamina_cutoff=$OPTARG
+ ;;
+ r)
+ rating_cutoff=$OPTARG
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ :)
+ echo "Option -$OPTARG requires an argument." >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [[ -z "$songs_dir" ]] || [[ "${songs_dir}xxx" = "xxx" ]]; then
+ echo "Songs directory not supplied.";
+ exit 1
+fi
+
+if [[ -z "$footspeed_cutoff" ]] || [[ "${footspeed_cutoff}xxx" = "xxx" ]]; then
+ echo "Footspeed cutoff not supplied.";
+ exit 1
+fi
+
+if [[ -z "$stamina_cutoff" ]] || [[ "${stamina_cutoff}xxx" = "xxx" ]]; then
+ echo "Stamina cutoff not supplied.";
+ exit 1
+fi
+
+if [[ -z "$rating_cutoff" ]] || [[ "${rating_cutoff}xxx" = "xxx" ]]; then
+ echo "Rating cutoff not supplied.";
+ exit 1
+fi
+
+[[ ! $footspeed_cutoff =~ ^-?[0-9]+$ ]] && echo "Footspeed cutoff must be integer" && exit 1
+[[ ! $stamina_cutoff =~ ^-?[0-9]+$ ]] && echo "Stamina cutoff must be integer" && exit 1
+[[ ! $rating_cutoff =~ ^-?[0-9]+$ ]] && echo "Rating cutoff must be integer" && exit 1
+
+[[ ! -d "$songs_dir" ]] && echo 100 && exit 0
+
+num=$(wc -l < /tmp/newsongs.txt)
+
+[[ ! $num -gt 0 ]] && echo 100 && exit 0
+
+IFS=$'\n'
+
+#(file, key)
+function extract_key()
+{
+ key=$(grep $2 $1 | cut -d ':' -f 2 | cut -d ';' -f 1 | tr -d $'\r')
+ echo "$key"
+}
+
+function song_length_minutes()
+{
+ path=$1
+ music_file=$(extract_key $1 "MUSIC")
+ music_path=${path%/*}
+
+ length=$(ffmpeg -i "$music_path/$music_file" 2>&1 | grep Duration |awk '{print $2}' | cut -d ':' -f 2 | tr -d ,)
+ length=${length##0}
+
+ echo "$length"
+}
+
+function max_bpm()
+{
+ bpms=$(extract_key $1 "BPMS")
+ IFS=',' read -a array <<< "$bpms"
+
+ max300=0.00
+ for bpm in "${array[@]}"
+ do
+ bpm=$(cut -d '=' -f 2 <<< "$bpm")
+ comp=$(echo "$bpm > $max300" | bc)
+ ((comp > 0)) && max300=$bpm
+ done
+
+ echo "$max300"
+}
+
+function difficulty()
+{
+ noteslines=$(grep -n "NOTES" $1)
+ readarray -t array <<<"$noteslines"
+ max300=0
+
+ for noteline in "${array[@]}"
+ do
+ linenum=$(cut -d ':' -f 1 <<< "$noteline")
+ linenum=$((linenum+4))
+ line=$(sed -n "${linenum}p" $1 | cut -d ':' -f 1)
+ diff="$(echo -e "${line}" | tr -d '[[:space:]]')"
+ comp=$(echo "$diff > $max300" | bc)
+ ((comp > 0)) && max300=$diff
+ done
+
+ echo "$max300"
+}
+
+mkdir -p "${songs_dir}/Footspeed"
+mkdir -p "${songs_dir}/Stamina"
+
+total_charts=$(find "$songs_dir" -name *.sm | wc -l)
+num_processed=0
+
+for file in $(find "$songs_dir" -name *.sm)
+do
+ difficulty=$(difficulty $file)
+ maxbpm=$(max_bpm $file)
+ songlength=$(song_length_minutes $file)
+
+ if [[ "$difficulty" > $rating_cutoff ]]; then
+ path_to_chart="$(dirname "$file")"
+ folder_name="$(basename "$path_to_chart")"
+ [[ "$maxbpm" > "$footspeed_cutoff" ]] && ln -s "${path_to_chart}" "${songs_dir}/Footspeed/${folder_name}" > /dev/null 2>&1
+ [[ "$songlength" > "$stamina_cutoff" ]] && ln -s "${path_to_chart}" "${songs_dir}/Stamina/${folder_name}" > /dev/null 2>&1
+ fi
+
+ ((num_processed++))
+
+ printf '%i %i' $num_processed $total_charts | mawk -Winteractive '{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }'
+done
+++ /dev/null
-#TITLE: Organise Simfiles
-#PARENT: ITG Options
-#WIDGET: progress_bar
-
-#!/bin/bash
-
-songs_dir=/home/cameron/Games/OpenITG/Songs
-symlink_dir=/home/cameron/Games/OpenITG/Songs/Fast
-
-IFS=$'\n'
-
-#(file, key)
-function extract_key()
-{
- key=$(grep $2 $1 | cut -d ':' -f 2 | cut -d ';' -f 1 | tr -d $'\r')
- echo "$key"
-}
-
-function song_length_minutes()
-{
- path=$1
- music_file=$(extract_key $1 "MUSIC")
- music_path=${path%/*}
-
- length=$(ffmpeg -i "$music_path/$music_file" 2>&1 | grep Duration |awk '{print $2}' | cut -d ':' -f 2 | tr -d ,)
- length=${length##0}
-
- echo "$length"
-}
-
-function max_bpm()
-{
- bpms=$(extract_key $1 "BPMS")
- IFS=',' read -a array <<< "$bpms"
-
- max300=0.00
- for bpm in "${array[@]}"
- do
- bpm=$(cut -d '=' -f 2 <<< "$bpm")
- comp=$(echo "$bpm > $max300" | bc)
- ((comp > 0)) && max300=$bpm
- done
-
- echo "$max300"
-}
-
-function difficulty()
-{
- noteslines=$(grep -n "NOTES" $1)
- readarray -t array <<<"$noteslines"
- max300=0
-
- for noteline in "${array[@]}"
- do
- linenum=$(cut -d ':' -f 1 <<< "$noteline")
- linenum=$((linenum+4))
- line=$(sed -n "${linenum}p" $1 | cut -d ':' -f 1)
- diff="$(echo -e "${line}" | tr -d '[[:space:]]')"
- comp=$(echo "$diff > $max300" | bc)
- ((comp > 0)) && max300=$diff
- done
-
- echo "$max300"
-}
-
-for file in $(find "$songs_dir" -name *.sm)
-do
- difficulty=$(difficulty $file)
- maxbpm=$(max_bpm $file)
- songlength=$(song_length_minutes $file)
-
- echo "$maxbpm"
- echo "$difficulty"
- echo "$songlength"
-done