Esempio n. 1
0
    def _parse_smpte(self, root):
        """
        Parses a SMPTE KDM

        :params root: the root element of the XML document
        :type root: ElementTree Element
        """
        self._kind = KDM.SMPTE
        smpte_etm_ns = get_namespace(root.tag)
        ap_el = get_element(root, 'AuthenticatedPublic', smpte_etm_ns)
        self.id = strip_urn(get_element_text(ap_el, 'MessageId', smpte_etm_ns))
        self.annotation_text = get_element_text(ap_el, 'AnnotationText',
                                                smpte_etm_ns)
        self.issue_date = get_element_text(ap_el, 'IssueDate', smpte_etm_ns)
        re_el = get_element(ap_el, 'RequiredExtensions', smpte_etm_ns)
        smpte_kdm_ns = 'http://www.smpte-ra.org/schemas/430-1/2006/KDM'
        kdm_re_el = get_element(re_el, 'KDMRequiredExtensions', smpte_kdm_ns)
        self.cpl_id = strip_urn(
            get_element_text(kdm_re_el, 'CompositionPlaylistId', smpte_kdm_ns))
        self.content_title_text = get_element_text(kdm_re_el,
                                                   'ContentTitleText',
                                                   smpte_kdm_ns)
        self.start_date = get_element_text(kdm_re_el,
                                           'ContentKeysNotValidBefore',
                                           smpte_kdm_ns)
        self.end_date = get_element_text(kdm_re_el, 'ContentKeysNotValidAfter',
                                         smpte_kdm_ns)
Esempio n. 2
0
    def parse(self):
        """
        Opens a given CPL asset, parses the XML to extract the playlist info and create a CPL object
        which is added to the DCP's CPL list.
        """
        try:
            tree = ET.parse(self.path)
            root = tree.getroot()
            # ElementTree prepends the namespace to all elements, so we need to extract
            # it so that we can perform sensible searching on elements.
            self.cpl_ns = get_namespace(root.tag)

            self.validate()
        except Exception as e:
            raise CPLError(e)


        self.id = get_element_text(root, "Id", self.cpl_ns).split(":")[2]
        self.content_title_text = get_element_text(root, "ContentTitleText", self.cpl_ns)
        self.annotation_text = get_element_text(root, "AnnotationText", self.cpl_ns)
        self.issue_date = parse_date(get_element_text(root, "IssueDate", self.cpl_ns))
        self.issuer = get_element_text(root, "Issuer", self.cpl_ns)
        self.creator = get_element_text(root, "Creator", self.cpl_ns)
        self.content_kind = get_element_text(root, "ContentKind", self.cpl_ns)

        # Get each of the parts of the CPL, i.e. the Reels :)
        for reel_list_elem in get_element_iterator(root, "ReelList", self.cpl_ns):
            for reel_elem in reel_list_elem.getchildren():
                reel = Reel(reel_elem, self.cpl_ns, assetmap=self.assetmap)

                # Add this in as a convenience for working with assets.
                for asset_id, asset in reel.assets.iteritems():
                    self.assets[asset_id] = asset

                self.reels.append(reel)
Esempio n. 3
0
    def parse(self):
        """
        Parse the pkl.xml, extracts asset info for storage in memory.
        """
        try:
            self.validate()
        except Exception as e:
            raise PKLError(e)

        # Get hashes from pkl.xml file
        tree = ET.parse(self.path)
        root = tree.getroot()

        # Again, get the namespace so we can search elements
        pkl_ns = get_namespace(root.tag)
        self.id = get_element_text(root, "Id", pkl_ns).split(":")[2]

        asset_list = get_element(root, "AssetList", pkl_ns)

        # Get the data from the pkl file
        for asset in asset_list.getchildren():
            asset_id = get_element_text(asset, "Id", pkl_ns).split(":")[2]

            p = {
                "file_hash": get_element_text(asset, "Hash", pkl_ns),
                "size": get_element_text(asset, "Size", pkl_ns),
                "file_type": get_element_text(asset, "Type", pkl_ns)
            }

            self.assets[asset_id] = PKLData(**p)
