def kcreatePlaylist(context): """Create an empty playlist on the kaltura server""" kplaylist = KalturaPlaylist() kplaylist.setName(context.Title()) kplaylist.setDescription(context.Description()) kplaylist.setReferenceId(context.UID()) if IKalturaManualPlaylist.providedBy(context): kplaylist.setPlaylistType(KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) elif IKalturaRuleBasedPlaylist.providedBy(context): kplaylist.setPlaylistType(KalturaPlaylistType(KalturaPlaylistType.DYNAMIC)) maxVideos = getattr(context, 'maxVideos', DEFAULT_DYNAMIC_PLAYLIST_SIZE) kplaylist.setTotalResults(maxVideos) kfilter = kcreateEmptyFilterForPlaylist() kfilter.setFreeText(u','.join(context.getTags())) kfilter.setCategoriesIdsMatchOr(u','.join(context.getCategories())) kplaylist.setFilters([kfilter]) else: raise AssertionError, "%s is not a known playlist type" % (context.portal_type,) (client, session) = kconnect() kplaylist = client.playlist.add(kplaylist) return kplaylist
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_createRemote(self): kplaylist = KalturaPlaylist() kplaylist.setName('pytest.PlaylistTests.test_createRemote') kplaylist.setPlaylistType( KalturaPlaylistType( KalturaPlaylistType.STATIC_LIST)) #??? STATIC LIST ??? kplaylist = self.client.playlist.add(kplaylist) self.assertIsInstance(kplaylist, KalturaPlaylist) self.assertIsInstance(kplaylist.getId(), unicode) #cleanup self.client.playlist.delete(kplaylist.getId())
def test_createRemote(self): kplaylist = KalturaPlaylist() kplaylist.setName('pytest.PlaylistTests.test_createRemote') kplaylist.setPlaylistType( KalturaPlaylistType(KalturaPlaylistType.DYNAMIC)) #must add a totalResults field kplaylist.setTotalResults(10) kplaylist = self.client.playlist.add(kplaylist) self.assertIsInstance(kplaylist, KalturaPlaylist) self.assertIsInstance(kplaylist.getId(), unicode) #cleanup self.client.playlist.delete(kplaylist.getId())
def test_updateExceptionReferenceIdNotSet(self): kplaylist = KalturaPlaylist() kplaylist.setName( 'pytest.PlaylistTests.test_updateExceptionReferenceIdNotSet') kplaylist.setPlaylistType( KalturaPlaylistType(KalturaPlaylistType.STATIC_LIST)) kplaylist = self.client.playlist.add(kplaylist) self.addCleanup(self.client.playlist.delete, kplaylist.getId()) playlistId = kplaylist.getId() playlist = self.client.playlist.get(playlistId) # don't set referenceId self.assertRaises(KalturaException, self.client.playlist.update, playlistId, playlist)
def test_update(self): referenceId = 'pytest.PlaylistTests.test_update' 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()) newPlaylist = KalturaPlaylist() newPlaylist.setReferenceId(referenceId) newPlaylist.setName("changed!") self.client.playlist.update(kplaylist.getId(), newPlaylist) resultPlaylist = self.client.playlist.get(kplaylist.getId()) self.assertEqual("changed!", resultPlaylist.getName())
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_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())