Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 23 Oct 2014, 01:12
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Multimedia
ashmusic -commandline music player
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7835
Location: qld

PostPosted: Mon 28 Nov 2011, 00:37    Post subject:  ashmusic -commandline music player
Subject description: uses ffmpeg, supports many formats, uses busybox ash shell
 

As seen on raffy's Puppy Help forum I made a script I call ashmusic

This is the second version with added directory support and the duration of the current track is displayed.

It may be a little heavy on resources with an older machine but the tradeoff is the number of formats it supports, it supports whatever your version of ffmpeg supports. Ffmpeg has been in all mainstream puppies for a long time. It may not be in heavily cut down puplets.

It uses the Pmusic engine by transcoding the file to .au format and piping to aplay. It works equally as well outside of X.. if anyone actually does that anymore! Should also run on any *nix.

You can create custom playlists and also a directory once played is stored as a playlist.

It handles spaces in filenames as long as you wrap the path in quotes, single or double.
Code:
# ashmusic
ashmusic-0.2 GPL3
Usage:
example: ashmusic "/path/to/music file can have spaces.mp3"
Options:
   -h   [display this help]
   -a <track> [add to playlist -track plays]
   -b <track> [add to playlist -track doesn't play]
   -d <directory> [add a whole directory as playlist]
   -l <name>(optional) [load playlist <name>]
You can use "ctrl - c" to quit at any time.
<-- Supports whatever audio format your ffmpeg supports
Code:
# ashmusic -l
angels
Judas_Priest
MCR
Sad_Wings_of_Destiny
The_Black_Parade
Type the name of a playlist to load from the above list
The_Black_Parade
Tracklist:
01 The End..mp3
02 Dead!.mp3
03 This Is How I Disappear.mp3
04 The Sharpest Lives.mp3
05 Welcome to the Black Parade.mp3
06 I Don't Love You.mp3
07 House of Wolves.mp3
08 Cancer.mp3
09 Mama.mp3
10 Sleep.mp3
11 Teenagers.mp3
12 Disenchanted.mp3

Now playing: 01 The End..mp3
Press "q" to skip
Duration:00:01:53
finished!
Now playing: 02 Dead!.mp3
Press "q" to skip
Duration:00:03:15


Have fun!
ashmusic-0.2.pet
Description 
pet

 Download 
Filename  ashmusic-0.2.pet 
Filesize  1.92 KB 
Downloaded  236 Time(s) 

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Fri 23 Dec 2011, 13:28    Post subject:  

you can also pipe .au to /dev/audio and .wav to /dev/dsp iirc in case aspell is missing
there are a couple of other formats that work this way too

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7835
Location: qld

PostPosted: Mon 02 Jan 2012, 07:00    Post subject:  

Tried piping to /dev/audio, didn't work.

Anyway, I implemented a feature I wanted, time progress of track. You'll see the code in the 'progressfunc'. Had to put in some weird filters for some garbage. I got the idea from Paul Colby.

The echo method is ok, but there is the tiniest of lag and sometimes you can just see the back spaces. The printf method seems flawless.
Code:
#!/bin/ash
#simple music player
#01micko 20111126
#GPLv3 see /usr/share/doc/legal
# (c) Mick Amadio 2011-2012
#depends <-- ffmpeg, alsa (aplay)
#v0.2 111128
#v0.3 120102

set -e #stop on all errors
#workdir
[ ! -d $HOME/.ashmusic ] && mkdir $HOME/.ashmusic
HOMEDIR="$HOME/.ashmusic"

#usage
usagefunc(){
echo "ashmusic-0.3 GPL3
Usage:
example: ashmusic \"/path/to/music file can have spaces.mp3\"
Options:
   -h   [display this help]
   -a <track> [add to playlist -track plays]
   -b <track> [add to playlist -track doesn't play]
   -d <directory> [add a whole directory as playlist]
   -l <name>(optional) [load playlist <name>]
You can use \"ctrl - c\" to quit at any time.
<-- Supports whatever audio format your ffmpeg supports" && exit 0
}

[ ! "$1" ] && usagefunc

[ $(pidof aplay) ] && echo 'ERROR: can only have 1 instance' && exit 1

#duration
durfunc(){
sleep 1
DUR=$(grep -wE "Duration" /tmp/ashmusic_ffmpeg|tr -d ' '|head -c17)
echo
[ "$DUR" ] && echo "$DUR"
}

#progress #this is slow
progressfunc(){
sleep 1
while [ -f /tmp/ashmusic_ffmpeg ]; do
 PROGRESS=$(tail -n1 /tmp/ashmusic_ffmpeg|sed -e 's%.*time\=%%'\
 -e 's%\..*%%')
 [ "`echo $PROGRESS|grep "video"`" ] && PROGRESS="" #filters for last lines >
 [ "`echo $PROGRESS|grep "Error"`" ] && PROGRESS="" #that we don't want
 [ "`echo $PROGRESS|grep "li"`" ] && PROGRESS=""
 [ "`echo $PROGRESS|grep "Header"`" ] && PROGRESS=""
 [ "`echo $PROGRESS|grep "Press"`" ] && PROGRESS=""
 #[ "$PROGRESS" != "" ] && echo -en "\r Time:${PROGRESS} \b"
 [ "$PROGRESS" != "" ] && printf "\r%s" "Time:${PROGRESS}"
 sleep 1
 done
}

#play
playfunc(){
SKIPORQUIT="$2"
[ ! "$SKIPORQUIT" ] && SKIPORQUIT="quit"
TRACKNAME=$(echo "$1"|tr '/' '\n'|tail -n1)
echo "Now playing: $TRACKNAME"
durfunc &
progressfunc &
echo "Press \"q\" to $SKIPORQUIT"
ffmpeg -i "$1" -ss 0  -f au - 2>/tmp/ashmusic_ffmpeg | aplay 2> /dev/null ||\
echo "$1 not found" #/dev/audio
rm -f /tmp/ashmusic*
echo -e "\nfinished!\n========================================================"
}

#play list
playlistfunc(){
   TRACKLIST="$(cat $HOMEDIR/$1|\
   while read ALINE
    do
    echo $ALINE|tr '/' '\n'|tail -n1
    done)"
   echo "Tracklist:"
   echo "$TRACKLIST"
   echo ""
    cat $HOMEDIR/$1|tr ' ' '_' > $HOMEDIR/${1}.new
    for i in $(cat $HOMEDIR/${1}.new)
     do TRACK=$(echo "$i"|grep "\."|tr '_' ' ')
     #rm /tmp/ashmusic*
     sleep 0.5
     [ "$TRACK" ] && playfunc "$TRACK" skip|| break
     done
    rm -f $HOMEDIR/*.new   && exit 0
}

#add playlist
addfunc(){
set +e #unset set -e, grep throws the error
NOTEXISTS=$(file "$1"|grep "cannot open")
[ "$NOTEXISTS" ] && \
echo ""$1" doesn't exist! Check the spelling or path" && exit 1
set -e
echo "Please type a playlist name"
read LISTNAME
[ ! -f $HOMEDIR/$LISTNAME ] && touch $HOMEDIR/$LISTNAME||\
echo "$LISTNAME exists! Appending track"   
}

#filter args
for arg in "$@"
 do
   case $arg in
   -*h*) usagefunc
   ;;
   -a)[ ! "$2" ] && usagefunc
   addfunc "$2" #add to playlist and play
   echo $LISTNAME > /tmp/ashmusic_add_track
   ;;
   -b)[ ! "$2" ] && usagefunc
   addfunc "$2" #add to playlist, don't play
   echo "$2" >> $HOMEDIR/$LISTNAME
   exit 0
   ;;
   -d)LISTDIR="$2" #add dir as playlist, play or not
   USELISTDIR=$(basename "$LISTDIR")
   DLIST=$(ls -1 "$LISTDIR"|grep -iE "\.mp3$|\.aif$|\.ogg$|\
   \.wma$|\.ra|\.wav$|\.aac$")
   echo "Type a name for your directory playlist (no spaces) then \"Enter\""
   echo "or just \"Enter\" to use "$USELISTDIR""
   read DPLAYLIST
   if [ ! "$DPLAYLIST" ];then
    DPLAYLIST=$(echo "$USELISTDIR"|tr ' ' '_')
   fi
   [ -f "$HOMEDIR/$DPLAYLIST" ] && echo ""$DPLAYLIST" already exists! Exiting.."\
   && exit 0
   echo "$DLIST"|\
   while read DLINE
    do echo "$LISTDIR/$DLINE" >> $HOMEDIR/$DPLAYLIST
    done
   echo "$DPLAYLIST is stored. Press \"p - Enter\""
   echo "now to play $DPLAYLIST or \"enter\" to quit"
   read PLAYNOW
   [ ! "$PLAYNOW" = "p" ] && exit 0 || echo "Playing $DPLAYLIST"
    echo "$DPLAYLIST"
    playlistfunc "$DPLAYLIST"
   ;;
   -l)NAME="$2" #play playlist
   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
   playlistfunc "$NAME"
   ;;
   *)TRACK="$arg" #play track only
     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

ashmusic-0.3.pet
Description 
pet

 Download 
Filename  ashmusic-0.3.pet 
Filesize  2.18 KB 
Downloaded  199 Time(s) 
ash0.png
 Description   
 Filesize   27.05 KB
 Viewed   491 Time(s)

ash0.png

ash1.png
 Description   
 Filesize   23.84 KB
 Viewed   532 Time(s)

ash1.png


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
darkcity


Joined: 23 May 2010
Posts: 2462
Location: near here

PostPosted: Mon 02 Jan 2012, 14:39    Post subject:  

other players are here ; -)
http://puppylinux.org/wikka/CommandLinePrograms

_________________
helping Wiki for help | IF SendSpace link = "dead" THEN PM me ("up file to http://meownplanet.net/")
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Multimedia
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0780s ][ Queries: 13 (0.0064s) ][ GZIP on ]