Esempio n. 4
0
 def _parse(self, catalog_str):
     """
     Parses a KDM bundle catalog XML string
     """
     root = ET.fromstring(catalog_str)
     cat_ns = get_namespace(root.tag)
     self.id = strip_urn(get_element_text(root, 'Id', cat_ns))
     self.annotation_text = get_element_text(root, 'AnnotationText', cat_ns)
     self.creator = get_element_text(root, 'Creator', cat_ns)
     self.cpl_ids = []
     self.kdm_paths = []
     self.start_dates = []
     self.end_dates = []
     for kdm_list_el in get_element_iterator(root, 'KDMFileList', cat_ns):
         for kdm_el in kdm_list_el.getchildren():
             self.cpl_ids.append(
                 strip_urn(get_element_text(kdm_el, 'CPLId', cat_ns)))
             self.kdm_paths.append(
                 get_element_text(kdm_el, 'FilePath', cat_ns))
             self.start_dates.append(
                 get_element_text(kdm_el, 'ContentKeysNotValidBefore',
                                  cat_ns))
             self.end_dates.append(
                 get_element_text(kdm_el, 'ContentKeysNotValidAfter',
                                  cat_ns))
Esempio n. 5
0
    def parse(self):
        """
        Parse the pkl.xml, extracts asset info for storage in memory.
        """
        try:
            self.validate()
        except Exception as e:
            raise PKLError(e)

        # Get hashes from pkl.xml file
        tree = ET.parse(self.path)
        root = tree.getroot()

        # Again, get the namespace so we can search elements
        pkl_ns = get_namespace(root.tag)
        self.id = get_element_text(root, "Id", pkl_ns).split(":")[2]

        asset_list = get_element(root, "AssetList", pkl_ns)

        # Get the data from the pkl file
        for asset in asset_list.getchildren():
            asset_id = get_element_text(asset, "Id", pkl_ns).split(":")[2]

            p = {
                "file_hash": get_element_text(asset, "Hash", pkl_ns),
                "size": get_element_text(asset, "Size", pkl_ns),
                "file_type": get_element_text(asset, "Type", pkl_ns)
            }

            self.assets[asset_id] = PKLData(**p)
Esempio n. 6
0
 def fromstring(self, xml):
     try:
         tree = ET.ElementTree(ET.fromstring(xml))
         root = tree.getroot()
         self.cpl_ns = get_namespace(root.tag)
         # self.validate(xml=xml)
     except Exception as e:
         raise CPLError(e)
     self._parse(tree)
Esempio n. 7
0
 def fromstring(self, xml):
     try:
         tree = ET.ElementTree(ET.fromstring(xml))
         root = tree.getroot()
         self.cpl_ns = get_namespace(root.tag)
         # self.validate(xml=xml)
     except Exception as e:
         raise CPLError(e)
     self._parse(tree)
Esempio n. 8
0
 def parse(self):
     """
     Opens a given CPL asset, parses the XML to extract the playlist info and create a CPL object
     which is added to the DCP's CPL list.
     """
     try:
         tree = ET.parse(self.path)
         root = tree.getroot()
         self.cpl_ns = get_namespace(root.tag)
         # self.validate()
     except Exception as e:
         raise CPLError(e)
     self._parse(root)
Esempio n. 9
0
 def parse(self):
     """
     Opens a given CPL asset, parses the XML to extract the playlist info and create a CPL object
     which is added to the DCP's CPL list.
     """
     try:
         tree = ET.parse(self.path)
         root = tree.getroot()
         self.cpl_ns = get_namespace(root.tag)
         # self.validate()
     except Exception as e:
         raise CPLError(e)
     self._parse(root)
