def _load_mediainfo(self): command = self.env.initialize_command("mediainfo", self.log) if command: command.extend([u"--Language=raw", u"--Output=XML", u"--Full", self.ontology["path"]]) proc_mediainfo = Popen(command, stdout=PIPE, stderr=PIPE) proc_grep = Popen([u"grep", u"-v", u"Cover_Data"], stdin=proc_mediainfo.stdout, stdout=PIPE) raw_xml = proc_grep.communicate()[0] # parse the DOM element = ElementTree.fromstring(raw_xml) if element is not None: for node in element.findall(u"File/track"): if "type" in node.attrib: mtype = self.env.enumeration["mediainfo stream type"].search(node.attrib["type"]) if mtype is not None: if mtype.node["namespace"]: # initialize an ontology with the correct namespace o = Ontology(self.env, mtype.node["namespace"]) # iterate over the properties and populate the ontology for item in list(node): text = item.text # decode base64 encoded element if "dt" in item.attrib and item.attrib["dt"] == "binary.base64": text = base64.b64decode(text) text = unicode(text, "utf8") # set the concept on the ontology o.decode(item.tag, text) # fix the video encoder settings on video tracks if mtype.key == "video": self._fix_mediainfo_encoder_settings(o) # add the ontology to the stream stack self._execution["crawl"]["stream"].append(o) elif mtype.key == "menu": menu = Menu(self.env) for item in list(node): menu.add(Chapter.from_raw(item.tag, item.text, Chapter.MEDIAINFO)) menu.normalize() if menu.valid: self._execution["crawl"]["menu"].append(menu) # Release resources held by the element, we no longer need it element.clear()
def parse(self): arguments = vars(self.parser.parse_args()) ontology = Ontology(self.env, self.node['namespace']) for k,v in arguments.iteritems(): ontology.decode(k, v) return ontology