]> git.plutz.net Git - serve0/blobdiff - pages/playctl.sh
fix status bar, correct reading of mplayer output
[serve0] / pages / playctl.sh
index ded8603313ddff9ffe8682cff43565f4361b2a9e..c4ece2c85c97ac1f15ac501f405bc37f5c14af8d 100755 (executable)
@@ -22,6 +22,7 @@
 info="${_GET[i]}"
 location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
 directory="${location%/*}"
+statusfile="$_DATA/mplayer.status"
 
 TITLE="$info"
 
@@ -40,3 +41,16 @@ fi
 volume=$(validate "$(cat "$_DATA/mplayer.volume")" '[1-9]?[0-9]|100' 20)
 
 debug VIDEO: $video
+
+progress(){
+  tail --pid=$$ -f "$statusfile" \
+  | tr '\r' '\n' \
+  | sed -urn '1~5s;^.* V: +([0-9]+)(\.[0-9]+) A-V:.*$;\1;p' \
+  | while read m; do
+    printf "%s\n" "$(($m * 100 / $length))"
+  done \
+  | while read n; do
+    [ "$n" != "$previous" ] && printf "%s\n" "$n"
+    previous=$n
+  done
+}