Esempio n. 10
0
    def _parse(self, kdm_xml):
        """
        Parses a KDM XML document

        :param kdm_xml: an interop or smpte KDM XML document
        :type kdm_xml: string
        """
        root = ET.fromstring(kdm_xml)
        kdm_ns = get_namespace(root.tag)
        if kdm_ns.startswith('http://www.smpte-ra.org'):
            self._parse_smpte(root)
        else:
            self._parse_interop(root)
Esempio n. 11
0
    def _parse(self, kdm_xml):
        """
        Parses a KDM XML document

        :param kdm_xml: an interop or smpte KDM XML document
        :type kdm_xml: string
        """
        root = ET.fromstring(kdm_xml)
        kdm_ns = get_namespace(root.tag)
        if kdm_ns.startswith('http://www.smpte-ra.org'):
            self._parse_smpte(root)
        else:
            self._parse_interop(root)
Esempio n. 12
0
    def parse(self):
        """
        Parse the ASSETMAP. Extract the id, path, volume index, offset and
        length for each asset, and the validate the paths of the downloaded
        files against the paths from the ASSETMAP file.
        """
        try:
            self.validate()
        except Exception as e:
            raise AssetmapError(e)

        tree = ET.parse(self.path)
        root = tree.getroot()
        # ElementTree prepends the namespace to all elements, so we need to extract
        # it so that we can perform sensible searching on elements.
        assetmap_ns = get_namespace(root.tag)

        self.id = get_element_text(root, "Id", assetmap_ns).split(":")[2]
        self.annotation_text = get_element_text(root, "AnnotationText",
                                                assetmap_ns)
        self.volume_count = int(
            get_element_text(root, "VolumeCount", assetmap_ns))
        self.issue_date = parse_date(
            get_element_text(root, "IssueDate", assetmap_ns))
        self.issuer = get_element_text(root, "Issuer", assetmap_ns)
        self.creator = get_element_text(root, "Creator", assetmap_ns)

        asset_list = get_element(root, "AssetList", assetmap_ns)
        # Get the data from the ASSETMAP file
        for asset in asset_list.getchildren():
            asset_id = get_element_text(asset, "Id", assetmap_ns).split(":")[2]
            for chunklist in get_element_iterator(asset, "ChunkList",
                                                  assetmap_ns):
                """
                The code below assumes that there will only ever be one chunk in a chunklist. Chunking is 
                used to split files up into smaller parts, usually in order to provide compatability with older
                filesystems, which is not applicable for our uses.
                """
                for chunk in chunklist.getchildren():
                    v = get_element_text(chunk, "VolumeIndex", assetmap_ns)
                    o = get_element_text(chunk, "Offset", assetmap_ns)
                    l = get_element_text(chunk, "Length", assetmap_ns)

                    a = {
                        "path": get_element_text(chunk, "Path", assetmap_ns),
                        "volume_index": int(v) if v is not None else v,
                        "offset": int(o) if o is not None else o,
                        "length": int(l) if l is not None else l
                    }

                    self.assets[asset_id] = AssetData(**a)
