13133 playd: Easy to use mplayer wrapper with playlist support [Archive] - The FreeBSD Forums

PDA

View Full Version : playd: Easy to use mplayer wrapper with playlist support


graudeejs
May 17th, 2009, 17:47
playd is a simple to use mplayer wrapper script.

Playd was designed to avoid installing mplayer GUI, which are far from perfect.

playd starts mplayer in slave mode and controls it with pipe.
It only depends on mplayer and FreeBSD base system (it can be ported to other systems)

It's possible to integrate playd in desktop environment (assign commands to shortcuts, integrate in menu, etc...)

Command line arguments are simple and easy to remember.


Features:

Extremely easy to use
Supports creation and playing of simple plain text playlists
1 dependency (multimedia/mplayer)
Very fast and small
K.I.S.S. - Keep It Small & Simple


I think it's perfect for people who want to use mplayer for everything.

new versions will be announced on this thread with link attached

Please, let me know about bugs in playd here

playd is available in ports collection:
multimedia/playd


[EDIT]
http://hg.bsdroot.lv/pub/aldis/playd.sh/
http://wiki.bsdroot.lv/playd

vivek
May 17th, 2009, 17:55
I use the -playlist option:
mplayer -playlist mp3.list
Will try out this one too.

graudeejs
May 17th, 2009, 18:00
I use the -playlist option:
mplayer -playlist mp3.list
Will try out this one too.

you won't need do keep virtual terminal opened. And still be able to pause, skip tracks etc.

Edit:
It also makes playlists ;)

meeb
May 17th, 2009, 18:06
I like and use that script. Thanks to killasmurf86!

graudeejs
June 2nd, 2009, 15:56
seams playd 1.1.5 will be available in ports any day now

LateNiteTV
June 2nd, 2009, 17:01
thanks killasmurf. this is a pretty handy script.

graudeejs
June 7th, 2009, 09:41
playd is now available in ports

for some reason commiter named it multimedia/dplay after you install you need to run playd....

I already emailed on this matter, and either I will change name to dplay or port will be renamed to playd (I prefer 2nd choice)

graudeejs
June 9th, 2009, 23:47
playd port got renamed to original name

multimedia/playd

blah
June 11th, 2009, 19:54
Some garbage crept in@@ -76,7 +76,7 @@ some_file [0|1] - play
some_dir [0|1] - play dir

http://playlist.on.net.m3u - play internet stream (radio in this example)
-ftp://ftp.me.com/cool_movie.avi - play stream from ftp serverYD_HOME/
+ftp://ftp.me.com/cool_movie.avi - play stream from ftp server
playlist [cusom_playlist] [0|1] - play playlist [1=append, 0=new playlist]
play ID - play specific item from playlist
Wouldn't it be better to rely on ~/.mplayer/config for video output drivers and software scaling? MPlayer already tries xv first and then falls back to x11. Some drivers may be undesirable (e.g. dga), so it's better to not hardcode them.@@ -51,7 +51,7 @@ PLAYD_PLAYLIST="$PLAYD_HOME/playd_playli
PLAYD_LOCK="$PLAYD_HOME/playd.lock"

MPLAYER_VERBOCITY=-1
-MPLAYER_CMD="mplayer -vo xv,x11,xvidix,gl,dga -zoom -msglevel all=$MPLAYER_VERBOCITY -quiet -idle -input file=$PLAYD_PIPE"
+MPLAYER_CMD="mplayer -msglevel all=$MPLAYER_VERBOCITY -quiet -idle -input file=$PLAYD_PIPE"
MPLAYER_SND_ONLY_CMD="mplayer -vo null -msglevel all=$MPLAYER_VERBOCITY -quiet -idle -input file=$PLAYD_PIPE"

# print helpWhy you discourage other schemes:// ?
I like to fill my playlist with entries from smb:// hosts@@ -405,7 +405,7 @@ if [ "$1" ]; then
echo 'loadfile dvd://' > "$PLAYD_PIPE"
;;

- 'http://'* | 'ftp://'* )
+ *'://'* )
playd_start '0' 'silent'
echo "loadfile $1" > "$PLAYD_PIPE"
;;mplayer spams to attached terminal on any error in audio/video stream. I think it's better to redirect stderr to /dev/null or just close ( `2>&-' ) it.mpg123: Can't rewind stream by 184 bits!
...
[flac @ 0x804a4e110]FRAME HEADER not here
Last message repeated 4 times
[flac @ 0x804a4e110]invalid sample size code (3)
[flac @ 0x804a4e110]invalid frame header
[flac @ 0x804a4e110]decode_frame() failed
[flac @ 0x804a4e110]FRAME HEADER not here

graudeejs
June 12th, 2009, 07:05
I fixed lines you mentioned.
The reasons mplayer_cmd line existed at all, is that few months ago, i had problem with mplayer, that is now fixed, at that time, it was much more easier to edit playd and fix mplayer with command line, than to read how to edit ~/.mplayer/config

--------

How to redirect stderr to /dev/null?


