Ejemplo n.º 1
0
    def _parseTimestamp(self, ts):
        # Take TS in YYYY-MM-DDThh:mm:ss.ssZ format, return timestamp in
        # nanoseconds since the epoch

        # time.strptime() doesn't handle the fractional seconds part. We ignore
        # it entirely, after verifying that it has the right format.
        tsmain, trailing = ts[:-4], ts[-4:]
        if trailing[0] != '.' or trailing[3] != 'Z' or \
                not trailing[1].isdigit() or not trailing[2].isdigit():
            raise fxml.ParserError("Invalid timestamp %s" % ts)
        formatString = "%Y-%m-%dT%H:%M:%S"

        try:
            timestruct = time.strptime(tsmain, formatString)
            return int(calendar.timegm(timestruct) * gst.SECOND)
        except ValueError:
            raise fxml.ParserError("Invalid timestamp %s" % ts)
Ejemplo n.º 2
0
    def _parseAttributes(self, node, required, optional):
        out = []
        for k in required:
            if node.hasAttribute(k):
                out.append(node.getAttribute(k))
            else:
                raise fxml.ParserError("Missing required attribute %s" % k)

        for k in optional:
            if node.hasAttribute(k):
                out.append(node.getAttribute(k))
            else:
                out.append(None)
        return out
Ejemplo n.º 3
0
    def parseFile(self, file, piid=None):
        """
        Parse a playlist file. Adds the contents of the file to the existing
        playlist, overwriting any existing entries for the same time period.
        """
        parser = fxml.Parser()

        root = parser.getRoot(file)

        node = root.documentElement
        self.debug("Parsing playlist from file %s", file)
        if node.nodeName != 'playlist':
            raise fxml.ParserError("Root node is not 'playlist'")

        self.blockDiscovery()
        try:
            for child in node.childNodes:
                if child.nodeType == Node.ELEMENT_NODE and \
                        child.nodeName == 'entry':
                    self.debug("Parsing entry")
                    self._parsePlaylistEntry(parser, child, piid)
        finally:
            self.unblockDiscovery()