# HG changeset patch # User morphbr # Date 1179249919 -3600 # Node ID 3433df0d6ae3ed1766e93672e4821e8a7fa60c18 # Parent c98ddd4a9513a9c5882e3014f6a748e2d3155628 [svn r659] * GMyth-Stream - created mencoder_lib to cleanup code - fixed progress bar function - get status by task diff -r c98ddd4a9513 -r 3433df0d6ae3 gmyth-stream/server/0.2/lib/server.py --- a/gmyth-stream/server/0.2/lib/server.py Tue May 15 15:45:34 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/server.py Tue May 15 18:25:19 2007 +0100 @@ -63,12 +63,9 @@ def __str__(self): - return '%s("%s", mux="%s", params=%s, addr=%s)' % \ + return '%s( params=%s )' % \ (self.__class__.__name__, - self.params_first("uri", "None"), - self.params_first("mux", "mpg"), - self.params, - repr(self)) + self.params) # __str__() # Transcoder @@ -244,16 +241,32 @@ running = "

No running transcoder.

\n" stopall = "" stopone = "" + + elif self.query.get("ip") and self.query.get("file"): + for transcoder, request in tl: + filename = "%s" % self.query.get("file")[0] + tfilename = "%s" % transcoder.params_first("uri") + + if tfilename.find(filename) >= 0 and \ + request.client_address[0] == self.query.get("ip")[0]: + self.wfile.write("Status: %s %%" % transcoder.status) + return + else: running = "

Running transcoders:

