def test_updateContent(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_updateContent') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) self.readyWait(mediaEntry.getId()) #now, change the content on the mediaEntry to another video file token = KalturaUploadToken() token = self.client.uploadToken.add(token) self.addCleanup(self.client.uploadToken.delete, token.getId()) ulFile = getTestFile('countdown.mp4') token = self.client.uploadToken.upload(token.getId(), ulFile) #create a resource resource = KalturaUploadedFileTokenResource() resource.setToken(token.getId()) #DO THE TEST newMediaEntry = self.client.media.updateContent(mediaEntry.getId(), resource) #must approve it... newMediaEntry = self.client.media.approveReplace(newMediaEntry.getId()) self.readyWait(newMediaEntry.getId()) #make sure everything but content is the same self.assertEqual(mediaEntry.getId(), newMediaEntry.getId()) self.assertEqual(mediaEntry.getName(), newMediaEntry.getName()) self.assertNotEqual(mediaEntry.getDuration(), newMediaEntry.getDuration())
def test_createAncestorCategoryRule(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType from KalturaClient.Plugins.Core import KalturaPlaylistFilter from KalturaClient.Plugins.Core import KalturaCategory referenceId = 'pytest.DynamicPlaylistTests.test_createAncestorCategoryRule' #create category entry hierarchy topCategory = KalturaCategory() topCategory.setName("TopCategory") topCategory = self.client.category.add(topCategory) self.addCleanup(self.client.category.delete, topCategory.getId()) subCategory = KalturaCategory() subCategory.setName("SubCategory") subCategory.setParentId(topCategory.getId()) subCategory = self.client.category.add(subCategory) self.addCleanup(self.client.category.delete, subCategory.getId()) #create a video, and assign it to subCategory. mediaEntry = KalturaMediaEntry() mediaEntry.setName(referenceId) mediaEntry.setReferenceId(referenceId) mediaEntry.setCategoriesIds(subCategory.getId()) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) #create a playlist kplaylist = KalturaPlaylist() kplaylist.setName(referenceId) kplaylist.setPlaylistType( KalturaPlaylistType(KalturaPlaylistType.DYNAMIC)) kplaylist.setTotalResults(10) kplaylist.setReferenceId(referenceId) #Create A Filter - use Top Level Category kFilter = KalturaPlaylistFilter() kFilter.setCategoryAncestorIdIn(topCategory.getId()) kplaylist.setFilters([kFilter]) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) print "Waiting for Media Entry to be 'Ready'" sleeptime = 5 mediaEntry = self.client.media.get(mediaEntry.getId()) while mediaEntry.getStatus().getValue() != '2': print "media entry status is %s " % ( mediaEntry.getStatus().getValue()) time.sleep(sleeptime) mediaEntry = self.client.media.get(mediaEntry.getId()) results = self.client.playlist.execute(kplaylist.getId(), kplaylist) self.assertEqual(len(results), 1) self.assertEqual(results[0].getName(), referenceId)
def test_list_utf8_search(self): """Get a list of videos based on a tag search containing unicode""" mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_UTF8_tags') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(self.test_unicode) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) self.readyWait(mediaEntry.getId()) #find it! kfilter = KalturaMediaEntryFilter() kfilter.setTagsLike(self.test_unicode) result = self.client.media.list(filter=kfilter) self.assertEqual( 1, len(result.objects), msg="Did not get expected number of objects back from result") mediaResult = result.objects[0] self.assertEqual(mediaEntry.getId(), mediaResult.getId(), msg="Did not get expected media object from result")
def test_Upload(self): token = KalturaUploadToken() token = self.client.uploadToken.add(token) self.assertIsInstance(token, KalturaUploadToken) self.addCleanup(self.client.uploadToken.delete, token.getId()) ulFile = getTestFile('DemoVideo.flv') resp = self.client.uploadToken.upload(token.getId(), ulFile) self.assertIsInstance(resp, KalturaUploadToken)
def test_createAncestorCategoryRule(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType from KalturaClient.Plugins.Core import KalturaPlaylistFilter from KalturaClient.Plugins.Core import KalturaCategory referenceId = 'pytest.DynamicPlaylistTests.test_createAncestorCategoryRule' #create category entry hierarchy topCategory = KalturaCategory() topCategory.setName('TopCategory_' + str(time.time())) topCategory = self.client.category.add(topCategory) self.addCleanup(self.client.category.delete, topCategory.getId()) subCategory = KalturaCategory() subCategory.setName("SubCategory" + str(time.time())) subCategory.setParentId(topCategory.getId()) subCategory = self.client.category.add(subCategory) self.addCleanup(self.client.category.delete, subCategory.getId()) #create a video, and assign it to subCategory. mediaEntry = KalturaMediaEntry() mediaEntry.setName(referenceId) mediaEntry.setReferenceId(referenceId) mediaEntry.setCategoriesIds(subCategory.getId()) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) #create a playlist kplaylist = KalturaPlaylist() kplaylist.setName(referenceId) kplaylist.setPlaylistType(KalturaPlaylistType(KalturaPlaylistType.DYNAMIC)) kplaylist.setTotalResults(10) kplaylist.setReferenceId(referenceId) #Create A Filter - use Top Level Category kFilter = KalturaPlaylistFilter() kFilter.setCategoryAncestorIdIn(topCategory.getId()) kplaylist.setFilters([kFilter]) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) print "Waiting for Media Entry to be 'Ready'" sleeptime=5 mediaEntry = self.client.media.get(mediaEntry.getId()) while mediaEntry.getStatus().getValue() != '2': print "media entry status is %s " % (mediaEntry.getStatus().getValue()) time.sleep(sleeptime) mediaEntry = self.client.media.get(mediaEntry.getId()) results = self.client.playlist.execute(kplaylist.getId(), kplaylist) self.assertEqual(len(results), 1) self.assertEqual(results[0].getName(), referenceId)
def test_utf8_name(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName(u'pytest.MediaTests.test_UTF8_name'+self.test_unicode) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) #this will throw an exception if fail. mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId())
def test_updateStaticContent(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType mediaEntry1 = KalturaMediaEntry() mediaEntry1.setName('pytest.PlaylistTests.test_updateStaticContent1') mediaEntry1.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry1 = self.client.media.addFromUploadedFile( mediaEntry1, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry1.getId()) mediaEntry2 = KalturaMediaEntry() mediaEntry2.setName('pytest.PlaylistTests.test_updateStaticContent2') mediaEntry2.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry2 = self.client.media.addFromUploadedFile( mediaEntry2, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry2.getId()) #playlistContent is simply a comma separated string of id's ? playlistContent = u','.join([mediaEntry1.getId(), mediaEntry2.getId()]) kplaylist = KalturaPlaylist() kplaylist.setName('pytest.PlaylistTests.test_updateStaticContent') kplaylist.setPlaylistType( KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) kplaylist.setPlaylistContent(playlistContent) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) #fetch the playlist from server and test it's content. resultPlaylist = self.client.playlist.get(kplaylist.getId()) self.assertEqual(resultPlaylist.playlistContent, playlistContent)
def test_utf8_name(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName(u'pytest.MediaTests.test_UTF8_name' + self.test_unicode) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) #this will throw an exception if fail. mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId())
def _AdvancedMultiRequestExample(self): #this is a separate, local client - not 'self.client' client = KalturaClient( self.config) #matches line 154 in PythonTester.py client.startMultiRequest() from KalturaClient.Plugins.Core import KalturaMixEntry from KalturaClient.Plugins.Core import KalturaEditorType # Request 1 ks = client.session.start(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "") client.setKs( ks ) # for the current multi request, the result of the first call will be used as the ks for next calls mixEntry = KalturaMixEntry() mixEntry.setName(".Net Mix %s" % (testString, )) mixEntry.setEditorType(KalturaEditorType.SIMPLE) # Request 2 mixEntry = client.mixing.add(mixEntry) # Request 3 ulFile = getTestFile('DemoVideo.flv') uploadTokenId = client.media.upload(ulFile) mediaEntry = KalturaMediaEntry() mediaEntry.setName("Media Entry For Mix %s" % (testString, )) mediaEntry.setMediaType(KalturaMediaType.VIDEO) # Request 4 mediaEntry = client.media.addFromUploadedFile(mediaEntry, uploadTokenId) # Request 5 client.mixing.appendMediaEntry(mixEntry.id, mediaEntry.id) response = client.doMultiRequest() for subResponse in response: if isinstance(subResponse, KalturaException): self.fail("Error occurred: " + subResponse.message) # when accessing the response object we will use an index and not the response number (response number - 1) assert (isinstance(response[1], KalturaMixEntry)) mixEntry = response[1] print "The new mix entry id is: " + mixEntry.id
def test_addFromUploadedFile(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_addFromUploadedFile') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.assertIsInstance(mediaEntry.getId(), unicode) #cleanup self.client.media.delete(mediaEntry.id)
def test_updateStaticContent(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType mediaEntry1 = KalturaMediaEntry() mediaEntry1.setName('pytest.PlaylistTests.test_updateStaticContent1') mediaEntry1.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry1 = self.client.media.addFromUploadedFile(mediaEntry1, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry1.getId()) mediaEntry2 = KalturaMediaEntry() mediaEntry2.setName('pytest.PlaylistTests.test_updateStaticContent2') mediaEntry2.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry2 = self.client.media.addFromUploadedFile(mediaEntry2, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry2.getId()) #playlistContent is simply a comma separated string of id's ? playlistContent = u','.join([mediaEntry1.getId(), mediaEntry2.getId()]) kplaylist = KalturaPlaylist() kplaylist.setName('pytest.PlaylistTests.test_updateStaticContent') kplaylist.setPlaylistType(KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) kplaylist.setPlaylistContent(playlistContent) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) #fetch the playlist from server and test it's content. resultPlaylist = self.client.playlist.get(kplaylist.getId()) self.assertEqual(resultPlaylist.playlistContent, playlistContent)
def test_updateContent(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_updateContent') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) self.readyWait(mediaEntry.getId()) #now, change the content on the mediaEntry to another video file token = KalturaUploadToken() token = self.client.uploadToken.add(token) self.addCleanup(self.client.uploadToken.delete, token.getId()) ulFile = getTestFile('countdown.mp4') token = self.client.uploadToken.upload(token.getId(), ulFile) #create a resource resource = KalturaUploadedFileTokenResource() resource.setToken(token.getId()) #DO THE TEST newMediaEntry = self.client.media.updateContent( mediaEntry.getId(), resource) #must approve it... newMediaEntry = self.client.media.approveReplace(newMediaEntry.getId()) self.readyWait(newMediaEntry.getId()) #make sure everything but content is the same self.assertEqual(mediaEntry.getId(), newMediaEntry.getId()) self.assertEqual(mediaEntry.getName(), newMediaEntry.getName()) self.assertNotEqual(mediaEntry.getDuration(), newMediaEntry.getDuration())
def test_addFromUploadedFile(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_addFromUploadedFile') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.assertIsInstance(mediaEntry.getId(), unicode) #cleanup self.client.media.delete(mediaEntry.id)
def test_utf8_tags(self): test_unicode = u'\u03dd\xf5\xf6' #an odd representation of the word 'FOO' mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_UTF8_tags') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(test_unicode) #this will throw an exception if fail. mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId())
def test_utf8_tags(self): test_unicode = u'\u03dd\xf5\xf6' #an odd representation of the word 'FOO' mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_UTF8_tags') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(test_unicode) #this will throw an exception if fail. mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId())
def _AdvancedMultiRequestExample(self): #this is a separate, local client - not 'self.client' client = KalturaClient(self.config) #matches line 154 in PythonTester.py client.startMultiRequest() from KalturaClient.Plugins.Core import KalturaMixEntry from KalturaClient.Plugins.Core import KalturaEditorType # Request 1 ks = client.session.start(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "") client.setKs(ks) # for the current multi request, the result of the first call will be used as the ks for next calls mixEntry = KalturaMixEntry() mixEntry.setName(".Net Mix %s" % (testString,)) mixEntry.setEditorType(KalturaEditorType.SIMPLE) # Request 2 mixEntry = client.mixing.add(mixEntry) # Request 3 ulFile = getTestFile('DemoVideo.flv') uploadTokenId = client.media.upload(ulFile) mediaEntry = KalturaMediaEntry() mediaEntry.setName("Media Entry For Mix %s" % (testString,)) mediaEntry.setMediaType(KalturaMediaType.VIDEO) # Request 4 mediaEntry = client.media.addFromUploadedFile(mediaEntry, uploadTokenId) # Request 5 client.mixing.appendMediaEntry(mixEntry.id, mediaEntry.id) response = client.doMultiRequest() for subResponse in response: if isinstance(subResponse, KalturaException): self.fail("Error occurred: " + subResponse.message) # when accessing the response object we will use an index and not the response number (response number - 1) assert(isinstance(response[1], KalturaMixEntry)) mixEntry = response[1] print "The new mix entry id is: " + mixEntry.id
def test_addmedia(self): ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = KalturaMediaEntry() mediaEntry.setName("Media Entry Using Python Client ver %s" % (API_VERSION,)) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) # serve DATA_ENTRY_CONTENT = 'bla bla bla' dataEntry = KalturaDataEntry() dataEntry.setName('test data entry') dataEntry.setDataContent(DATA_ENTRY_CONTENT) addedDataEntry = self.client.data.add(dataEntry) serveUrl = self.client.data.serve(addedDataEntry.id) f = urllib.urlopen(serveUrl) assert(DATA_ENTRY_CONTENT == f.read())
def test_addmedia(self): ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = KalturaMediaEntry() mediaEntry.setName("Media Entry Using Python Client ver %s" % (API_VERSION, )) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) # serve DATA_ENTRY_CONTENT = 'bla bla bla' dataEntry = KalturaDataEntry() dataEntry.setName('test data entry') dataEntry.setDataContent(DATA_ENTRY_CONTENT) addedDataEntry = self.client.data.add(dataEntry) serveUrl = self.client.data.serve(addedDataEntry.id) f = urllib.urlopen(serveUrl) assert (DATA_ENTRY_CONTENT == f.read())
def test_addStaticToExistingEmpty(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType referenceId = 'pytest.PlaylistTests.test_addStaticToExistingEmpty' #create empty playlist on server kplaylist = KalturaPlaylist() kplaylist.setName(referenceId) kplaylist.setReferenceId(referenceId) kplaylist.setPlaylistType( KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) playlistId = kplaylist.getId() #now, add some media mediaEntry = KalturaMediaEntry() mediaEntry.setName(referenceId) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) #add to (update) existing playlist newplaylist = KalturaPlaylist() newplaylist.setReferenceId(referenceId) playlistContent = u','.join([mediaEntry.getId()]) newplaylist.setPlaylistContent(playlistContent) self.client.playlist.update(playlistId, newplaylist) #check it. resultPlaylist = self.client.playlist.get(playlistId) self.assertEqual(playlistContent, resultPlaylist.getPlaylistContent())
def test_addStaticToExistingEmpty(self): from KalturaClient.Plugins.Core import KalturaMediaEntry, KalturaMediaType referenceId = 'pytest.PlaylistTests.test_addStaticToExistingEmpty' #create empty playlist on server kplaylist = KalturaPlaylist() kplaylist.setName(referenceId) kplaylist.setReferenceId(referenceId) kplaylist.setPlaylistType(KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) playlistId = kplaylist.getId() #now, add some media mediaEntry = KalturaMediaEntry() mediaEntry.setName(referenceId) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) #add to (update) existing playlist newplaylist = KalturaPlaylist() newplaylist.setReferenceId(referenceId) playlistContent = u','.join([mediaEntry.getId()]) newplaylist.setPlaylistContent(playlistContent) self.client.playlist.update(playlistId, newplaylist) #check it. resultPlaylist = self.client.playlist.get(playlistId) self.assertEqual(playlistContent, resultPlaylist.getPlaylistContent())
def test_list_utf8_search(self): """Get a list of videos based on a tag search containing unicode""" mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_UTF8_tags') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(self.test_unicode) mediaEntry = self.client.media.addFromUploadedFile(mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry.getId()) self.readyWait(mediaEntry.getId()) #find it! kfilter = KalturaMediaEntryFilter() kfilter.setTagsLike(self.test_unicode) result = self.client.media.list(filter=kfilter) self.assertEqual(1, len(result.objects), msg="Did not get expected number of objects back from result") mediaResult = result.objects[0] self.assertEqual(mediaEntry.getId(), mediaResult.getId(), msg="Did not get expected media object from result")
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