1.1 --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 00:10:15 2007 +0100
1.2 +++ b/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 17:08:11 2007 +0100
1.3 @@ -9,7 +9,7 @@
1.4 from select import *
1.5 from subprocess import *
1.6
1.7 -class Media:
1.8 +class Media(object):
1.9
1.10 def __init__(self, config):
1.11
1.12 @@ -33,22 +33,24 @@
1.13
1.14 for opt in options:
1.15
1.16 - if (opt == "file" or opt == "dvd"):
1.17 - if (self.acodec == "mp3lame"):
1.18 + if opt is "file" or opt is "dvd":
1.19 +
1.20 + if self.acodec is "mp3lame":
1.21 audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate
1.22 else:
1.23 audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\
1.24 self.acodec, self.abitrate)
1.25
1.26 - if (opt == "file"):
1.27 +
1.28 + if opt is "file":
1.29 self.kind = "file"
1.30 - self.args += " %s -mf fps=%s -of %s -noodml %s"\
1.31 + self.args += " %s -mf fps=%s -of %s %s"\
1.32 " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\
1.33 " -o %s 1> /dev/null 2> /dev/null" % (
1.34 self.filename, self.fps, self.mux, audio, self.vcodec,
1.35 self.vbitrate, self.width, self.height, self.fifo)
1.36
1.37 - elif (opt == "dvd"):
1.38 + elif opt is "dvd":
1.39 self.kind = "dvd"
1.40 self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\
1.41 " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -o %s"\
1.42 @@ -56,19 +58,26 @@
1.43 self.filename, self.language, self.width, self.height, audio,
1.44 self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps)
1.45
1.46 - elif (opt == "local"):
1.47 + elif opt is "local":
1.48 self.mplayer = os.popen("which mplayer").read().strip()
1.49
1.50 - elif (opt.find("language=") >= 0):
1.51 + elif opt.find("language=") >= 0:
1.52 try:
1.53 self.language = opt.split("=")[1]
1.54 except:
1.55 lib.log("Bad language option")
1.56
1.57 + elif opt.find("format=") >= 0:
1.58 + try:
1.59 + self.mux += " -mpegopts format=%s" % opt.split("=")[1]
1.60 + except:
1.61 + lib.log("Bad format option")
1.62 +
1.63
1.64 def run_mplayer(self):
1.65 msg = "%s 1>/dev/null 2>/dev/null" % self.filename
1.66 - if (self.kind == "dvd"):
1.67 +
1.68 + if self.kind is "dvd":
1.69 msg = "dvd://" + msg
1.70
1.71 self.mplayer += " " + msg
1.72 @@ -94,15 +103,16 @@
1.73 self.kind = ""
1.74 self.set_args(options)
1.75
1.76 - if (self.kind == "file" and not os.path.exists(self.filename)):
1.77 + if self.kind is "file" and not os.path.exists(self.filename):
1.78 msg = "File requested does not exist. SETUP failed."
1.79 lib.log(msg)
1.80 return msg
1.81
1.82 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
1.83 + #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd
1.84 self.path = self.config.get("Mencoder", "path")
1.85
1.86 - if (self.socket != None):
1.87 + if self.socket is not None:
1.88 del(self.socket)
1.89
1.90 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
1.91 @@ -128,7 +138,7 @@
1.92
1.93 self.child_pid = os.fork()
1.94
1.95 - if (self.child_pid == 0):
1.96 + if self.child_pid is 0:
1.97 conn,addr= self.socket.accept()
1.98 lib.log("Sending Data to client: %s" % addr[0])
1.99
1.100 @@ -136,13 +146,13 @@
1.101 conn.settimeout(5)
1.102 retry = 0
1.103
1.104 - while( data != "" and retry < 5):
1.105 + while data is not "" and retry < 5:
1.106 try:
1.107 conn.send(data)
1.108 r, w, x = select([conn], [], [], 0)
1.109 if conn in r:
1.110 back = conn.recv(1024)
1.111 - if (back == "OK" and self.mplayer and not self.mplayer_pid):
1.112 + if back is "OK" and self.mplayer and not self.mplayer_pid:
1.113 self.run_mplayer()
1.114
1.115 except socket.error:
1.116 @@ -151,7 +161,7 @@
1.117
1.118 data = fifo.read(1024)
1.119
1.120 - if (retry < 5):
1.121 + if retry < 5:
1.122 lib.log("Finished sending Data to client: %s" % addr[0])
1.123 else:
1.124 lib.log("Client timed out")
1.125 @@ -166,10 +176,10 @@
1.126 except:
1.127 lib.log("Trying to stop before playing...")
1.128
1.129 - if (self.socket != None):
1.130 + if self.socket is not None:
1.131 lib.log("Closing socket")
1.132 self.socket.close()
1.133
1.134 lib.log("Trying to stop Mencoder process")
1.135 - if (self.child_pid != None):
1.136 + if self.child_pid is not None:
1.137 os.kill(self.child_pid, signal.SIGABRT)