1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py Tue May 15 20:16:26 2007 +0100
1.3 @@ -0,0 +1,72 @@
1.4 +import os
1.5 +import subprocess
1.6 +import fcntl
1.7 +
1.8 +import lib.utils as utils
1.9 +import lib.server as server
1.10 +
1.11 +from select import select
1.12 +
1.13 +def _setup_mythfile(err):
1.14 + size = err.read(20).split("\n")[0].split("Size:")[1]
1.15 + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
1.16 + fcntl.fcntl(err, fcntl.F_SETFL, flags)
1.17 + return size
1.18 +# _setup_mythfile
1.19 +
1.20 +def _setup_gmythcat(self):
1.21 + gmyth_cat = utils.which("gmyth-cat")
1.22 + return [ utils.which("gmyth-cat"),
1.23 + "-h", self.args["gmyth-cat"][0],
1.24 + "-p", self.args["gmyth-cat"][1],
1.25 + "-" + self.args["gmyth-cat"][2],
1.26 + self.args["gmyth-cat"][3]
1.27 + ]
1.28 +# _setup_gmythcat
1.29 +
1.30 +def start_myth(self, outfd):
1.31 + opts = _setup_gmythcat(self)
1.32 + try:
1.33 + self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
1.34 + stderr=subprocess.PIPE,
1.35 + close_fds=True)
1.36 + except Exception, e:
1.37 + self.log.error("Error executing gmyth-cat: %s" % e)
1.38 + return False
1.39 +
1.40 + if not self._run_mencoder(input=self.gmyth.stdout,
1.41 + output=subprocess.PIPE):
1.42 + return False
1.43 +
1.44 + if self.args["gmyth-cat"][2] == "f":
1.45 + try:
1.46 + size = _setup_mythfile(self.gmyth.stderr)
1.47 + self.log.debug("Size of file: %s" % size)
1.48 + except Exception, e:
1.49 + self.log.error("Problems getting size of file: %s" % e)
1.50 + return False
1.51 +
1.52 + try:
1.53 + while self.proc and self.proc.poll() == None:
1.54 + r, w, x = select([self.gmyth.stderr, self.proc.stdout],
1.55 + [], [], 0)
1.56 + if self.proc.stdout in r:
1.57 + d = self.proc.stdout.read(4096)
1.58 + outfd.write(d)
1.59 +
1.60 + if self.gmyth.stderr in r:
1.61 + partial = self.gmyth.stderr.read(50).split("\n")[-2]
1.62 + if partial != "":
1.63 + self.status = utils.progress_bar(self.log,
1.64 + int(partial),
1.65 + int(size), 50)
1.66 +
1.67 + except IndexError, e:
1.68 + pass
1.69 + except Exception, e:
1.70 + self.log.error("Problems handling data: %s" % e)
1.71 + return False
1.72 +
1.73 + self.log.info("Finished sending data")
1.74 + return True
1.75 +# _start_myth()