Thread: aUDIOBOOK?
View Single Post
jldiaz's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#7
Originally Posted by Benson View Post
Why does everyone want to do everything with Python?
Shell scripts, awk, etc. are more than sufficient for this task.
You are right. Using python for everything is a tic. I accomplished this task with a simple shell script and a little of awk. Here is how:

Copy the following code to a file named, for example abplayer (from "audiobook player), or wathever you like:

Code:
#!/bin/sh
if test -f "$1".resume
then
 resumepoint=`cat "$1".resume`
else
 resumepoint=0
fi
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' > "$1".resume
Put this file in a place where your shell can find it (I have a "bin" folder in my $HOME, and a line in the .profile for adding this folder to the PATH variable). Make executable this file (chmod +x abplayer).

Then, use it from the command line (xterm) like this:
Code:
$ abplayer /route/to/audiobook.mp3
The audio begins to play. When you press 'q', the player is exited, and a new file is created, with name /route/to/audiobook.mp3.resume which contains the time in which the playback was quitted. Next time you use abeplay, it will search for this file. If it founds it, the playback is resumed from that point. If not, it is restarted again from the beginning.

If the player exits unexpectedly and the .resume file is corrupt, you have to delete it (or you can write a correct one with any editor, it only contains the time where the playback has to be resumed, in the format hh:mm:ss.ff, being ff any fraction of second, for example: 3:21.52)

Originally Posted by Benson View Post
What format are your audiobooks? mpg123 might seem a more natural choice than mplayer, if they're mp3; otherwise mplayer might be better.
I used mplayer because I have it already installed, and supports a wide range of formats. As for mpg123, I did not find it with apt-cache...
__________________
--ル Diaz
 

The Following 4 Users Say Thank You to jldiaz For This Useful Post: