def createMetadataProfile(self, objectType, xsdData):
        metadataProfile = KalturaMetadataProfile()
        metadataProfile.metadataObjectType = objectType
        metadataProfile.name = self.uniqid('test_')
        metadataProfile.systemName = self.uniqid('test_')

        metadataProfile = self.client.metadata.metadataProfile.add(metadataProfile, xsdData)

        return metadataProfile
Exemple #2
0
    def createMetadataProfile(self, objectType, xsdData):
        metadataProfile = KalturaMetadataProfile()
        metadataProfile.metadataObjectType = objectType
        metadataProfile.name = self.uniqid('test_')
        metadataProfile.systemName = self.uniqid('test_')

        metadataProfile = self.client.metadata.metadataProfile.add(
            metadataProfile, xsdData)

        return metadataProfile
Exemple #3
0
 def test_SampleMetadataOperations(self):
     
     from KalturaClient.Plugins.Metadata import KalturaMetadataProfile
     from KalturaClient.Plugins.Metadata import KalturaMetadataObjectType
     from KalturaClient.Plugins.Metadata import KalturaMetadataProfileFilter
     from KalturaClient.Plugins.Metadata import KalturaMetadataFilter        
     
     # The metadata field we'll add/update
     metaDataFieldName = "SubtitleFormat"
     fieldValue = "VobSub"
 
     # The Schema file for the field
     # Currently, you must build the xsd yourself. There is no utility provided.
     xsdFile = "MetadataSchema.xsd"
 
     # Setup a pager and search to use
     pager = KalturaFilterPager()
     search = KalturaMediaEntryFilter()
     search.setOrderBy(KalturaMediaEntryOrderBy.CREATED_AT_ASC)
     search.setMediaTypeEqual(KalturaMediaType.VIDEO)  # Video only
     pager.setPageSize(10)
     pager.setPageIndex(1)
 
     print "List videos, get the first one..."
 
     # Get 10 video entries, but we'll just use the first one returned
     entries = self.client.media.list(search, pager).objects
 
     # make sure we have a metadata profile
     profile = KalturaMetadataProfile() 
     profile.setName('TestProfile %s' % (testString,))
     MetadataObjectType = KalturaMetadataObjectType.ENTRY
     
     profile.setMetadataObjectType(MetadataObjectType)
     viewsData = ""
 
     xsdFh = getTestFile(xsdFile)
     newProfile = self.client.metadata.metadataProfile.add(profile, xsdFh.read(), viewsData)
 
     # Check if there are any custom fields defined in the KMC (Settings -> Custom Data)
     # for the first item returned by the previous listaction
     filter = KalturaMetadataProfileFilter()
     metadata = self.client.metadata.metadataProfile.list(filter, pager).objects
 
     name = entries[0].getName()
     id = entries[0].getId()
     if metadata[0].getXsd() != None:
         print "1. There are custom fields for video: " + name + ", entryid: " + id
     else:
         print "1. There are no custom fields for video: " + name + ", entryid: " + id
 
     # Add a custom data entry in the KMC  (Settings -> Custom Data)
     profile = KalturaMetadataProfile()
     profile.setName('TestProfile %s' % (testString,))
     profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
     viewsData = ""
 
     metadataResult = self.client.metadata.metadataProfile.update(newProfile.id, profile, xsdFh.read(), viewsData)
 
     assert(metadataResult.xsd != None)
 
     # Add the custom metadata value to the first video
     filter2 = KalturaMetadataFilter()
     filter2.setObjectIdEqual(entries[0].id)
     xmlData = "<metadata><SubtitleFormat>" + fieldValue + "</SubtitleFormat></metadata>"
     metadata2 = self.client.metadata.metadata.add(newProfile.id, profile.metadataObjectType, entries[0].id, xmlData)
 
     assert(metadata2.xml != None)
     
     print "3. Successfully added the custom data field for video: " + name + ", entryid: " + id
     xmlStr = metadata2.xml
     print "XML used: " + xmlStr
 
     # Now lets change the value (update) of the custom field
     # Get the metadata for the video
     filter3 = KalturaMetadataFilter()
     filter3.setObjectIdEqual(entries[0].id)
     filter3.setMetadataProfileIdEqual(newProfile.id)
     metadataList = self.client.metadata.metadata.list(filter3).objects
     assert(metadataList[0].xml != None)
 
     print "4. Current metadata for video: " + name + ", entryid: " + id
     xmlquoted = metadataList[0].xml
     print "XML: " + xmlquoted
     xml = metadataList[0].xml
     # Make sure we find the old value in the current metadata
     pos = xml.find("<" + metaDataFieldName + ">" + fieldValue + "</" + metaDataFieldName + ">")
     assert(pos >= 0)
 
     pattern = re.compile("<" + metaDataFieldName + ">([^<]+)</" + metaDataFieldName + ">")
     xml = pattern.sub("<" + metaDataFieldName + ">Ogg Writ</" + metaDataFieldName + ">", xml)
     rc = self.client.metadata.metadata.update(metadataList[0].id, xml)
     print "5. Updated metadata for video: " + name + ", entryid: " + id
     xmlquoted = rc.xml
     print "XML: " + xmlquoted
    def test_SampleMetadataOperations(self):

        from KalturaClient.Plugins.Metadata import KalturaMetadataProfile
        from KalturaClient.Plugins.Metadata import KalturaMetadataObjectType
        from KalturaClient.Plugins.Metadata import KalturaMetadataProfileFilter
        from KalturaClient.Plugins.Metadata import KalturaMetadataFilter

        # The metadata field we'll add/update
        metaDataFieldName = "SubtitleFormat"
        fieldValue = "VobSub"

        # The Schema file for the field
        # Currently, you must build the xsd yourself. There is no utility provided.
        xsdFile = "MetadataSchema.xsd"

        # Setup a pager and search to use
        pager = KalturaFilterPager()
        search = KalturaMediaEntryFilter()
        search.setOrderBy(KalturaMediaEntryOrderBy.CREATED_AT_ASC)
        search.setMediaTypeEqual(KalturaMediaType.VIDEO)  # Video only
        pager.setPageSize(10)
        pager.setPageIndex(1)

        print "List videos, get the first one..."

        # Get 10 video entries, but we'll just use the first one returned
        entries = self.client.media.list(search, pager).objects

        # make sure we have a metadata profile
        profile = KalturaMetadataProfile()
        profile.setName('TestProfile %s' % (testString, ))
        MetadataObjectType = KalturaMetadataObjectType.ENTRY

        profile.setMetadataObjectType(MetadataObjectType)
        viewsData = ""

        xsdFh = getTestFile(xsdFile)
        newProfile = self.client.metadata.metadataProfile.add(
            profile, xsdFh.read(), viewsData)

        # Check if there are any custom fields defined in the KMC (Settings -> Custom Data)
        # for the first item returned by the previous listaction
        filter = KalturaMetadataProfileFilter()
        metadata = self.client.metadata.metadataProfile.list(filter,
                                                             pager).objects

        name = entries[0].getName()
        id = entries[0].getId()
        if metadata[0].getXsd() != None:
            print "1. There are custom fields for video: " + name + ", entryid: " + id
        else:
            print "1. There are no custom fields for video: " + name + ", entryid: " + id

        # Add a custom data entry in the KMC  (Settings -> Custom Data)
        profile = KalturaMetadataProfile()
        profile.setName('TestProfile %s' % (testString, ))
        profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
        viewsData = ""

        metadataResult = self.client.metadata.metadataProfile.update(
            newProfile.id, profile, xsdFh.read(), viewsData)

        assert (metadataResult.xsd != None)

        # Add the custom metadata value to the first video
        filter2 = KalturaMetadataFilter()
        filter2.setObjectIdEqual(entries[0].id)
        xmlData = "<metadata><SubtitleFormat>" + fieldValue + "</SubtitleFormat></metadata>"
        metadata2 = self.client.metadata.metadata.add(
            newProfile.id, profile.metadataObjectType, entries[0].id, xmlData)

        assert (metadata2.xml != None)

        print "3. Successfully added the custom data field for video: " + name + ", entryid: " + id
        xmlStr = metadata2.xml
        print "XML used: " + xmlStr

        # Now lets change the value (update) of the custom field
        # Get the metadata for the video
        filter3 = KalturaMetadataFilter()
        filter3.setObjectIdEqual(entries[0].id)
        filter3.setMetadataProfileIdEqual(newProfile.id)
        metadataList = self.client.metadata.metadata.list(filter3).objects
        assert (metadataList[0].xml != None)

        print "4. Current metadata for video: " + name + ", entryid: " + id
        xmlquoted = metadataList[0].xml
        print "XML: " + xmlquoted
        xml = metadataList[0].xml
        # Make sure we find the old value in the current metadata
        pos = xml.find("<" + metaDataFieldName + ">" + fieldValue + "</" +
                       metaDataFieldName + ">")
        assert (pos >= 0)

        pattern = re.compile("<" + metaDataFieldName + ">([^<]+)</" +
                             metaDataFieldName + ">")
        xml = pattern.sub(
            "<" + metaDataFieldName + ">Ogg Writ</" + metaDataFieldName + ">",
            xml)
        rc = self.client.metadata.metadata.update(metadataList[0].id, xml)
        print "5. Updated metadata for video: " + name + ", entryid: " + id
        xmlquoted = rc.xml
        print "XML: " + xmlquoted