Esempio n. 13
0
    def parse(self):
        """
        Parse the ASSETMAP. Extract the id, path, volume index, offset and
        length for each asset, and the validate the paths of the downloaded
        files against the paths from the ASSETMAP file.
        """
        try:
            self.validate()
        except Exception as e:
            raise AssetmapError(e)

        tree = ET.parse(self.path)
        root = tree.getroot()
        # ElementTree prepends the namespace to all elements, so we need to extract
        # it so that we can perform sensible searching on elements.
        assetmap_ns = get_namespace(root.tag)

        self.id = get_element_text(root, "Id", assetmap_ns).split(":")[2]
        self.annotation_text = get_element_text(root, "AnnotationText", assetmap_ns)
        self.volume_count = int(get_element_text(root, "VolumeCount", assetmap_ns))
        self.issue_date = parse_date(get_element_text(root, "IssueDate", assetmap_ns))
        self.issuer = get_element_text(root, "Issuer", assetmap_ns)
        self.creator = get_element_text(root, "Creator", assetmap_ns)

        asset_list = get_element(root, "AssetList", assetmap_ns)
        # Get the data from the ASSETMAP file
        for asset in asset_list.getchildren():
            asset_id = get_element_text(asset, "Id", assetmap_ns).split(":")[2]
            for chunklist in get_element_iterator(asset, "ChunkList", assetmap_ns):
                """
                The code below assumes that there will only ever be one chunk in a chunklist. Chunking is 
                used to split files up into smaller parts, usually in order to provide compatability with older
                filesystems, which is not applicable for our uses.
                """
                for chunk in chunklist.getchildren():
                    v = get_element_text(chunk, "VolumeIndex", assetmap_ns)
                    o = get_element_text(chunk, "Offset", assetmap_ns) 
                    l = get_element_text(chunk, "Length", assetmap_ns)
                    
                    a = {
                        "path": get_element_text(chunk, "Path", assetmap_ns),
                        "volume_index": int(v) if v is not None else v,
                        "offset": int(o) if o is not None else o,
                        "length": int(l) if l is not None else l
                    }

                    self.assets[asset_id] = AssetData(**a)
Esempio n. 14
0
    def _parse_interop(self, root):
        """
        Parses a KDM in interop format

        :params root: the root element of the XML document
        :type root: ElementTree Element
        """
        self._kind = KDM.INTEROP
        interop_kdm_ns = get_namespace(root.tag)
        ap_el = get_element(root, 'AuthenticatedPublic', interop_kdm_ns)
        self.id = strip_urn(get_element_text(ap_el, 'MessageId', interop_kdm_ns))
        self.annotation_text = get_element_text(ap_el, 'AnnotationText', interop_kdm_ns)
        self.issue_date = get_element_text(ap_el, 'IssueDate', interop_kdm_ns)
        re_el = get_element(ap_el, 'RequiredExtensions', interop_kdm_ns)
        self.cpl_id = strip_urn(get_element_text(re_el, 'CompositionPlaylistId', interop_kdm_ns))
        self.content_title_text = get_element_text(re_el, 'ContentTitleText', interop_kdm_ns)
        self.start_date = get_element_text(re_el, 'ContentKeysNotValidBefore', interop_kdm_ns)
        self.end_date = get_element_text(re_el, 'ContentKeysNotValidAfter', interop_kdm_ns)
Esempio n. 15
0
    def _parse_interop(self, root):
        """
        Parses a KDM in interop format

        :params root: the root element of the XML document
        :type root: ElementTree Element
        """
        self._kind = KDM.INTEROP
        interop_kdm_ns = get_namespace(root.tag)
        ap_el = get_element(root, 'AuthenticatedPublic', interop_kdm_ns)
        self.id = strip_urn(get_element_text(ap_el, 'MessageId', interop_kdm_ns))
        self.annotation_text = get_element_text(ap_el, 'AnnotationText', interop_kdm_ns)
        self.issue_date = get_element_text(ap_el, 'IssueDate', interop_kdm_ns)
        re_el = get_element(ap_el, 'RequiredExtensions', interop_kdm_ns)
        self.cpl_id = strip_urn(get_element_text(re_el, 'CompositionPlaylistId', interop_kdm_ns))
        self.content_title_text = get_element_text(re_el, 'ContentTitleText', interop_kdm_ns)
        self.start_date = get_element_text(re_el, 'ContentKeysNotValidBefore', interop_kdm_ns)
        self.end_date = get_element_text(re_el, 'ContentKeysNotValidAfter', interop_kdm_ns)