or just close ( `2>&-' ) it.
I don't really understand this (where and how to add? At the end of mplayer_cmd right?)

--------

Hey, i was also wondering, how could i check file extensions? (I need some awk/sed help on this)
This could speed up making playlists by factor ~20-30


I have started writing playd2 in perl. After some thinking I decided to check for extensions first and then fall back to mime, because many mp3's report their mime as application/octet-stream. In playd.sh i simply added them to playlist, which is wrong, because there are other file types, that report to be application/octet-stream.

blah
June 12th, 2009, 09:32
Here is some bug$ sh -x $(which playd) stop
+ PLAYD_VERSION=1.1.5
+ PLAYD_HOME=/home/luser/.mplayer
+ PLAYD_PIPE=/home/luser/.mplayer/playd.fifo
+ PLAYD_PLAYLIST=/home/luser/.mplayer/playd_playlist.txt
+ PLAYD_LOCK=/home/luser/.mplayer/playd.lock
+ MPLAYER_VERBOCITY=-1
+ MPLAYER_CMD=mplayer -vo xv,x11,xvidix,gl,dga -zoom -msglevel all=-1 -quiet -idle -input file=/home/luser/.mplayer/playd.fifo
+ MPLAYER_SND_ONLY_CMD=mplayer -vo null -msglevel all=-1 -quiet -idle -input file=/home/luser/.mplayer/playd.fifo
+ [ ! /home/luser ]
+ [ ! -d /home/luser/.mplayer ]
+ [ ! -p /home/luser/.mplayer/playd.fifo ]
+ mplayer_instaled=no
+ echo /usr/local/libexec/ccache:/usr/local/libexec/usr:/home/luser/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/luser/bin:/home/luser/local/bin
+ tr :
+ [ -f /usr/local/libexec/ccache/mplayer ]
+ [ -f /usr/local/libexec/usr/mplayer ]
+ [ -f /home/luser/local/bin/mplayer ]
+ mplayer_instaled=yes
+ break
+ [ yes = no ]
+ [ stop ]
+ playd_stop
+ playd_check
+ [ -f /home/luser/.mplayer/playd.lock ]
+ cat /home/luser/.mplayer/playd.lock
+ pidStored=12071
+ pgrep mplayer
+ [ 12071 = 12071 ]
+ return 12071
+ [ 12071 = 0 ]
+ echo quit
+ playd_check
+ [ -f /home/luser/.mplayer/playd.lock ]
+ cat /home/luser/.mplayer/playd.lock
+ pidStored=12071
+ pgrep mplayer
+ [ 12071 = 12071 ]
+ return 12071
+ [ 12071 != 0 ]
+ kill 0
zsh: terminated sh -x $(which playd) stopSpotted on 8-CURRENT. Look at PID of the kill'd process. Possible fix is to NOT rely on exit code@@ -105,19 +105,22 @@ playd_check() {
# probably won't find mplayer if launched with console
# potential bug
for pid in `pgrep mplayer`; do
- if [ "$pid" = "$pidStored" ]; then return "$pidStored"; fi
+ if [ "$pid" = "$pidStored" ]; then
+ echo $pidStored
+ return
+ fi
done
rm -f "$PLAYD_LOCK"
fi
- return 0
+ echo 0
}


# start daemon
playd_start() {
- playd_check
+ local pid=$(playd_check)

- if [ "$?" -eq 0 ]; then
+ if [ $pid -eq 0 ]; then
if [ "$1" = 'novid' ]; then
cd /
exec $MPLAYER_SND_ONLY_CMD > /dev/null 2> /dev/null &
@@ -139,14 +142,14 @@ playd_start() {

# stop daemon
playd_stop() {
- playd_check
- if [ "$?" = 0 ]; then
+ local pid=$(playd_check)
+
+ if [ $pid -eq 0 ]; then
echo 'playd is not running'
else
echo 'quit' >> "$PLAYD_PIPE"
- playd_check
- if [ "$?" != 0 ]; then
- kill "$?"
+ if [ $pid -ne 0 ]; then
+ kill $pid
rm -f "$PLAYD_LOCK"
fi
fi
@@ -260,7 +263,7 @@ if [ $mplayer_instaled = 'no' ]; then
exit 1
fi

-
+pid=$(playd_check)

# check command line arguments
if [ "$1" ]; then
@@ -350,8 +353,7 @@ if [ "$1" ]; then
;;

'mute' )
- playd_check
- if [ ! "$?" = 0 ]; then
+ if [ $pid -ne 0 ]; then
echo 'mute' > "$PLAYD_PIPE"
else
echo "playd doesn't seam to be running"
@@ -359,8 +361,7 @@ if [ "$1" ]; then
;;

'pause' )
- playd_check
- if [ ! "$?" = 0 ]; then
+ if [ $pid -ne 0 ]; then
echo 'pause' > "$PLAYD_PIPE"
else
echo "playd doesn't seam to be running"
@@ -368,8 +369,7 @@ if [ "$1" ]; then
;;

'seek' )
- playd_check
- if [ ! "$?" = 0 ]; then
+ if [ $pid -ne 0 ]; then
echo "seek $2 $3" > "$PLAYD_PIPE"
else
echo "playd doesn't seam to be running"
@@ -377,8 +377,7 @@ if [ "$1" ]; then
;;

'next' )
- playd_check
- if [ ! "$?" = 0 ]; then
+ if [ $pid -ne 0 ]; then
echo "seek 100 1" > "$PLAYD_PIPE"
else
echo "playd doesn't seam to be running"
@@ -386,8 +385,7 @@ if [ "$1" ]; then
;;

'status' )
- playd_check
- if [ "$?" = 0 ]; then
+ if [ $pid -eq 0 ]; then
echo 'playd is not running'
else
echo 'play is running'There is some obvious code duplication in case statement that can be removed with simple function that sends string into pipe# put argv into pipe
# ex.: playd_put seek 100
playd_put() {
local pid=$(playd_check)

if [ $pid -ne 0 ]; then
echo "$@" >> "$PLAYD_PIPE"
else
echo "playd doesn't seam to be running"
return 1
fi
}So you can use smth like this in case statement 'seek' )
playd_put seek $2 $3
;;How to redirect stderr to /dev/null?foo 2>/dev/null@@ -120,11 +120,11 @@ playd_start() {
if [ "$?" -eq 0 ]; then
if [ "$1" = 'novid' ]; then
cd /
- exec ${MPLAYER_SND_ONLY_CMD} >> /dev/null &
+ exec $MPLAYER_SND_ONLY_CMD > /dev/null 2> /dev/null &
echo "$!" > "$PLAYD_LOCK"
else
cd /
- exec ${MPLAYER_CMD} >> /dev/null &
+ exec $MPLAYER_CMD > /dev/null 2> /dev/null &
echo "$!" > "$PLAYD_LOCK"
fi
elseHey, i was also wondering, how could i check file extensions? (I need some awk/sed help on this)
This could speed up making playlists by factor ~20-30$ foo=smb://host/pub/muz/ly/openbsd.4.5.games.ogg

$ foo_ext=${foo##*.}; echo $foo_ext
ogg

$ foo_dir=${foo%/*}; echo $foo_dir
smb://host/pub/muz/ly
$ dirname $foo
smb://host/pub/muz/ly

$ foo_base=${foo##*/}; echo $foo_base
openbsd.4.5.games.ogg
$ basename $foo
openbsd.4.5.games.oggIt's explained in section Parameter Expansion in sh. Try this@@ -170,7 +170,7 @@ playd_mk_playlist() {
# for some reason i have seen some mp3's to be reported as "application/octet-stream"
# because of that playd didn't play them earlier.
# thsi fixes the problem.... hopefully i will find better solution
- if [ $(file -ib "$1/$fileName" | tr " " "_") = 'application/octet-stream' ]; then
+ if [ "${fileName##*.}" = 'mp3' ]; then
echo "$1/$fileName" >> "$PLAYD_PLAYLIST.tmp"
fi
;;
I decided to check for extensions first and then fall back to mime, because many mp3's report their mime as application/octet-stream.I'd rely on mime-type and if it's application/octet-stream only then check extension. This way some_file.mp3 that is actually text/plain wouldn't end up in playlist by accident.

graudeejs
June 12th, 2009, 10:16
But there's also questions performance vs correctness

If differance is small, that i'd prefer correctness.
But on perl, i have gained performance boost up to x30 by checking extensions first.
(i recall numbers 2m vs 4s, i will provide results once my I/O Buffer is clean)




Let's face the fact:
How often do you see text file with mp3 extension?

The file that is reported as application/octet-stream could as well be plain text (i have seen some) and have mp3 extension....
it would be very rear case...

that's why I would prefer to check extension and fallback to mime

blah
June 12th, 2009, 11:41
on perl, i have gained performance boost up to x30 by checking extensions first.Since you already do benchmarks how about pure shell (except file(1) + cut(1)) vs. pure perl traversing directories#! /bin/sh

# generate playlist from file/directory
# usage: playd_mk_playlist <file | directory>
playd_mk_playlist() {
for fileName in "$1"/*; do
# XXX: recursion is slower than simple `while' loop
if [ -d "$fileName" ]; then
playd_mk_playlist "$fileName"
fi
case "${fileName##*.}" in
mp3 );;
ogg );;
flac );;
avi );;
mkv );;
* ) # no known extension found, try mime-type then
mime=$(file -ib "$fileName" | cut -d\; -f1)
case $mime in
audio* | video* );;
* ) continue # jump to next file
esac
esac
# finally, add file
echo adding \"$fileName\"
# echo "$fileName" >> "$PLAYD_PLAYLIST.tmp"
done
}

set -o xtrace
playd_mk_playlist /d/muz

graudeejs
June 12th, 2009, 12:52
I run test on 2454 music files (with some crap files in directories)

my test showed:
1m 7s to 1m 20 when checking mime first and fallback to extensions
vs
3s to 5s when checking extensions first fallback to mime


I think numbers speak clearly


P.S.
I modified your code and implemented it directly

graudeejs
June 12th, 2009, 13:18
Here's latest version
http://www.failiem.lv/down.php?i=zdewqn&n=playd-1.2.0.tar.bz2

blah
June 12th, 2009, 13:52
Please, keep lines under 80 chars long. They don't fit on my screen (xterm on 1600x1200, DejaVu Sans Mono-24).

