This is a simple music player invoked from the command line. It's inspired by zigbert and Thunor.
Why do we need another music player? Why not!
The unique thing is that it uses just ffmpeg and aplay (the engine for Pmusic) which are in 99% of all puppies, even old ones, probably not really cut down ones but you never know.
It also uses busybox ash as the shell, to be faster and lighter.
Any way, paste the following code into your fav text editor and save as "ashmusic". Set exec permissions, plonk it in your executable PATH and you are ready to go.
It's invoked with ashmusic "/path/to/music file.mp3" (be sure to use quotes if you have spaces). It plays music well and even has some features as you may discover. It works equally as well outside of X.
TODO: add directory support.
Enjoy!
#!/bin/ash
#simple music player
#01micko 20111126
#GPLv3 see /usr/share/doc/legal
# (c) Mick Amadio 2011
#depends <-- ffmpeg, alsa (aplay)
set -e #stop on all errors
#workdir
[ ! -d $HOME/.ashmusic ] && mkdir $HOME/.ashmusic
HOMEDIR="$HOME/.ashmusic"
#usage
usagefunc(){
echo "Usage:
example: ashmusic \"/path/to/music file can have spaces.mp3\"
Options:
-h [display this help]
-a [add to playlist -track plays]
-l <name>(optional) load playlist [<name>]
<-- Supports whatever audio format your ffmpeg supports" && exit 0
}
[ ! "$1" ] && usagefunc
[ $(pidof aplay) ] && echo 'ERROR: can only have 1 instance' && exit 1
#play
playfunc(){
TRACKNAME=$(echo "$1"|tr '/' '\n'|tail -n1)
echo "Now playing: $TRACKNAME"
echo "Press \"q\" to quit"
ffmpeg -i "$1" -ss 0 -f au - 2>/tmp/ashmusic_ffmpeg | aplay 2> /dev/null ||\
echo "$1 not found"
rm -f /tmp/ashmusic*
echo "finished!"
}
#filter args
for arg in "$@"
do
case $arg in
-*h*) usagefunc
;;
-a)echo "Please type a playlist name"
read LISTNAME
[ ! -f $HOMEDIR/$LISTNAME ] && touch $HOMEDIR/$LISTNAME||\
echo "$LISTNAME exists! Appending track"
echo $LISTNAME > /tmp/ashmusic_add_track
;;
-l)NAME="$2"
ls -1 $HOMEDIR >/tmp/ashmusic_playlists
PLAYLISTS=$(cat /tmp/ashmusic_playlists)
if [ ! "$NAME" ];then
echo "$PLAYLISTS"
echo "Type the name of a playlist to load from the above list"
read NAME
fi
PLAYOK=$(grep "$NAME" /tmp/ashmusic_playlists)
[ ! "$PLAYOK" ] && echo "That list doesn't exist!" && exit 1
TRACKLIST="$(cat $HOMEDIR/$NAME|\
while read ALINE
do
echo $ALINE|tr '/' '\n'|tail -n1
done)"
echo "Tracklist:"
echo "$TRACKLIST"
echo ""
#cat $HOMEDIR/$NAME|\
#while read TLINE
#do
##[ "$TLINE" ] && playfunc "$TLINE" || break
#done #I'd like to know why the "while read LINE" routine failed!
cat $HOMEDIR/$NAME|tr ' ' '_' > $HOMEDIR/${NAME}.new
for i in $(cat $HOMEDIR/${NAME}.new)
do TRACK=$(echo "$i"|tr '_' ' ')
[ "$TRACK" ] && playfunc "$TRACK" || break
done
rm -f $HOMEDIR/${NAME}.new
;;
*)TRACK="$arg"
if [ -f /tmp/ashmusic_add_track ];then
TOADD=$(cat /tmp/ashmusic_add_track)
echo "$TRACK" >> $HOMEDIR/$TOADD
rm -f /tmp/ashmusic_add_track
fi
playfunc "$TRACK"
;;
esac
done
exit 0
NB: the < code > tags and backticks mess with the code!!!
EDIT: all subshells with backticks changed to $(do something here)
