1.1 --- a/gmyth-stream/server/0.2/lib/server.py Tue May 15 15:45:34 2007 +0100
1.2 +++ b/gmyth-stream/server/0.2/lib/server.py Tue May 15 18:25:19 2007 +0100
1.3 @@ -63,12 +63,9 @@
1.4
1.5
1.6 def __str__(self):
1.7 - return '%s("%s", mux="%s", params=%s, addr=%s)' % \
1.8 + return '%s( params=%s )' % \
1.9 (self.__class__.__name__,
1.10 - self.params_first("uri", "None"),
1.11 - self.params_first("mux", "mpg"),
1.12 - self.params,
1.13 - repr(self))
1.14 + self.params)
1.15 # __str__()
1.16 # Transcoder
1.17
1.18 @@ -244,16 +241,32 @@
1.19 running = "<p>No running transcoder.</p>\n"
1.20 stopall = ""
1.21 stopone = ""
1.22 +
1.23 + elif self.query.get("ip") and self.query.get("file"):
1.24 + for transcoder, request in tl:
1.25 + filename = "%s" % self.query.get("file")[0]
1.26 + tfilename = "%s" % transcoder.params_first("uri")
1.27 +
1.28 + if tfilename.find(filename) >= 0 and \
1.29 + request.client_address[0] == self.query.get("ip")[0]:
1.30 + self.wfile.write("Status: %s %%" % transcoder.status)
1.31 + return
1.32 +
1.33 else:
1.34 running = "<p>Running transcoders:</p>\n"
1.35 - stopall = self._create_html_item("<a href='%s?request=all'>[STOP ALL]</a>" %
1.36 + stopall = self._create_html_item("<a href='%s?request=all'>"
1.37 + "[STOP ALL]</a>" %
1.38 self.menu["Stop"])
1.39
1.40 for transcoder, request in tl:
1.41 - stopone = self._create_html_item("%s: %s:%s<a href='%s?request=%s:%s'>"
1.42 - "[STOP]</a> - Status: %s%%" % (
1.43 - transcoder, request.client_address[0], request.client_address[1],
1.44 - self.menu["Stop"], request.client_address[0], request.client_address[1],
1.45 + stopone = self._create_html_item("%s: %s:%s<a href='%s?"
1.46 + "request=%s:%s'>"
1.47 + "[STOP]</a> - Status: %s%%"\
1.48 + % (
1.49 + transcoder, request.client_address[0],
1.50 + request.client_address[1],
1.51 + self.menu["Stop"], request.client_address[0],
1.52 + request.client_address[1],
1.53 transcoder.status) )
1.54
1.55 self.wfile.write(utils.getHTML("status",
2.1 --- a/gmyth-stream/server/0.2/lib/utils.py Tue May 15 15:45:34 2007 +0100
2.2 +++ b/gmyth-stream/server/0.2/lib/utils.py Tue May 15 18:25:19 2007 +0100
2.3 @@ -170,5 +170,5 @@
2.4 else:
2.5 sys.stdout.write("[%3i%%]\r" % (percent))
2.6 sys.stdout.flush()
2.7 -
2.8 + return percent
2.9 # progress_bar by osantana
3.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 15:45:34 2007 +0100
3.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 18:25:19 2007 +0100
3.3 @@ -7,6 +7,7 @@
3.4
3.5 import lib.utils as utils
3.6 import lib.server as server
3.7 +import plugins.transcoders.mencoder_lib.mythtv as mythtv
3.8
3.9 from select import select
3.10
3.11 @@ -33,11 +34,6 @@
3.12 self.args["subtitle"] = params_first("subtitle", False)
3.13 self.args["format"] = params_first("format", "mpeg1")
3.14 self.args["outfile"] = params_first("outfile", "-")
3.15 - self.args["sendback"] = params_first("sendback", True)
3.16 -
3.17 - # handle sendback variable
3.18 - if self.args["sendback"] == "False":
3.19 - self.args["sendback"] = False
3.20
3.21 # input_opt
3.22 uri = params_first("uri", "file:-").split(":", 1)
3.23 @@ -200,8 +196,6 @@
3.24 os.write(stdw, data_in)
3.25 total_read += 4096
3.26 d = stdout.read(4096)
3.27 - if self.args["sendback"]:
3.28 - outfd.write(d)
3.29 self.status = total_read * 100 / size
3.30 else:
3.31 finished = True
3.32 @@ -209,8 +203,6 @@
3.33
3.34 else:
3.35 d = stdout.read(4096)
3.36 - if self.args["sendback"] and d != "":
3.37 - outfd.write(d)
3.38
3.39 except Exception, e:
3.40 self.log.error("Problems handling data: %s" % e)
3.41 @@ -218,9 +210,6 @@
3.42 return False
3.43
3.44 self.log.info("%s: Finished sending data to client" % repr(self))
3.45 - if not self.args["sendback"]:
3.46 - outfd.write("DONE")
3.47 -
3.48 return True
3.49 # _start_outfile()
3.50
3.51 @@ -241,59 +230,6 @@
3.52 return True
3.53 # _start()
3.54
3.55 - def _start_myth(self, outfd):
3.56 - # gmyth-cat -h 192.168.1.124 -p 6543 -c 111
3.57 - # gmyth-cat -h 192.168.1.124 -p 6543 -f file.nuv
3.58 - # myth://IP:PORT:type:file
3.59 - host = self.args["gmyth-cat"][0]
3.60 - port = self.args["gmyth-cat"][1]
3.61 - kind = self.args["gmyth-cat"][2]
3.62 - fchan = self.args["gmyth-cat"][3]
3.63 -
3.64 - gmyth_cat = utils.which("gmyth-cat")
3.65 - opts = [gmyth_cat, "-h", host, "-p", port, "-" + kind, fchan]
3.66 -
3.67 - try:
3.68 - self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
3.69 - stderr=subprocess.PIPE,
3.70 - close_fds=True)
3.71 - except Exception, e:
3.72 - self.log.error("Error executing gmyth-cat: %s" % e)
3.73 - return False
3.74 -
3.75 - err = self.gmyth.stderr
3.76 -
3.77 - if not self._run_mencoder(input=self.gmyth.stdout,
3.78 - output=subprocess.PIPE):
3.79 - return False
3.80 -
3.81 - if kind == "f":
3.82 - partial = 0
3.83 - size = err.read(20).split("\n")[0].split("Size:")[1]
3.84 - self.log.debug("Size of file: %s" % size)
3.85 - flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
3.86 - fcntl.fcntl(err, fcntl.F_SETFL, flags)
3.87 -
3.88 - try:
3.89 - while self.proc and self.proc.poll() == None:
3.90 - r, w, x = select([err, self.proc.stdout], [], [], 0)
3.91 - if self.proc.stdout in r:
3.92 - d = self.proc.stdout.read(4096)
3.93 - outfd.write(d)
3.94 -
3.95 - if err in r and kind == "f":
3.96 - partial = err.read(50).split("\n")[-2]
3.97 - if partial != "":
3.98 - utils.progress_bar(self.log, int(partial), int(size), 50)
3.99 -
3.100 -
3.101 - except Exception, e:
3.102 - self.log.error("Problems handling data: %s" % e)
3.103 - return False
3.104 -
3.105 - return True
3.106 - # _start_myth()
3.107 -
3.108 def _run_mencoder(self, input=None, output=None):
3.109 try:
3.110 self.proc = subprocess.Popen(self.mencoder_opts, stdin=input,
3.111 @@ -315,7 +251,7 @@
3.112 ret = self._start(outfd)
3.113
3.114 elif self.args["type"] == "myth":
3.115 - ret = self._start_myth(outfd)
3.116 + ret = mythtv.start_myth(self, outfd)
3.117
3.118 else:
3.119 ret = self._start_outfile(outfd)
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py Tue May 15 18:25:19 2007 +0100
4.3 @@ -0,0 +1,72 @@
4.4 +import os
4.5 +import subprocess
4.6 +import fcntl
4.7 +
4.8 +import lib.utils as utils
4.9 +import lib.server as server
4.10 +
4.11 +from select import select
4.12 +
4.13 +def _setup_mythfile(err):
4.14 + size = err.read(20).split("\n")[0].split("Size:")[1]
4.15 + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
4.16 + fcntl.fcntl(err, fcntl.F_SETFL, flags)
4.17 + return size
4.18 +# _setup_mythfile
4.19 +
4.20 +def _setup_gmythcat(self):
4.21 + gmyth_cat = utils.which("gmyth-cat")
4.22 + return [ utils.which("gmyth-cat"),
4.23 + "-h", self.args["gmyth-cat"][0],
4.24 + "-p", self.args["gmyth-cat"][1],
4.25 + "-" + self.args["gmyth-cat"][2],
4.26 + self.args["gmyth-cat"][3]
4.27 + ]
4.28 +# _setup_gmythcat
4.29 +
4.30 +def start_myth(self, outfd):
4.31 + opts = _setup_gmythcat(self)
4.32 + try:
4.33 + self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
4.34 + stderr=subprocess.PIPE,
4.35 + close_fds=True)
4.36 + except Exception, e:
4.37 + self.log.error("Error executing gmyth-cat: %s" % e)
4.38 + return False
4.39 +
4.40 + if not self._run_mencoder(input=self.gmyth.stdout,
4.41 + output=subprocess.PIPE):
4.42 + return False
4.43 +
4.44 + if self.args["gmyth-cat"][2] == "f":
4.45 + try:
4.46 + size = _setup_mythfile(self.gmyth.stderr)
4.47 + self.log.debug("Size of file: %s" % size)
4.48 + except Exception, e:
4.49 + self.log.error("Problems getting size of file: %s" % e)
4.50 + return False
4.51 +
4.52 + try:
4.53 + while self.proc and self.proc.poll() == None:
4.54 + r, w, x = select([self.gmyth.stderr, self.proc.stdout],
4.55 + [], [], 0)
4.56 + if self.proc.stdout in r:
4.57 + d = self.proc.stdout.read(4096)
4.58 + outfd.write(d)
4.59 +
4.60 + if self.gmyth.stderr in r:
4.61 + partial = self.gmyth.stderr.read(50).split("\n")[-2]
4.62 + if partial != "":
4.63 + self.status = utils.progress_bar(self.log,
4.64 + int(partial),
4.65 + int(size), 50)
4.66 +
4.67 + except IndexError, e:
4.68 + pass
4.69 + except Exception, e:
4.70 + self.log.error("Problems handling data: %s" % e)
4.71 + return False
4.72 +
4.73 + self.log.info("Finished sending data")
4.74 + return True
4.75 +# _start_myth()