summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2011-03-14 21:10:32 (GMT)
committerAdrian C. (anrxc) <anrxc@sysphere.org>2011-03-14 21:10:32 (GMT)
commited3405a3b4890ce01972d3b07754fe35b8291816 (patch)
tree23909d8be59ee9abf92d33bf636d7c480cb24fc7
parente01a74776c421b309da1f878f401da734482fa53 (diff)
downloadplay-ed3405a3b4890ce01972d3b07754fe35b8291816.tar.xz
play: better mplayer support by Tomi Pievilainen
-rw-r--r--README7
-rwxr-xr-xplay.py53
2 files changed, 36 insertions, 24 deletions
diff --git a/README b/README
index b0d29ec..f4d2d77 100644
--- a/README
+++ b/README
@@ -20,7 +20,7 @@ Miscellaneous:
from the id3-py project: http://id3-py.sourceforge.net/
A playlist can contain URLs, but the playlist itself will have
- to be local. For mpeg streaming, splay is recommended.
+ to be local. For mpeg streaming splay is recommended.
It is also possible to pipe a playlist to play, as stdin will
be reopened on startup unless it is attached to a tty.
@@ -33,3 +33,8 @@ Authors:
years for cplay's home, and code, to resurface it was finally
forked. This exceptional software, originally written by Ulf
Betlehem, should not be forgotten.
+
+ In March of 2011 a cplay branch was found on GitHub, published
+ by Tomi Pievilainen, with some interesting patches on top of
+ the original cplay. Very much like play includes. From this
+ code MPlayer support was added to play.
diff --git a/play.py b/play.py
index 06b3212..aa1c620 100755
--- a/play.py
+++ b/play.py
@@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# ------------------------------------------
from types import *
+import re
import os
import sys
import time
@@ -33,7 +34,7 @@ import getopt
import signal
import string
import select
-import re
+import subprocess
try: from ncurses import curses
except ImportError: import curses
@@ -608,16 +609,8 @@ class TagListWindow(ListWindow):
sys.stderr.write("\n")
argv = map(lambda x: x.pathname, self.get_tagged())
argv or self.current() and argv.append(self.current().pathname)
- argv = ["/bin/sh", "-c", s, "--"] + argv
- pid = os.fork()
- if pid == 0:
- try: os.execv(argv[0], argv)
- except: os._exit(1)
- try:
- try: pid, r = os.waitpid(pid, os.WNOHANG)
- except os.error: pass
- sys.stderr.write("\nshell returned %s, press return!\n" % r)
- except: pass
+ r = subprocess.call(" ".join([s] + argv), shell=True)
+ sys.stderr.write("\nshell returned %s, press return!\n" % r)
sys.stdin.readline()
app.win_root.update()
app.restore_default_status()
@@ -1181,14 +1174,16 @@ class Player:
self.argv = string.split(self.commandline)
self.argv[0] = which(self.argv[0])
for i in range(len(self.argv)):
- if self.argv[i] == "%s": self.argv[i] = entry.pathname
- if self.argv[i] == "%d": self.argv[i] = str(offset*self.fps)
+ if self.argv[i] == "{file}":
+ self.argv[i] = entry.pathname
+ if self.argv[i] == "{offset}":
+ self.argv[i] = str(offset*self.fps)
self.entry = entry
+ self.offset = offset
if offset == 0:
app.progress(0)
self.offset = 0
self.length = 0
- self.values = [0, 0]
self.time_setup = time.time()
return self.argv[0]
@@ -1255,14 +1250,13 @@ class Player:
self.offset = (offset < 0) and self.length+offset or offset
self.show_position()
- def set_position(self, offset, length, values):
+ def set_position(self, offset, length):
self.offset = offset
self.length = length
- self.values = values
self.show_position()
def show_position(self):
- app.counter(self.values)
+ app.counter((self.offset, self.length-self.offset))
app.progress(self.length and (float(self.offset) / self.length))
def update_status(self):
@@ -1284,7 +1278,7 @@ class FrameOffsetPlayer(Player):
if match:
m1, s1, m2, s2 = map(string.atoi, match.groups())
head, tail = m1*60+s1, m2*60+s2
- self.set_position(head, head+tail, [head, tail])
+ self.set_position(head, head+tail)
# ------------------------------------------
class FrameOffsetPlayerMpp(Player):
@@ -1296,7 +1290,7 @@ class FrameOffsetPlayerMpp(Player):
m1, s1, m2, s2 = map(string.atoi, match.groups())
head = m1*60+s1
tail = (m2*60+s2) - head
- self.set_position(head, head+tail , [head, tail])
+ self.set_position(head, head+tail)
# ------------------------------------------
class TimeOffsetPlayer(Player):
@@ -1308,25 +1302,35 @@ class TimeOffsetPlayer(Player):
h, m, s = map(string.atoi, match.groups())
tail = h*3600+m*60+s
head = max(self.length, tail) - tail
- self.set_position(head, head+tail, [head, tail])
+ self.set_position(head, head+tail)
# ------------------------------------------
class TimeOffsetPlayerMplayer(Player):
re_progress = re.compile("^A:.*?(\d+)\.\d \([^)]+\) of (\d+)\.\d")
+ def play(self):
+ if os.path.exists(CONTROL_FIFO + "-mplayer"):
+ os.unlink(CONTROL_FIFO + "-mplayer")
+ os.mkfifo(CONTROL_FIFO + "-mplayer", 0600)
+ Player.play(self)
+ fifo = open(CONTROL_FIFO + "-mplayer", 'w')
+ fifo.write("seek %d\n" % self.offset)
+ fifo.flush()
+ fifo.close()
+
def parse_buf(self):
match = self.re_progress.search(self.buf)
if match:
curS, totS = map(string.atoi, match.groups())
position, length = curS, totS
- self.set_position(position, length, [position, length])
+ self.set_position(position, length)
# ------------------------------------------
class NoOffsetPlayer(Player):
def parse_buf(self):
head = self.offset+1
- self.set_position(head, 0, [head, head])
+ self.set_position(head, head*2)
def seek(self, *dummy):
return 1
@@ -1694,7 +1698,10 @@ PLAYERS = [
NoOffsetPlayer("xmp -q %s", "\.(mod|xm|fm|s3m|med|col|669|it|mtm|stm)$"),
NoOffsetPlayer("play %s", "\.(aiff|au|cdr|mp3|ogg|wav)$"),
NoOffsetPlayer("speexdec %s", "\.spx$"),
- TimeOffsetPlayerMplayer("mplayer %s", "^http://|\.(mp[123]|m4a|ogg|flac|spx|mp[cp+]|mod|xm|fm|s3m|med|col|669|it|mtm|stm|aiff|au|cdr|wav|wma)$")
+ TimeOffsetPlayerMplayer("mplayer -input file=%s -vc null -vo null {file}" %
+ (CONTROL_FIFO + "-mplayer"),
+ "^http://|\.(mp[123]|ogg|oga|flac|spx|mp[cp+]|mod|xm|fm|s3m|" +
+ "med|col|669|it|mtm|stm|aiff|au|cdr|wav)$"),
]
MACRO = {}