![]() |
2008-04-14
, 22:26
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#22
|
pwd ls -l abplayer cat abplayer
![]() |
2008-04-15
, 14:55
|
|
Posts: 96 |
Thanked: 7 times |
Joined on Sep 2007
|
#23
|
![]() |
2008-04-15
, 16:54
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#24
|
#!/bin/sh ls `pwd`/$1/*.mp3 > $1.m3u
![]() |
2008-04-20
, 13:44
|
|
Posts: 41 |
Thanked: 21 times |
Joined on Apr 2008
@ Nurnberg
|
#25
|
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:
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).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
Then, use it from the command line (xterm) like this:
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.Code:$ abplayer /route/to/audiobook.mp3
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)
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...
#!/bin/sh if [ -e $HOME/.mplayer/abook.plist ] && [ -z "$1" ] then LASTFILE=`cat $HOME/.mplayer/abook.resume | tail -n2 | awk -Fmp3 '{print $1}'` RESPOINT=`cat $HOME/.mplayer/abook.resume | tail -n1` FILESUM=`wc -l $HOME/.mplayer/abook.plist | awk '/[0-1]/ {print $1}'` CPLIST=`cat $HOME/.mplayer/abook.plist | grep -A$FILESUM "$LASTFILE"` elif [ -e $HOME/.mplayer/abook.plist ] && [ ! -z "$1" ] then echo " " > $HOME/.mplayer/abook.plist cd "$1" ABFILES=`ls -1` for I in $ABFILES do echo "`pwd`/$I" >> $HOME/.mplayer/abook.plist done CPLIST=`cat $HOME/.mplayer/abook.plist` RESPOINT=0 else echo "Usage: abplayer.sh /path/to/audiobook/dir/" exit fi mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume
![]() |
2008-04-20
, 14:18
|
Posts: 118 |
Thanked: 16 times |
Joined on Sep 2007
|
#26
|
![]() |
2008-04-21
, 09:51
|
|
Posts: 48 |
Thanked: 40 times |
Joined on Apr 2008
@ Spain
|
#27
|
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?
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") {t=$2;printf $0"\r" > "/dev/stderr"}} END{print t}' > "$1".resume
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
![]() |
2008-04-21
, 10:06
|
|
Posts: 48 |
Thanked: 40 times |
Joined on Apr 2008
@ Spain
|
#28
|
Thanks for idea.
My scripting skills are not so good... but this script works %)
Code:...(omitted)...
how from last 3 lines make only one line? :/Code:... mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume
thanks.
mplayer -ss $RESPOINT $CPLIST | awk 'BEGIN{RS="\r"}/Playing/{print $2}/^A:/{t=$2}END{print t}' > $HOME/.mplayer/abook.resume
![]() |
2008-04-21
, 10:43
|
|
Posts: 41 |
Thanked: 21 times |
Joined on Apr 2008
@ Nurnberg
|
#29
|
It did not work for me... I'm unsure why (because I don't fully understand its purpose, for example, the variable FILESUM). I have some ogg files, and your script relies on the assumption that only mp3 files are present.
Anyway...
#!/bin/sh if [ -z "$1" ] then LASTFILE=`cat $HOME/.mplayer/abook.resume | tail -n2 | awk -Fmp3 '{print $1}'` RESPOINT=`cat $HOME/.mplayer/abook.resume | tail -n1` FILESUM=`wc -l $HOME/.mplayer/abook.plist | awk '/[0-1]/ {print $1}'` CPLIST=`cat $HOME/.mplayer/abook.plist | grep -A$FILESUM "$LASTFILE"` else echo " " > $HOME/.mplayer/abook.plist cd "$1" ABFILES=`ls -1` for I in $ABFILES do echo "`pwd`/$I" >> $HOME/.mplayer/abook.plist done CPLIST=`cat $HOME/.mplayer/abook.plist` RESPOINT=0 fi mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume
What about the following? (not tested)
The use of pipes in a single line avoids the existence of the temporal file, which is a good thing, because that file grows very faster (mplayer outputs status information about ten times per second!)Code:mplayer -ss $RESPOINT $CPLIST | awk 'BEGIN{RS="\r"}/Playing/{print $2}/^A:/{t=$2}END{print t}' > $HOME/.mplayer/abook.resume
Btw, /home is not a good place to leave things. Better at /home/user, which is you user folder.
--ル Diaz