BTW, why not add failiem.lv as a mirror for distfile into portIndex: multimedia/playd/Makefile
================================================== =================
RCS file: /home/csup/ports/multimedia/playd/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- multimedia/playd/Makefile 9 Jun 2009 16:04:31 -0000 1.1
+++ multimedia/playd/Makefile 12 Jun 2009 12:53:26 -0000
@@ -8,13 +8,17 @@
PORTNAME= playd
PORTVERSION= 1.1.5
CATEGORIES= multimedia
-MASTER_SITES= http://www.logvinov.ru/files/dist/playd/
+MASTER_SITES= http://www.logvinov.ru/files/dist/playd/ \
+ http://www.failiem.lv/down.php?i=${MAGIC_KEY}&n=

MAINTAINER= killasmurf86@gmail.com
COMMENT= Very easy to use mplayer sh wrapper script, with usefull features

RUN_DEPENDS= mplayer:${PORTSDIR}/multimedia/mplayer

+FETCH_BEFORE_ARGS= -o${DISTFILES}
+MAGIC_KEY= qqekrf
+
PLIST_FILES= bin/playd

NO_BUILD= yes

graudeejs
June 12th, 2009, 13:59
Please, keep lines under 80 chars. They doesn't fit on my screen` (xterm on 1600x1200, DejaVu Sans Mono-24).

OH, brother, why do you use such a big font? on such a big screen, on X?





BTW, why not add failiem.lv as a mirror for distfile into portIndex: multimedia/playd/Makefile
================================================== =================
RCS file: /home/csup/ports/multimedia/playd/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- multimedia/playd/Makefile 9 Jun 2009 16:04:31 -0000 1.1
+++ multimedia/playd/Makefile 12 Jun 2009 12:53:26 -0000
@@ -8,13 +8,17 @@
PORTNAME= playd
PORTVERSION= 1.1.5
CATEGORIES= multimedia
-MASTER_SITES= http://www.logvinov.ru/files/dist/playd/
+MASTER_SITES= http://www.logvinov.ru/files/dist/playd/ \
+ http://www.failiem.lv/down.php?i=${MAGIC_KEY}&n=

MAINTAINER= killasmurf86@gmail.com
COMMENT= Very easy to use mplayer sh wrapper script, with usefull features

RUN_DEPENDS= mplayer:${PORTSDIR}/multimedia/mplayer

+FETCH_BEFORE_ARGS= -o${DISTFILES}
+MAGIC_KEY= qqekrf
+
PLIST_FILES= bin/playd

NO_BUILD= yes


Originally Port had failiem.lv as mirror...
for some reason portlint yells, that mirror doesn't end with /

Before that I didn't thought of MAGIC_KEY.... (this is pretty much my first port)
I'll speak to committer about that.

EDIT:
fixed misspelling

