Ejemplo 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)
Ejemplo n.º 2
0
    def __init__(self, element, cpl_ns, assetmap=None):
        """
        Takes a "Reel" element and parses out the information contained inside.

        @todo: Check this against 3D content, in theory it should work but needs tests!
        """

        self.assets = {}
        self.id = get_element_text(element, "Id", cpl_ns).split(":")[2]

        for asset in get_element(element, "AssetList", cpl_ns).getchildren():
            asset_tag = asset.tag.split('}')[
                1]  # Remove the namespace, hack but it works for now!
            if asset_tag in ("MainPicture", "MainStereoscopicPicture"):
                asset_instance = Picture(asset, cpl_ns)
                self.picture = asset_instance
            elif asset_tag == "MainSound":
                asset_instance = Sound(asset, cpl_ns)
                self.sound = asset_instance
            elif asset_tag == "MainSubtitle":
                asset_instance = Subtitle(asset, cpl_ns)
                self.subtitle = asset_instance
            else:
                raise CPLError(
                    "Unknown asset type found: {0}".format(asset_tag))

            # Finally set the path to this particular asset.
            if assetmap is not None:
                asset_instance.path = assetmap[asset_instance.id].path

            # Assets can be accessed in two ways now.
            self.assets[asset_instance.id] = asset_instance
Ejemplo 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)
Ejemplo n.º 4
0
    def __init__(self, element, cpl_ns, assetmap=None):
        """
        Takes a "Reel" element and parses out the information contained inside.

        @todo: Check this against 3D content, in theory it should work but needs tests!
        """

        self.assets = {}
        self.id = get_element_text(element, "Id", cpl_ns).split(":")[2]

        for asset in get_element(element, "AssetList", cpl_ns).getchildren():
            asset_tag = asset.tag.split('}')[1] # Remove the namespace, hack but it works for now!
            if asset_tag in ("MainPicture", "MainStereoscopicPicture"):
                asset_instance = Picture(asset, cpl_ns)
                self.picture = asset_instance
            elif asset_tag == "MainSound":
                asset_instance = Sound(asset, cpl_ns)
                self.sound = asset_instance
            elif asset_tag == "MainSubtitle":
                asset_instance = Subtitle(asset, cpl_ns)
                self.subtitle = asset_instance
            else:
                raise CPLError("Unknown asset type found: {0}".format(asset_tag))

            # Finally set the path to this particular asset.
            if assetmap is not None:
                asset_instance.path = assetmap[asset_instance.id].path

            # Assets can be accessed in two ways now.
            self.assets[asset_instance.id] = asset_instance
Ejemplo 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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)