98 lines
2.6 KiB
Bash
Executable file
98 lines
2.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
if [ $# -lt 2 ]
|
|
then
|
|
echo "$0 <rate> <file>"
|
|
fi
|
|
|
|
RATE="$1"
|
|
FILE="$2"
|
|
|
|
OUTPUTFILE="$(echo "$2" | sed 's/\.osu//g' | cut -d']' -f1) x$RATE].osu"
|
|
|
|
AUDIO=$(grep "AudioFilename:" "$FILE" | cut -d' ' -f2- | tr -d '\n\r')
|
|
AUDIORATED=$(echo $AUDIO | cut -d'.' -f1)-x$RATE".mp3"
|
|
|
|
echo "" > $OUTPUTFILE
|
|
rm "$OUTPUTFILE"
|
|
|
|
output_line () {
|
|
printf "%s\r\n" "$1" >> $OUTPUTFILE
|
|
}
|
|
|
|
audioRate () {
|
|
ffmpeg -i "$AUDIO" -filter:a "asetrate=$(ffprobe -v error -show_entries stream=sample_rate -of default=noprint_wrappers=1:nokey=1 "$AUDIO")*$RATE" -y "$AUDIORATED"
|
|
}
|
|
|
|
LINES=$(wc -l "$FILE" | cut -d' ' -f1)
|
|
FFILE=$(cat "$FILE")
|
|
|
|
step_skip ()
|
|
{
|
|
printf "$(echo "$FFILE" | grep -B $LINES "$1" | head -n -1)" >> $OUTPUTFILE
|
|
FFILE=$(echo "$FFILE" | grep -A $LINES "$1" | tail -n +2)
|
|
}
|
|
|
|
step_skip "AudioFilename:"
|
|
output_line "AudioFilename: $AUDIORATED"
|
|
|
|
PREVIEW=$(echo "$FFILE" | grep "PreviewTime:" | cut -d' ' -f2 | tr -d '\r\n')
|
|
step_skip "PreviewTime:"
|
|
output_line "PreviewTime: $(echo "$PREVIEW / $RATE" | bc | cut -d '.' -f1)"
|
|
VERSION=$(echo "$FFILE" | grep "Version:" | cut -d':' -f2- | tr -d '\n\r')
|
|
step_skip "Version:"
|
|
output_line "Version:$VERSION x$RATE"
|
|
|
|
step_skip "BeatmapID:"
|
|
output_line "BeatmapID:0"
|
|
|
|
step_skip "\[TimingPoints\]"
|
|
TIMINGPOINTS=$(echo "$FFILE" | grep -B $LINES "\[HitObjects\]" | head -n -1)
|
|
OBJECTS=$(echo "$FFILE" | grep -A $LINES "\[HitObjects\]" | tail -n +2)
|
|
|
|
output_line "[TimingPoints]"
|
|
|
|
N=$(echo "$TIMINGPOINTS" | wc -l)
|
|
I=0
|
|
for LINE in $TIMINGPOINTS
|
|
do
|
|
# TODO: ignore colors
|
|
I=$((I + 1))
|
|
printf "Timing: %s%%\r" $(echo "$I * 100 / $N" | bc)
|
|
if [ -n "$(echo $LINE | grep ",")" ]
|
|
then
|
|
VAL=$(echo "$(echo "$LINE" | cut -d ',' -f1) / $RATE" | bc | cut -d '.' -f1)
|
|
BPM=$(echo "$LINE" | cut -d',' -f7)
|
|
if [ $BPM -eq 1 ] ; then
|
|
VAL2=$(echo "$(echo "$LINE" | cut -d ',' -f2) / $RATE" | bc -l)
|
|
output_line "$VAL,$VAL2,$(echo "$LINE" | cut -d ',' -f3-)"
|
|
else
|
|
output_line "$VAL,$(echo "$LINE" | cut -d ',' -f2-)"
|
|
fi
|
|
else
|
|
output_line "$LINE"
|
|
fi
|
|
done
|
|
echo ""
|
|
|
|
output_line "[HitObjects]"
|
|
N=$(echo "$OBJECTS" | wc -l)
|
|
I=0
|
|
for LINE in $OBJECTS
|
|
do
|
|
I=$((I + 1))
|
|
printf "Objects: %s%%\r" $(echo "$I * 100 / $N" | bc)
|
|
if [ -n "$(echo $LINE | grep ",")" ]
|
|
then
|
|
V12=$(echo $LINE | cut -d',' -f-2)
|
|
V3=$(echo "$(echo "$LINE" | cut -d ',' -f3) / $RATE" | bc | cut -d '.' -f1)
|
|
V45=$(echo $LINE | cut -d',' -f4-5)
|
|
V6=$(echo "$(echo $LINE | cut -d',' -f6 | cut -d':' -f1) / $RATE" | bc | cut -d '.' -f1)
|
|
CPM=$(echo $LINE | cut -d':' -f2-)
|
|
output_line "$V12,$V3,$V45,$V6:$CPM"
|
|
else
|
|
output_line $LINE
|
|
fi
|
|
done
|
|
echo ""
|
|
audioRate
|