Extract song length using ffmpeg
authorCameron Ball <cameron@getapproved.com.au>
Fri, 13 Feb 2015 07:18:49 +0000 (15:18 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Fri, 13 Feb 2015 07:18:49 +0000 (15:18 +0800)
.gitignore [new file with mode: 0644]
simlink.sh

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b25c15b
--- /dev/null
@@ -0,0 +1 @@
+*~
index 5589b54..245e499 100755 (executable)
@@ -2,14 +2,32 @@
 
 songs_dir=/home/cameron/Games/OpenITG/Songs
 symlink_dir=/home/cameron/Games/OpenITG/Songs/Fast
+current_file=
 
 IFS=$'\n'
 
-function maxbpm()
+#(file, key)
+function extract_key()
 {
-       bpms=$(grep "BPMS" $1)
-       bpms=${bpms:6:-2}
+       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
@@ -45,8 +63,10 @@ function difficulty()
 for file in $(find "$songs_dir" -name *.sm)
 do
        difficulty=$(difficulty $file)
-       maxbpm=$(maxbpm $file)
+       maxbpm=$(max_bpm $file)
+       songlength=$(song_length_minutes $file)
 
        echo "$maxbpm"
        echo "$difficulty"
+       echo "$songlength"
 done