Esempio n. 16
0
 def _parse(self, catalog_str):
     """
     Parses a KDM bundle catalog XML string
     """
     root = ET.fromstring(catalog_str)
     cat_ns = get_namespace(root.tag)
     self.id = strip_urn(get_element_text(root, 'Id', cat_ns))
     self.annotation_text = get_element_text(root, 'AnnotationText', cat_ns)
     self.creator = get_element_text(root, 'Creator', cat_ns)
     self.cpl_ids = []
     self.kdm_paths = []
     self.start_dates = []
     self.end_dates = []
     for kdm_list_el in get_element_iterator(root, 'KDMFileList', cat_ns):
         for kdm_el in kdm_list_el.getchildren():
             self.cpl_ids.append(strip_urn(get_element_text(kdm_el, 'CPLId', cat_ns)))
             self.kdm_paths.append(get_element_text(kdm_el, 'FilePath', cat_ns))
             self.start_dates.append(get_element_text(kdm_el, 'ContentKeysNotValidBefore', cat_ns))
             self.end_dates.append(get_element_text(kdm_el, 'ContentKeysNotValidAfter', cat_ns))
Esempio n. 17
0
    def _parse_smpte(self, root):
        """
        Parses a SMPTE KDM

        :params root: the root element of the XML document
        :type root: ElementTree Element
        """
        self._kind = KDM.SMPTE
        smpte_etm_ns = get_namespace(root.tag)
        ap_el = get_element(root, 'AuthenticatedPublic', smpte_etm_ns)
        self.id = strip_urn(get_element_text(ap_el, 'MessageId', smpte_etm_ns))
        self.annotation_text = get_element_text(ap_el, 'AnnotationText', smpte_etm_ns)
        self.issue_date = get_element_text(ap_el, 'IssueDate', smpte_etm_ns)
        re_el = get_element(ap_el, 'RequiredExtensions', smpte_etm_ns)
        smpte_kdm_ns ='http://www.smpte-ra.org/schemas/430-1/2006/KDM'
        kdm_re_el = get_element(re_el, 'KDMRequiredExtensions', smpte_kdm_ns)
        self.cpl_id = strip_urn(get_element_text(kdm_re_el, 'CompositionPlaylistId', smpte_kdm_ns))
        self.content_title_text = get_element_text(kdm_re_el, 'ContentTitleText', smpte_kdm_ns)
        self.start_date = get_element_text(kdm_re_el, 'ContentKeysNotValidBefore', smpte_kdm_ns)
        self.end_date = get_element_text(kdm_re_el, 'ContentKeysNotValidAfter', smpte_kdm_ns)
Esempio n. 18
0
    def parse(self):
        """
        Opens a given CPL asset, parses the XML to extract the playlist info and create a CPL object
        which is added to the DCP's CPL list.
        """
        try:
            tree = ET.parse(self.path)
            root = tree.getroot()
            # ElementTree prepends the namespace to all elements, so we need to extract
            # it so that we can perform sensible searching on elements.
            self.cpl_ns = get_namespace(root.tag)

            self.validate()
        except Exception as e:
            raise CPLError(e)

        self.id = get_element_text(root, "Id", self.cpl_ns).split(":")[2]
        self.content_title_text = get_element_text(root, "ContentTitleText",
                                                   self.cpl_ns)
        self.annotation_text = get_element_text(root, "AnnotationText",
                                                self.cpl_ns)
        self.issue_date = parse_date(
            get_element_text(root, "IssueDate", self.cpl_ns))
        self.issuer = get_element_text(root, "Issuer", self.cpl_ns)
        self.creator = get_element_text(root, "Creator", self.cpl_ns)
        self.content_kind = get_element_text(root, "ContentKind", self.cpl_ns)

        # Get each of the parts of the CPL, i.e. the Reels :)
        for reel_list_elem in get_element_iterator(root, "ReelList",
                                                   self.cpl_ns):
            for reel_elem in reel_list_elem.getchildren():
                reel = Reel(reel_elem, self.cpl_ns, assetmap=self.assetmap)

                # Add this in as a convenience for working with assets.
                for asset_id, asset in reel.assets.iteritems():
                    self.assets[asset_id] = asset

                self.reels.append(reel)