blah
June 12th, 2009, 15:36
'vol' )
mixer pcm ${2}
;;After ariff@ introduced VPC (http://people.freebsd.org/~ariff/SOUND_4.TXT.html) (Volume Per Channel) changing master pcm volume directly is a bad idea. Better would be to use mplayer slave interface.

playd_put volume $2 $3

BTW, I think there should be playd command that allows passing arguments directly to mplayer. It would be useful when one needs to send some less frequent command like `loop'.'quote' )
shift
playd_put $@
;;

graudeejs
June 12th, 2009, 16:37
'vol' )
mixer pcm ${2}
;;After ariff@ introduced VPC (http://people.freebsd.org/~ariff/SOUND_4.TXT.html) (Volume Per Channel) changing master pcm volume directly is a bad idea. Better would be to use mplayer slave interface.

playd_put volume $2 $3

BTW, I think there should be playd command that allows passing arguments directly to mplayer. It would be useful when one needs to send some less frequent command like `loop'.'quote' )
shift
playd_put $@
;;

Implemented (look at first post for link to new version)

blah
June 12th, 2009, 17:41
PLAYD_HOME=$HOME/.mplayer
PLAYD_PIPE=$PLAYD_HOME/playd.fifo
PLAYD_PLAYLIST=$PLAYD_HOME/playd_playlist.txt
PLAYD_LOCK=$PLAYD_HOME/playd.lock
It's safe to assume that all path variables (may) contain spaces.
pw user add test -md '/home/foo bar' ($HOME with spaces inbetween)
su -l test
sh -x $(which playd) start
+ PLAYD_VERSION=1.2.1
+ PLAYD_HOME=/home/foo bar/.mplayer
+ PLAYD_PIPE=/home/foo bar/.mplayer/playd.fifo
+ PLAYD_PLAYLIST=/home/foo bar/.mplayer/playd_playlist.txt
+ PLAYD_LOCK=/home/foo bar/.mplayer/playd.lock
+ MPLAYER_VERBOCITY=-1
+ MPLAYER_GENERIC_CMD=mplayer -msglevel all=-1
+ MPLAYER_CMD=mplayer -msglevel all=-1 -quiet -idle -input file=/home/foo bar/.mplayer/playd.fifo
+ MPLAYER_SND_ONLY_CMD=mplayer -msglevel all=-1 -vo null -quiet -idle -input file=/home/foo bar/.mplayer/playd.fifo
+ which mplayer
+ [ ! /home/foo bar/bin/mplayer ]
[: /home/foo: unexpected operator
+ [ ! /home/foo bar ]
[: /home/foo: unexpected operator
+ [ ! -d /home/foo bar/.mplayer ]
[: /home/foo: unexpected operator
+ [ ! -p /home/foo bar/.mplayer/playd.fifo ]
[: /home/foo: unexpected operator
+ [ start ]
+ playd_start
+ playd_check
+ [ -f /home/foo bar/.mplayer/playd.lock ]
[: /home/foo: unexpected operator
+ return 0
+ [ 0 -eq 0 ]
+ [ = novid ]
[: =: unexpected operator
+ cd /
+ exec mplayer -msglevel all=-1 -quiet -idle -input file=/home/foo bar/.mplayer/playd.fifo
+ echo 26533
+ exit 0

There is another bug on `playd start'. It's because $1 undefined. In such a case one can enclose varable in double quotes so when test evaluates it becomes string with only NUL char.
[ $blah = foo ]
[: =: unexpected operator
echo $?
2
[ "$blah" = foo ]
echo $?
1

playd stop
load: 0.08 cmd: sh 27830 [fifoow] 0.35r 0.00u 0.00s 0% 1788k
Appeared: 1.2.0
Possible cause: playd_put sends data to a disconnected named pipe in playd_stop

graudeejs
June 12th, 2009, 18:52
dam....
I had all variables double quoted.... and then one day i unquoted them (something strike me)


grrrrrrrrrrrr, i'm mad at me....
Will fix ASAP

graudeejs
June 12th, 2009, 20:30
fixed (i found some more bugs myself), hopefully no more bugs. lol

This was good lesson for me:
If you quote everything don't remove quotes later :D

link as usually on 1st post
EDIT:

Uploaded v1.2.3

blah
June 15th, 2009, 11:40
playd_stop() {
playd_put quit
if [ ! "$?" ]; then[ ! "0" ] && echo not zero
[ ! "1" ] && echo not non-zero
Both tests return non-zero (false). `$?' needs to be null string or undefined for test to return 0 (true). Is this intended?

Here is a specific for 1.2.3, MPLAYER_CMD related:
mplayer --msglevel all=-1
Unknown option on the command line: --msglevel
Error parsing option on the command line: --msglevel
MPlayer SVN-r29362-4.5.0 (C) 2000-2009 MPlayer Team

graudeejs
June 15th, 2009, 21:04
another bug

--- playd-1.2.3/playd 2009-06-13 13:17:31.299309947 +0300
+++ playd-1.2.4/playd 2009-06-15 23:14:09.546677243 +0300
@@ -40,7 +40,7 @@
# BUGS: there are probably some, but they aren't pretty important
# However if you find them, or can tell me how to reproduce them let me know :D

-PLAYD_VERSION="1.2.3"
+PLAYD_VERSION="1.2.4"

PLAYD_HOME="$HOME/.mplayer"
PLAYD_PIPE="$PLAYD_HOME/playd.fifo"
@@ -105,7 +105,7 @@
# put argv into pipe
playd_put() {
playd_check
- if [ "$?" -ne 0 ]; then
+ if [ $? -gt 0 ]; then
echo "$@" >> "$PLAYD_PIPE"
return 0
fi
@@ -133,7 +133,7 @@
playd_start() {
playd_check

- if [ "$?" -eq 0 ]; then
+ if [ $? -eq 0 ]; then
cd /
if [ "$1" = 'novid' ]; then
exec ${MPLAYER_SND_ONLY_CMD} > /dev/null 2> /dev/null &
@@ -155,20 +155,20 @@
# stop playd daemon
playd_stop() {
playd_put quit
- if [ ! "$?" ]; then
+ if [ $? -gt 0 ]; then
sleep 1 # give mplayer 1s to quit
playd_check
- kill_pid="$?"
- if [ "$kill_pid" ]; then
+ kill_pid=$?
+ if [ $kill_pid -gt 0 ]; then
kill "$kill_pid"
sleep 1
playd_check
- kill_pid="$?"
- if [ "$kill_pid" ]; then
+ kill_pid=$?
+ if [ $kill_pid -gt 0 ]; then
kill -9 "$kill_pid"
sleep 1
playd_check
- if [ "$?" ]; then
+ if [ $? -gt 0 ]; then
echo "can't kill mplayer"
return 1
fi
@@ -230,7 +230,7 @@
if [ -d "$1" ]; then
playd_mk_playlist "$1"

- if [ "$2" = 1 ]; then
+ if [ "$2" = "1" ]; then
echo "directory '$1' appended to current playlist"
else
echo "Now playing directory: '$1'"
@@ -242,7 +242,7 @@
elif [ -f "$1" ]; then
playd_put "loadfile '$1' $2"

- if [ "$2" = 1 ]; then
+ if [ "$2" = "1" ]; then
echo "file '$1' appended to current playlist"
else
echo "Now playing file: '$1'"
@@ -281,7 +281,7 @@

if [ ! -d "$PLAYD_HOME" ]; then
mkdir "$PLAYD_HOME"
- if [ "$?" != 0 ]; then
+ if [ $? -gt 0 ]; then
echo "Can't create $PLAYD_HOME"
echo 'Exiting'
fi
@@ -394,10 +394,10 @@

'status' )
playd_check
- if [ "$?" = 0 ]; then
- echo 'playd is not running'
- else
+ if [ $? -gt 0 ]; then
echo 'play is running'
+ else
+ echo 'playd is not running'
fi
;;

blah
June 15th, 2009, 22:01
Here is a specific for 1.2.3, MPLAYER_CMD related:
mplayer --msglevel all=-1
Unknown option on the command line: --msglevel
Error parsing option on the command line: --msglevel
MPlayer SVN-r29362-4.5.0 (C) 2000-2009 MPlayer TeamAnd this one?MPLAYER_CMD="$MPLAYER_GENERIC_CMD --msglevel all=-1 quiet -idle -input file=$PLAYD_PIPE"stderr being redirected to null device you'll not find out why mplayer doesn't start

graudeejs
June 15th, 2009, 22:14
I will. When i start mplayer, I get it's pid.
I save it in lock file.
Next time, I want to do something, i read lock file and get mplayers pid.

Then I run `pgrep mplayer` and get pids of all running mplayers.
If one pid match pid stored in lock file, that it's our mplayer, and it's running.
If not, we should playd restart


(well, That's how i planned it)


P.S.
I'm starting to redesign command line arguments. I want to be able to select multiple files/dirs at time

blah
June 15th, 2009, 23:03
I will. When i start mplayer, I get it's pid.... and this PID immediately gets free'd - incorrect option. But it does appear in process list for some time and passes test with pgrep.$ playd /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg
+ PLAYD_VERSION=1.2.4
+ PLAYD_HOME=/home/luser/.mplayer
+ PLAYD_PIPE=/home/luser/.mplayer/playd.fifo
+ PLAYD_PLAYLIST=/home/luser/.mplayer/playd_playlist.txt
+ PLAYD_LOCK=/home/luser/.mplayer/playd.lock
+ MPLAYER_GENERIC_CMD=mplayer
+ MPLAYER_CMD=mplayer --msglevel all=-1 quiet -idle -input file=/home/luser/.mplayer/playd.fifo
+ MPLAYER_SND_ONLY_CMD=mplayer --msglevel all=-1 -vo null -quiet -idle -input file=/home/luser/.mplayer/playd.fifo
+ which mplayer
+ [ ! /home/luser/local/bin/mplayer ]
+ [ ! /home/luser ]
+ [ ! -d /home/luser/.mplayer ]
+ [ ! -p /home/luser/.mplayer/playd.fifo ]
+ mkfifo /home/luser/.mplayer/playd.fifo
+ [ /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg ]
+ [ -f /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg -o -d /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg ]
+ playd_start 0 silent
+ playd_check
+ [ -f /home/luser/.mplayer/playd.lock ]
+ return 0
+ [ 0 -eq 0 ]
+ cd /
+ [ 0 = novid ]
+ exec mplayer --msglevel all=-1 quiet -idle -input file=/home/luser/.mplayer/playd.fifo
+ echo 28915
+ playd_play /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg
+ rm -f /home/luser/.mplayer/playd_playlist.txt.tmp
+ playd_start 0 silent
+ playd_check
+ [ -f /home/luser/.mplayer/playd.lock ]
+ cat /home/luser/.mplayer/playd.lock
+ pidStored=28915
+ pgrep mplayer
+ [ 28915 = 28915 ]
+ return 28915
+ [ 28915 -eq 0 ]
+ [ silent != silent ]
+ [ -d /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg ]
+ [ -f /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg ]
+ playd_put loadfile '/d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg'
+ playd_check
+ [ -f /home/luser/.mplayer/playd.lock ]
+ cat /home/luser/.mplayer/playd.lock
+ pidStored=28915
+ pgrep mplayer
+ [ 28915 = 28915 ]
+ return 28915
+ [ 28915 -gt 0 ]
+ echo loadfile '/d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg'
load: 0.10 cmd: sh 28912 [fifoow] 1.30r 0.00u 0.00s 0% 1836k
load: 0.10 cmd: sh 28912 [fifoow] 1.70r 0.00u 0.00s 0% 1836k
^C/usr/local/bin/playd: cannot create /home/luser/.mplayer/playd.fifo: Interrupted system call
+ return 0
+ [ = 1 ]
+ echo Now playing file: '/d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg'
Now playing file: '/d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg'
+ rm -f /home/luser/.mplayer/playd_playlist.txt
+ echo /d/muz/ly/openbsd.4.4.trial_of_the_bsd_knights.ogg
+ exit 0Simplified version$ mplayer >&- 2>&- --msglevel all=-1 & ps lwwp $!
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1001 29236 29235 0 44 0 40376 4268 zio->i D 5 0:00.00 mplayer --msglevel all=-1
$ ps lp $!
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
[1] Done (1) mplayer --msglevel all=-1 >&- 2>&-

graudeejs
June 16th, 2009, 19:59
--msglevel was unsupported option (some kind of mistake, anyway, i removed it, since everything goes to /dev/null)

I think I fixed it

I rewrote pretty much of playd :D
v1.3.0 is out, for you to grab.

What's new:
* man page
* any number of arguments in command line
* cmdl syntax changed a bit, you may need to reconfigure you application settings (if you have integrated playd in window manager, like I did)
* code cleanup
* command aliases
* --file command
* probably something more, but I don't remember
* new bugs ???

Discovered bug, possible mplayers (check manpage bugs section)

p.s.
Your testing greatly appreciated


p.s.s.
now i go study for exam :D

graudeejs
June 18th, 2009, 12:01
uploaded playd v1.3.1

I've added a lot of new commands. Especially related to video (few more to be added in v1.3.2)

blah
June 18th, 2009, 18:37
Don't you have a repo (or a ,v-file for RCS/CVS)? It would be easier to find when each line was added and bug introduced. Especially when you remove URL's for previous versions from the first post.

graudeejs
June 18th, 2009, 18:40
I don't have....
Can you suggest any?

blah
June 18th, 2009, 18:50
rcsintro and put `,v' files in tarball. Though RCS is not so good for many files, e.g. if you decide to split playd into several files in future.

graudeejs
June 22nd, 2009, 19:17
rcsintro and put `,v' files in tarball. Though RCS is not so good for many files, e.g. if you decide to split playd into several files in future.

I didn't like it....
(I will search for something)

graudeejs
June 23rd, 2009, 14:52
http://code.google.com/p/playd-sh/

to chechout code
hg clone https://playd-sh.googlecode.com/hg/ playd-sh
you'll need to install devel/mercurial


EDIT:
Switched to Google Code

graudeejs
June 29th, 2009, 22:31
I have finally move forward with playd.pl at rapid speed
I think in weak or two I could release it

graudeejs
July 3rd, 2009, 18:57
Ok, here's my first release of playd v2
it's about the same as current version of playd v1, only difference is that it's written in perl, and seams to create playlists faster (up to 4 times)

http://code.google.com/p/playd/downloads/list
to run this version you need to install

devel/perl5.8 or devel/perl5.10
I have only tested on perl5.8

devel/p5-File-Type
multimedia/mplayer

EDIT:
also i have new blog where you can fallow playd....
http://killasmurf86.blogspot.com/
http://code.google.com/p/playd/
http://twitter.com/killasmurf86

EDIT:
UPDATE links (noticed someone digging here):
http://aldis.git.bsdroot.lv/playd.sh/
http://aldis.git.bsdroot.lv/playd.pl/ (deprecated)

Wiki
http://wiki.bsdroot.lv/playd

eye
November 18th, 2010, 07:43
Hmm, playd-1.9.5 looks nice but...

About every command on my system respects $PAGER from environment, playd being the only exception. I don't like how it exits at the end of text by default, makes scrolling playlist from the end more annoying.
playd doesn't show current position in playlist, guess I'm spoiled by `xmms2 list'. At least it'd be nice if playd cmd get_file_name worked like `xmms2 current', i.e. showed current track.
typo: `sarution' vs. `saturation' in the manpage and `help' output
some places use `...`, some $(...); is such inconsistency intended?

UNIXgod
November 18th, 2010, 08:44
Play a directory backwards:

ls -1 -r * |mplayer -vo xv -fs -playlist -

Might even work this way
mplayer -vo xv -fs -playlist `ls -r -1 *`

graudeejs
November 18th, 2010, 09:31
Hmm, playd-1.9.5 looks nice but...
About every command on my system respects $PAGER from environment, playd being the only exception. I don't like how it exits at the end of text by default, makes scrolling playlist from the end more annoying.

actually I didn't thought about $PAGER, thanks I will fix it


playd doesn't show current position in playlist, guess I'm spoiled by `xmms2 list'. At least it'd be nice if playd cmd get_file_name worked like `xmms2 current', i.e. showed current track.

By current design it is not possible... I don't know any way to get feedback from mplayer after I start it as daemon and redirect outputs to /dev/null. I control mplayer via pipe


typo: `sarution' vs. `saturation' in the manpage and `help' output

Will fix it


some places use `...`, some $(...); is such inconsistency intended?

There are actually some small differences between `...` and $(...)
Also playd started as very simple script that was generating fvwm menus, and it was my sh learning project... It was been modified gazillion times....

Play a directory backwards:

ls -1 -r * |mplayer -vo xv -fs -playlist -

Might even work this way
mplayer -vo xv -fs -playlist `ls -r -1 *`

Ye, but playd generates playlist, and then loads it to mplayer. You can randomize playlist and load it to mplayer (which playd does, with rnd command), but you can't go back one song, because you don't know where you are in playlist :)
That's quite a problem....


I have to say, that I have an Idea, that might give playd opportunity to "know position in playlist" and play previous song, but It requires a Huge rethinking and rewriting....
Right now I don't have time for this.....

Meanwhile I use play already for like 1-2 years (maube 3, don't remember)

P.S.
Thanks for feedback

eye
November 19th, 2010, 02:42
one more wish for your TODO: make playd remember position in playlist across daemon restarts (or reboots).
actually I didn't thought about $PAGER, thanks I will fix itports/152361 is not going to work correctly where $PAGER is not defined, just like $EDITOR, $LANG, $TZ, $TMPDIR, etc. are common to be left undefined.

graudeejs
November 19th, 2010, 09:08
one more wish for your TODO: make playd remember position in playlist across daemon restarts (or reboots).
I told you I can't..... I don't know at any time what mplayer is playing

ports/152361 is not going to work correctly where $PAGER is not defined, just like $EDITOR, $LANG, $TZ, $TMPDIR, etc. are common to be left undefined.

Ye, I was in rush.... (session is coming)
Will fix

eye
November 19th, 2010, 14:52
If you're moving configuration from ~/.config/playd to ~/.config/playd/playd a note in UPDATING may be required.

BTW, is the git repo just for show? It still lists 1.9.5 as the last while that PR contains 1.9.9.

graudeejs
November 19th, 2010, 15:57
I now use http://hg.bsdroot.lv/pub/aldis/playd.sh

graudeejs
November 19th, 2010, 15:58
If you're moving configuration from ~/.config/playd to ~/.config/playd/playd a note in UPDATING may be required.

BTW, is the git repo just for show? It still lists 1.9.5 as the last while that PR contains 1.9.9.

There are pretty much no configuration...
Crap.... now that is a bug :)

Beastie
November 19th, 2010, 17:05
I told you I can't..... I don't know at any time what mplayer is playing
Anything preventing the use of the get_file_name command? Or am I misunderstanding something?

graudeejs
November 19th, 2010, 17:18
Anything preventing the use of the get_file_name command? Or am I misunderstanding something?

Yup....
mplayer is very verbose... no matter how much you want to shut it up (at least as much as I have tried)
Since I want mplayer to run in background (because I often control it from fvwm, and I don't want HUGE log file) I redirect stdout & stderr to /dev/null. I don't have way to read output of mplayer.

The problem is that playd is written to execute commands and exit, while leaving mplayer in background.
Now imagine you have mplayer dameon and you tell playd to get file name, how would you read it's output? Even if mplayer output wasn't redirected, playd can't read mplayers output... unless you redirect that output to some pipe or file, this is a problem again, because, mplayer is writing a lot to output, and after about hour of playing, you have pretty big piece of text in pipe or file. This is not good.


If you have anyideas, how playd could be started and read mplayer output shoot....

One way to solve this could be to rewrite playd so that, mplayer is started as command command of sh (without & at the end.) and then keep playd script as daemon. This way I could know when mplayer stops playing track and thus know where in playlist we are....

But this requires significant rewrite.... I don't have time for this right now.
And I'm not sure how well it would work as well :)

Beastie
November 19th, 2010, 17:32
Something like this (http://forums.freebsd.org/showthread.php?t=4857).

graudeejs
November 19th, 2010, 17:42
Something like this (http://forums.freebsd.org/showthread.php?t=4857).

Hmm, back then I didn't really understand it... Now I do.
Thanks. I will think about it....

graudeejs
November 19th, 2010, 20:18
OK, I wrote functions to get info from mplayer (currently not pushed to repository)
The problem is that it's very easy to kill mplayer (I think it's mplayers bug)
I will investigate deeper, when I have more time... I will probably push changes in few hours

UNIXgod
November 19th, 2010, 20:46
I have to say, that I have an Idea, that might give playd opportunity to "know position in playlist" and play previous song, but It requires a Huge rethinking and rewriting....
Right now I don't have time for this.....

Meanwhile I use play already for like 1-2 years (maube 3, don't remember)

P.S.
Thanks for feedback

make variables named prev and next

Set next to null (or whatever null is in that language) that way if it's the first pass it knows to generate a new next or use what is already been set of the user begins to use prev a couple of times.

graudeejs
November 19th, 2010, 21:54
OK, I wrote functions to get info from mplayer (currently not pushed to repository)
The problem is that it's very easy to kill mplayer (I think it's mplayers bug)
I will investigate deeper, when I have more time... I will probably push changes in few hours

OK, it's not mplayer bug, it's playd bug :)

eye
November 20th, 2010, 08:01
How to populate playlist without playing it? I'm trying to start daemon with shuffled playlist from ~/.profile.playd /path/to/music-dir
playd rnd
playd playlistThe thing is it starts to play the first file from that directory for a few seconds. Actually, there is a race in the above example that makes playd start two instances of mplayer.

Also, that note about hw.snd.vpc_autoreset in the man page can be removed. It's strictly mplayer's issue and the port's maintainer added a note (http://lists.freebsd.org/pipermail/freebsd-ports/2010-November/064524.html) (not committed yet)============================================== =====================
If seeking in streams causes the playback volume to be reset to
the previous setting (on 8.x or newer system with VPC enabled),
you and you dislike this behaviour, you have two options:
- Use mplayer's -softvol command line option
- Set the sysctl hw.snd.vpc_autoreset to 0
================================================== =================

graudeejs
November 20th, 2010, 09:10
How to populate playlist without playing it? I'm trying to start daemon with shuffled playlist from ~/.profile.playd /path/to/music-dir
playd rnd
playd playlistThe thing is it starts to play the first file from that directory for a few seconds. Actually, there is a race in the above example that makes playd start two instances of mplayer.

Current implementation makes it always play when you make new playlist
But I could add --noplay option

About race condition.... that's interesting... I noticed 2x mplayers, and thought that it was normal... now on slightly newer and powerful PC, I see only 1 mplayer. maybe adding sleep 1 after starting mplayer will prevent that... (can you test with your local playd?)

graudeejs
November 20th, 2010, 10:02
added --noplay switch....
YOu can clone my repo with:
hg clone http://hg.bsdroot.lv/pub/aldis/playd.sh/

need devel/mercurial

eye
November 20th, 2010, 10:04
Current implementation makes it always play when you make new playlist
But I could add --noplay optionPlease, do. It also may mitigate the bug.About race condition.... that's interesting... I noticed 2x mplayers, and thought that it was normal... now on slightly newer and powerful PC, I see only 1 mplayer. maybe adding sleep 1 after starting mplayer will prevent that... (can you test with your local playd?)No, I'm not talking about caching instance that mplayer spawns to buffer IO, -nocache negates it. What I see/listen is two tracks playing at the same time. The interesting thing is it does happen only in subshell$ (playd /path/to/music-dir; playd rnd; playd playlist)
$ procstat -f $(pgrep mplayer)
PID COMM FD T V FLAGS REF OFFSET PRO NAME
99629 mplayer cwd v d -------- - - - /
99629 mplayer root v d -------- - - - /
99629 mplayer 0 v c r------- 1 0 - /dev/null
99629 mplayer 1 v c -w------ 1 0 - /dev/null
99629 mplayer 2 v c -w------ 1 0 - /dev/null
99629 mplayer 3 f - rw------ 1 0 - /home/luser/.config/playd/fifo
99629 mplayer 4 v r r------- 1 360448 - /path/to/music-dir/bar.mp3
99629 mplayer 5 v c -w------ 1 1491968 - /dev/dsp1.2
99207 mplayer cwd v d -------- - - - /
99207 mplayer root v d -------- - - - /
99207 mplayer 0 v c r------- 1 0 - /dev/null
99207 mplayer 1 v c -w------ 1 0 - /dev/null
99207 mplayer 2 v c -w------ 1 0 - /dev/null
99207 mplayer 3 f - rw------ 1 0 - -
99207 mplayer 4 v r r------- 1 393216 - /path/to/music-dir/foo.mp3
99207 mplayer 5 v c -w------ 1 1560576 - /dev/dsp1.1
$ { playd /path/to/music-dir; playd rnd; playd playlist; }
$ procstat -f $(pgrep mplayer)
PID COMM FD T V FLAGS REF OFFSET PRO NAME
1312 mplayer cwd v d -------- - - - /
1312 mplayer root v d -------- - - - /
1312 mplayer 0 v c r------- 1 0 - /dev/null
1312 mplayer 1 v c -w------ 1 0 - /dev/null
1312 mplayer 2 v c -w------ 1 0 - /dev/null
1312 mplayer 3 f - rw------ 1 0 - /home/luser/.config/playd/fifo
1312 mplayer 4 v r r------- 1 229376 - /path/to/music-dir/bar.mp3
1312 mplayer 5 v c -w------ 1 785408 - /dev/dsp1.1It's probably not a race as sleep between playd invocations doesn't help.

Also, you can close all those open file-descriptors for /dev/null by using <&- instead of </dev/null
>&- instead of >/dev/null
2>&- instead of 2>/dev/null$ procstat -f $(pgrep mplayer)
PID COMM FD T V FLAGS REF OFFSET PRO NAME
2914 mplayer cwd v d -------- - - - /
2914 mplayer root v d -------- - - - /
2914 mplayer 0 f - rw------ 1 0 - /home/luser/.config/playd/fifo
2914 mplayer 1 v r r------- 1 491520 - /path/to/music-dir/bar.mp3
2914 mplayer 2 v c -w------ 1 2132992 - /dev/dsp1.2

BTW, does below piece work as expected? The quoting doesn't seem right.* )
playd_warn "Sorry `echo "${1##*.}" | tr [A-Z] [a-z]` is unsupported playlist type. Ignoring"
return 1
;;It should probably be eitherplayd_warn "Sorry `echo \\"${1##*.}\\" | tr [A-Z] [a-z]` is unsupported playlist type. Ignoring"orplayd_warn "Sorry $(echo \"${1##*.}\" | tr [A-Z] [a-z]) is unsupported playlist type. Ignoring"Notice how escaping double-quotes inside double-quotes differs between `...` and $(...) - a good reason to avoid using backticks.

graudeejs
November 20th, 2010, 10:07
How about jabber talk.... we're starting to spam FreeBSD forum with non-freebsd stuff :)
I'll pm you details

eye
November 20th, 2010, 10:33
Also, you can close all those open file-descriptors for /dev/null by using <&- instead of </dev/null
>&- instead of >/dev/null
2>&- instead of 2>/dev/null$ procstat -f $(pgrep mplayer)
PID COMM FD T V FLAGS REF OFFSET PRO NAME
2914 mplayer cwd v d -------- - - - /
2914 mplayer root v d -------- - - - /
2914 mplayer 0 f - rw------ 1 0 - /home/luser/.config/playd/fifo
2914 mplayer 1 v r r------- 1 491520 - /path/to/music-dir/bar.mp3
2914 mplayer 2 v c -w------ 1 2132992 - /dev/dsp1.2Doh, it works a bit differently on mplayer from Uoti's repo (http://repo.or.cz/w/mplayer.git) (in git) and mainline (in svn), e.g. closing input doesn't work on mainlinediff --git a/bin/playd.sh b/bin/playd.sh
--- a/bin/playd.sh
+++ b/bin/playd.sh
@@ -165,8 +165,9 @@ playd_start() { # {{{1
|| local mplayer_run_cmd="$MPLAYER_SND_ONLY_CMD"
sleep 1

- #{ ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2> /dev/null & } \
- { ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2> /dev/null & } \
+ #{ ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2>&- & } \
+ # closing input fd works only on mplayer-uau
+ { ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2>&- & } \
&& echo "$$" > "$PLAYD_LOCK" \
|| playd_die 'Failed to start mplayer'
cd - > /dev/null 2> /dev/null
How about jabber talk.... we're starting to spam FreeBSD forum with non-freebsd stuff :)
I'll pm you detailsNo thanks, non-public discussions suck and cannot be found on google. This forum is about userland programming, what's so wrong about dev talk? If it turns out to be too voluminous you can create a mailing list to reduce noise ratio here.

eye
November 20th, 2010, 10:59
it works a bit differently on mplayer from Uoti's repo (http://repo.or.cz/w/mplayer.git) (in git) and mainline (in svn), e.g. closing input doesn't work on mainlineOops, with -noconsolecontrols both work$ procstat -f $(pgrep mplayer)
PID COMM FD T V FLAGS REF OFFSET PRO NAME
33484 mplayer cwd v d -------- - - - /
33484 mplayer root v d -------- - - - /
33484 mplayer 0 f - rw------ 1 0 - /home/luser/.config/playd/playd.fifo
33484 mplayer 1 f - -w------ 1 0 - /home/luser/.config/playd/mplayer.fifo
33484 mplayer 2 v r r------- 1 71680 - /path/to/music-dir/foo.mp3
33484 mplayer 3 v c -w------ 1 290816 - /dev/dsp1.2diff --git a/bin/playd.sh b/bin/playd.sh
--- a/bin/playd.sh
+++ b/bin/playd.sh
@@ -70,7 +70,7 @@ readonly CAT_LOCK="$PLAYD_HOME/cat.lock"

# to customise mplayers command line set PLAYD_MPLAYER_USER_OPTIONS environment variable
#readonly MPLAYER_CMD_GENERIC="$PLAYD_MPLAYER_USER_OPTIONS -really-quiet -idle -input file=$PLAYD_PIPE"
-readonly MPLAYER_CMD_GENERIC="$PLAYD_MPLAYER_USER_OPTIONS -quiet -idle -input file=$PLAYD_PIPE"
+readonly MPLAYER_CMD_GENERIC="$PLAYD_MPLAYER_USER_OPTIONS -noconsolecontrols -quiet -idle -input file=$PLAYD_PIPE"
readonly MPLAYER_CMD="mplayer $MPLAYER_CMD_GENERIC"
readonly MPLAYER_SND_ONLY_CMD="mplayer -vo null $MPLAYER_CMD_GENERIC"
NOVID=0
@@ -164,8 +164,8 @@ playd_start() { # {{{1
&& local mplayer_run_cmd="$MPLAYER_CMD" \
|| local mplayer_run_cmd="$MPLAYER_SND_ONLY_CMD"

- #{ ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2> /dev/null & } \
- { ${mplayer_run_cmd} > "$MPLAYER_PIPE" 2> /dev/null & } \
+ #{ ${mplayer_run_cmd} <&- > "$MPLAYER_PIPE" 2>&- & } \
+ { ${mplayer_run_cmd} <&- > "$MPLAYER_PIPE" 2>&- & } \
&& echo "$$" > "$PLAYD_LOCK" \
|| playd_die 'Failed to start mplayer'
cd - > /dev/null 2> /dev/null

graudeejs
November 20th, 2010, 11:02
BTW, does below piece work as expected? The quoting doesn't seem right.* )
playd_warn "Sorry `echo "${1##*.}" | tr [A-Z] [a-z]` is unsupported playlist type. Ignoring"
return 1
;;It should probably be eitherplayd_warn "Sorry `echo \\"${1##*.}\\" | tr [A-Z] [a-z]` is unsupported playlist type. Ignoring"orplayd_warn "Sorry $(echo \"${1##*.}\" | tr [A-Z] [a-z]) is unsupported playlist type. Ignoring"Notice how escaping double-quotes inside double-quotes differs between `...` and $(...) - a good reason to avoid using backticks.


It's fine.. Check this out:
echo "test `echo "x"`" in sh or mksh

graudeejs
November 20th, 2010, 12:13
Just pushed rev f17d1537ea9f
Now playd shows position in playlist.
Actually it guesses position in playlist by matching playlist entries and filename (full path) that mplayer is playd.
Thanks for your post with procstat -f $(pgrep mplayer) otherwise I would never thought of it :D

Now It should be possible to implement previous... (which should play previous song against first matched playlist entry of current song [Did what I said make sense, to you?])

:D
Woooooooot

eye
November 20th, 2010, 12:31
Hmm, new get functions are a bit buggy$ cat /tmp/m.blah
ANS_FILENAME='my track.mp3'
and here is how playd works$ playd get filename | cat
ANS_filename=my track.mp3
Terminated(no quoting, mangled case in ANS_FILENAME, "Terminated" in stdout)

I was thinking about[code]eval $(playd get filename)
echo Current track is $ANS_FILENAME[/cmd]in zsh's precmd hook or ~/.screenrc.

graudeejs
November 20th, 2010, 12:55
Hmm, new get functions are a bit buggy$ cat /tmp/m.blah
ANS_FILENAME='my track.mp3'
and here is how playd works$ playd get filename | cat
ANS_filename=my track.mp3
Terminated(no quoting, mangled case in ANS_FILENAME, "Terminated" in stdout)

I was thinking about[code]eval $(playd get filename)
echo Current track is $ANS_FILENAME[/cmd]in zsh's precmd hook or ~/.screenrc.

Just fixed (and pushed) by adding 2> /dev/null to cat :D

I preffer 2> /dev/null over 2>-, because I think it's easier to understand :D (more people are familiar with this)

DID you subscribe to rss or atom feeds of commits?

eye
November 20th, 2010, 14:30
Just fixed (and pushed)It has more assumption about mplayer's config -nomsgmodule and -nomsgcolor.DID you subscribe to rss or atom feeds of commits?Nah, only to crontab$
You have new mail.
$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/mail/luser": 1 message 1 new
>N 1 luser@earth.local Sat Nov 20 16:05 23/854 "Cron <luser@earth> slurp hg /a/playd.sh"
&
Message 1:
From luser@earth.local Sat Nov 20 16:05:07 2010
Date: Sat, 20 Nov 2010 13:05:02 +0000 (UTC)
From: luser@earth.local (Cron Daemon)
To: luser@earth.local
Subject: Cron <luser@earth> slurp hg /a/playd.sh
X-Cron-Env: <PATH=/home/luser/.bin:/bin:/usr/bin:/usr/local/bin>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/luser>
X-Cron-Env: <LOGNAME=luser>
X-Cron-Env: <USER=luser>

53:ca5190b1e0ba
54:f17d1537ea9f
55:2482978da388
56:ac1044126e82
57:565e24ce0642
58:13105a41801e
59:e46067f6f348
60:b8fdeaf36f35

&

graudeejs
November 20th, 2010, 18:27
Implemented long waited --previous :D
I'm so dam happy :D

eye
November 20th, 2010, 20:20
Don't you need to escape + (plus symbol), ?, etc. from re_format? Otherwise they'd break prev command.

UNIXgod
November 20th, 2010, 20:21
The links on the first post are broken. I would be interested in seeing your shell script. Is there another link?

graudeejs
November 20th, 2010, 20:25
Project repo (moved to Mercurial. Git is overcomplicated):
http://hg.bsdroot.lv/pub/aldis/playd.sh/

graudeejs
November 20th, 2010, 20:28
Don't you need to escape + (plus symbol), ?, etc. from re_format? Otherwise they'd break prev command.
Which lines are you referring to?

eye
November 20th, 2010, 20:51
playd_current_file_escaped(), try with filenames containing those characters.

graudeejs
November 20th, 2010, 20:57
Yes, I should escape, them...

eye
November 20th, 2010, 21:40
You haven't looked at that manpage when committing 74:8c15e48779dd. There are more - $, ^. Perhaps, you should consider filtering output by fgrep -x before doing awk rather than haphazardly escaping RE.

graudeejs
November 20th, 2010, 21:52
I'm lazy, like everyone else :)
I thought I had $ ^ espaced already... :D

No, playd_current_file_escaped is used to inject filename in awk script

eye
November 21st, 2010, 07:51
I'm curious why do you need to know position in order to switch to previous track in playlist? What's wrong with playd cmd 'pt_step -1'?

graudeejs
November 21st, 2010, 10:36
Wow.... How did I miss that one... :)
Thank you so much

eye
November 21st, 2010, 14:00
one more wish for your TODO: make playd remember position in playlist across daemon restarts (or reboots)I told you I can't..... I don't know at any time what mplayer is playingIt should be possible now. One way is to keep log of played files$ mplayer -playlist ~/foo.plst -nomsgmodule -msglevel all=-1 -msglevel identify=4 | fgrep -i file
ID_FILENAME=/path/to/music-dir/foo.mp3
ID_FILENAME=/path/to/music-dir/bar.mp3
ID_FILENAME=/path/to/music-dir/foo.mp3And when mplayer is not alive do load playlist and jump (pt_step) to the last file in the log.

This feature is useful for lazy people putting their entire music library into playlist and shuffling it. Keeping current position across reboots would make distribution of played tracks more even because it ensures that every track is played at least once. Currently some tracks play more often than others either by repeating playlist from the start or increasing the chance to hit already played files with random command.

graudeejs
November 21st, 2010, 14:41
That will cause problems if person suddenly wants to watch video, or something, however I have idea.... (a little complex to explaing and I'm short on time)

What is important now:
* Need to figure out how to fix playd on linux again :D
* Linux doesn't have procstat

probably need to look at /proc

Anyway, today I don't have time. I need to prepare myself for tomorrow. Tomorrow I will teach auditory of about 60 students (class mates) how to code Assembler in Un*x environment.

eye
November 21st, 2010, 17:38
That will cause problems if person suddenly wants to watch video, or something, however I have idea.... (a little complex to explaing and I'm short on time)Can you elaborate? No need to care about user that resets current playlist, he should use mplayer directly or with gui front-end rather than playd. Well, unless you plan to implement playlist sets and push video files in a separate playlist by default.What is important now:
* Need to figure out how to fix playd on linux again :D
* Linux doesn't have procstat

probably need to look at /procYep, figuring out files used by a process is system-dependent. That's why you should re-evaluate your approach with two-way communication in experimantal-mplayer-get branch. I think using fifo may be a bad idea, it's synchronous. The process sending to a named pipe is blocked until the data is read on another end. Regular files don't have this disadvantage. And -msglevel allows very precise control over mplayer output so filtering is rarely needed.

Also, does random command work on linux? jot may not be available there.

graudeejs
November 21st, 2010, 17:43
Yes, for example, on Ubuntu you need to install athena-jot

eye
November 22nd, 2010, 20:06
I don't think you need both -msglevel all=-1 and -really-quiet. Also you can easily test linux sed by installing textproc/gsed and defining wrapper at the start of the script.
alias sed=gsed # ex. 1
sed() { gsed "$@"; } # ex. 2It's same for dash/bash, just swap shebang.

Note, sed(1) on 7.x and 8.0 doesn't have -r for gnu compat, it's very recent thing (r206538 (http://svn.freebsd.org/viewvc/base?view=revision&revision=206538) was committed in Apr 2010). OTOH, gsed has -E for bsd compat for a bit longer time. Other BSDs seem to have both except for DragonFlyBSD which doesn't have -r.

graudeejs
November 22nd, 2010, 20:19
Patches welcomed :D

eye
November 24th, 2010, 12:28
I thought the change was obvious without diffs.diff --git a/bin/playd.sh b/bin/playd.sh
--- a/bin/playd.sh
+++ b/bin/playd.sh
@@ -73,7 +73,7 @@ FORMAT_SPACES=${FORMAT_SPACES:-'yes'}


# to customise mplayers command line set PLAYD_MPLAYER_USER_OPTIONS environment variable
-readonly MPLAYER_CMD_GENERIC="$PLAYD_MPLAYER_USER_OPTIONS -really-quiet -msglevel all=-1 -nomsgmodule -idle -input file=$PLAYD_PIPE"
+readonly MPLAYER_CMD_GENERIC="$PLAYD_MPLAYER_USER_OPTIONS -msglevel all=-1 -nomsgmodule -idle -input file=$PLAYD_PIPE"
readonly MPLAYER_CMD="mplayer $MPLAYER_CMD_GENERIC"
readonly MPLAYER_SND_ONLY_CMD="mplayer -vo null $MPLAYER_CMD_GENERIC"
NOVID=0
@@ -375,21 +375,8 @@ playd_current_file_escaped() { # {{{1
playd_cat_playlist() { # {{{1
if [ -f "$PLAYD_PLAYLIST" ]; then
if [ $FORMAT_SHORTNAMES = 'yes' -o $FORMAT_SHORTNAMES = 'YES' ]; then
- if [ "$OS" = 'FreeBSD' ]; then
playd_longcat_playlist \
- | sed -r \
- -e 's#/.*/##' \
- -e 's#_# #g' \
- -e 's#^[ ]*##' \
- -e 's# ?- ?[0-9]{1,2} ?- ?# - #' \
- -e 's#-[0-9]{2}\.# - #' \
- -E -e "s#\.($PLAYD_FILE_FORMATS)\$##" \
- -E -e 's#\| (([0-9][ -]?)?[0-9]{1,2}( - |\. |-|\.| ))?#| #' \
- -E -e 's#\|\* (([0-9][ -]?)?[0-9]{1,2}( - |\. |-|\.| ))?#|* #'
- else
- # assuming Linux
- playd_longcat_playlist \
- | sed -r \
+ | sed $(case $OS in (*BSD) printf -- -E;; (*) printf -- -r;; esac) \
-e 's#/.*/##' \
-e 's#_# #g' \
-e 's#^[ ]*##' \
@@ -398,7 +385,6 @@ playd_cat_playlist() { # {{{1
-e "s#\.($PLAYD_FILE_FORMATS)\$##" \
-e 's#\| (([0-9][ -]?)?[0-9]{1,2}( - |\. |-|\.| ))?#| #' \
-e 's#\|\* (([0-9][ -]?)?[0-9]{1,2}( - |\. |-|\.| ))?#|* #'
- fi
else
if [ $FORMAT_SPACES = 'yes' -o $FORMAT_SPACES = 'YES' ]; then
playd_longcat_playlist | sed -e 's#/.*/##' -e 's#_# #g'

graudeejs
November 24th, 2010, 12:47
I see you removed 2 lines, that I was just about to tell you about :)

eye
November 24th, 2010, 13:04
It was buggy butprocstat -f $pid | sed -n '/ 4 v r r-------/s#.* /#/#p'should work on any POSIX compliant sed (including gsed). In simple cases sed, awk, grep are interchangeable.

graudeejs
November 27th, 2010, 13:59
Released playd v1.16.0
In v1.16.0 I added support to save/restore playlist position :D

I wanted to note, that you can override some default playd variables in playd.conf (in playd home)

for example by default playd use $PAGER environment variable as pager.
IF you want to use other pager for playd exclusively, you can set

PAGER=more

in playd.conf
This is not documented in manual (yet), but you can check source, to see what you can override

graudeejs
December 3rd, 2010, 11:34
Lately my mind is bugged by idea of storing playlists and such things in sqlite database :D
Need more thinking about this... but it would be very interesting challenge... That could give many benefits (I think)

0