5 import lib.utils as utils
6 import lib.server as server
8 from select import select
10 buffer_size = 1024 * 64
12 def _setup_mythfilename(self):
13 # mythtv:mythtv@192.168.3.110:6543/1002_20070426230000.nuv
15 _mysql = self.args["input"].split("@")[0].split(":")
17 _mysql = ["mythtv", "mythtv"]
20 _args = self.args["input"].split("@")[1].split(":")
22 _args = self.args["input"].split(":")
25 gmyth_dict["mysql"] = _mysql
26 gmyth_dict["backend"] = _args[0]
27 gmyth_dict["port"] = _args[1].split("/", 1)[0]
29 _tmp_file = _args[1].split("/", 1)[1]
31 if _tmp_file.find("channel") >= 0:
32 gmyth_dict["kind"] = "c"
33 gmyth_dict["cfile"] = _tmp_file.split("=")[1]
35 gmyth_dict["kind"] = "f"
36 gmyth_dict["cfile"] = _tmp_file
38 self.args["input"] = "-"
42 def _setup_mythfile(err):
43 size = err.readline().split("Size:")[1]
44 flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
45 fcntl.fcntl(err, fcntl.F_SETFL, flags)
49 def _setup_gmythcat(self):
50 gmyth_cat = utils.which("gmyth-cat")
51 if self.args.has_key("gmyth-cat"):
52 return [ utils.which("gmyth-cat"),
53 "-h", self.args["gmyth-cat"]["backend"],
54 "-p", self.args["gmyth-cat"]["port"],
55 "-" + self.args["gmyth-cat"]["kind"],
56 self.args["gmyth-cat"]["cfile"]
59 self.log.error(self.tid, "Error: URI error")
63 def start_myth(self, outfd):
64 opts = _setup_gmythcat(self)
66 self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
67 stderr=subprocess.PIPE,
70 self.log.error(self.tid, "Error: gmyth-cat: %s" % e)
73 if not self._run_mencoder(input=self.gmyth.stdout,
74 output=subprocess.PIPE):
77 if self.args["gmyth-cat"]["kind"] == "f":
79 size = _setup_mythfile(self.gmyth.stderr)
80 self.log.debug(self.tid, "Info: Size of file: %s" % size)
82 self.log.error(self.tid, "Error: Problems getting size of"\
84 outfd.write("Error: Problems getting size of file: %s" % e)
90 while self.proc and self.proc.poll() == None:
91 r, w, x = select([self.gmyth.stderr, self.proc.stdout],
93 if self.proc.stdout in r:
94 d = self.proc.stdout.read(buffer_size)
95 outfd.write("%x\r\n", len(d))
99 if self.gmyth.stderr in r:
100 partial = self.gmyth.stderr.readline()
102 self.status = utils.progress_bar(int(partial),
105 outfd.write("0\r\n\r\n")
107 except IndexError, e:
110 self.log.error(self.tid, "Error: %s" % e)
113 self.log.info(self.tid, "OK: Done")