\n" - stopall = self._create_html_item("[STOP ALL]" % + stopall = self._create_html_item("" + "[STOP ALL]" % self.menu["Stop"]) for transcoder, request in tl: - stopone = self._create_html_item("%s: %s:%s" - "[STOP] - Status: %s%%" % ( - transcoder, request.client_address[0], request.client_address[1], - self.menu["Stop"], request.client_address[0], request.client_address[1], + stopone = self._create_html_item("%s: %s:%s" + "[STOP] - Status: %s%%"\ + % ( + transcoder, request.client_address[0], + request.client_address[1], + self.menu["Stop"], request.client_address[0], + request.client_address[1], transcoder.status) ) self.wfile.write(utils.getHTML("status", diff -r c98ddd4a9513 -r 3433df0d6ae3 gmyth-stream/server/0.2/lib/utils.py --- a/gmyth-stream/server/0.2/lib/utils.py Tue May 15 15:45:34 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/utils.py Tue May 15 18:25:19 2007 +0100 @@ -170,5 +170,5 @@ else: sys.stdout.write("[%3i%%]\r" % (percent)) sys.stdout.flush() - + return percent # progress_bar by osantana diff -r c98ddd4a9513 -r 3433df0d6ae3 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 15:45:34 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 18:25:19 2007 +0100 @@ -7,6 +7,7 @@ import lib.utils as utils import lib.server as server +import plugins.transcoders.mencoder_lib.mythtv as mythtv from select import select @@ -33,11 +34,6 @@ self.args["subtitle"] = params_first("subtitle", False) self.args["format"] = params_first("format", "mpeg1") self.args["outfile"] = params_first("outfile", "-") - self.args["sendback"] = params_first("sendback", True) - - # handle sendback variable - if self.args["sendback"] == "False": - self.args["sendback"] = False # input_opt uri = params_first("uri", "file:-").split(":", 1) @@ -200,8 +196,6 @@ os.write(stdw, data_in) total_read += 4096 d = stdout.read(4096) - if self.args["sendback"]: - outfd.write(d) self.status = total_read * 100 / size else: finished = True @@ -209,8 +203,6 @@ else: d = stdout.read(4096) - if self.args["sendback"] and d != "": - outfd.write(d) except Exception, e: self.log.error("Problems handling data: %s" % e) @@ -218,9 +210,6 @@ return False self.log.info("%s: Finished sending data to client" % repr(self)) - if not self.args["sendback"]: - outfd.write("DONE") - return True # _start_outfile() @@ -241,59 +230,6 @@ return True # _start() - def _start_myth(self, outfd): - # gmyth-cat -h 192.168.1.124 -p 6543 -c 111 - # gmyth-cat -h 192.168.1.124 -p 6543 -f file.nuv - # myth://IP:PORT:type:file - host = self.args["gmyth-cat"][0] - port = self.args["gmyth-cat"][1] - kind = self.args["gmyth-cat"][2] - fchan = self.args["gmyth-cat"][3] - - gmyth_cat = utils.which("gmyth-cat") - opts = [gmyth_cat, "-h", host, "-p", port, "-" + kind, fchan] - - try: - self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - close_fds=True) - except Exception, e: - self.log.error("Error executing gmyth-cat: %s" % e) - return False - - err = self.gmyth.stderr - - if not self._run_mencoder(input=self.gmyth.stdout, - output=subprocess.PIPE): - return False - - if kind == "f": - partial = 0 - size = err.read(20).split("\n")[0].split("Size:")[1] - self.log.debug("Size of file: %s" % size) - flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK - fcntl.fcntl(err, fcntl.F_SETFL, flags) - - try: - while self.proc and self.proc.poll() == None: - r, w, x = select([err, self.proc.stdout], [], [], 0) - if self.proc.stdout in r: - d = self.proc.stdout.read(4096) - outfd.write(d) - - if err in r and kind == "f": - partial = err.read(50).split("\n")[-2] - if partial != "": - utils.progress_bar(self.log, int(partial), int(size), 50) - - - except Exception, e: - self.log.error("Problems handling data: %s" % e) - return False - - return True - # _start_myth() - def _run_mencoder(self, input=None, output=None): try: self.proc = subprocess.Popen(self.mencoder_opts, stdin=input, @@ -315,7 +251,7 @@ ret = self._start(outfd) elif self.args["type"] == "myth": - ret = self._start_myth(outfd) + ret = mythtv.start_myth(self, outfd) else: ret = self._start_outfile(outfd) diff -r c98ddd4a9513 -r 3433df0d6ae3 gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py Tue May 15 18:25:19 2007 +0100 @@ -0,0 +1,72 @@ +import os +import subprocess +import fcntl + +import lib.utils as utils +import lib.server as server + +from select import select + +def _setup_mythfile(err): + size = err.read(20).split("\n")[0].split("Size:")[1] + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK + fcntl.fcntl(err, fcntl.F_SETFL, flags) + return size +# _setup_mythfile + +def _setup_gmythcat(self): + gmyth_cat = utils.which("gmyth-cat") + return [ utils.which("gmyth-cat"), + "-h", self.args["gmyth-cat"][0], + "-p", self.args["gmyth-cat"][1], + "-" + self.args["gmyth-cat"][2], + self.args["gmyth-cat"][3] + ] +# _setup_gmythcat + +def start_myth(self, outfd): + opts = _setup_gmythcat(self) + try: + self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True) + except Exception, e: + self.log.error("Error executing gmyth-cat: %s" % e) + return False + + if not self._run_mencoder(input=self.gmyth.stdout, + output=subprocess.PIPE): + return False + + if self.args["gmyth-cat"][2] == "f": + try: + size = _setup_mythfile(self.gmyth.stderr) + self.log.debug("Size of file: %s" % size) + except Exception, e: + self.log.error("Problems getting size of file: %s" % e) + return False + + try: + while self.proc and self.proc.poll() == None: + r, w, x = select([self.gmyth.stderr, self.proc.stdout], + [], [], 0) + if self.proc.stdout in r: + d = self.proc.stdout.read(4096) + outfd.write(d) + + if self.gmyth.stderr in r: + partial = self.gmyth.stderr.read(50).split("\n")[-2] + if partial != "": + self.status = utils.progress_bar(self.log, + int(partial), + int(size), 50) + + except IndexError, e: + pass + except Exception, e: + self.log.error("Problems handling data: %s" % e) + return False + + self.log.info("Finished sending data") + return True +# _start_myth()