Thread: aUDIOBOOK?
View Single Post
jldiaz's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#27
Originally Posted by MstPrgmr View Post
ok, so i got the original abplayer script to work. any ideas how i can get mplayer to show stats such as current position in audiobook mp3 while the script is running?
Change the last line in the script by this one:

Code:
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") {t=$2;printf $0"\r" > "/dev/stderr"}} END{print t}' > "$1".resume
The trick is: when awk detects a line beginning with "A:", it updates the variable t, and prints that line in the standard error output. This output is connected to the screen, so it is visible.

I use printf instead of print, because print always add a "\n" at the end, and this will result in a lot of lines printed. Using "\r", each line is overimposed on the previous one, and thus appears as a single line which updates itself.

I print $0, which means "the whole line as it was read", but if you prefer, you can parse it a bit. You have the current position in seconds in variable $2, and the current position in format "HH:MM:SS.dd" in variable $3. The total time in seconds is in $5, and the total time in format "HH:MM:SS.dd" in $7. Finally, $8 holds the CPU usage (not very useful, I would prefer a current position as a percentage of total). You can use this information and build your own status line, such as:

Code:
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") {t=$2;printf "Position: %s of (%s   %5.1f%% played\r", $3, $7, $2*100/$5 > "/dev/stderr"}} END{print t}'  > "$1".resume
Also note that, while mplayer is runnig, you can use some keys to control it, such as the cursor keys (up and right to seek forward in different amounts, down and left to rewind), space or return to pause, and q to quit among others.
__________________
--ル Diaz

Last edited by jldiaz; 2008-04-21 at 10:12. Reason: Removing spureous line