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_createAncestorCategoryRule(self): 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 {}".format( 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 kupload(FileObject, mediaEntry=None): """Provide an ATCTFileContent based object Upload attached contents to Kaltura Currently Treats all objects as 'videos' - this should change when other kaltura media types are implemented. If MediaEntry is provided, the uploaded video is associated with that media entry """ usingEntitlements = False #this check can be done better if not hasattr(FileObject, 'get_data'): print "nothing to upload to kaltura from object %s" % ( str(FileObject), ) return 1 #XXX Configure Temporary Directory and name better #XXX Turn into a file stream from context.get_data to avoid write to file... tempfh = open('/tmp/tempfile', 'wr') tempfh.write(FileObject.get_data()) tempfh.close() #XXX Not A good idea if we plan on not using the ZODB name = FileObject.Title() ProviderId = FileObject.UID() (client, session) = kconnect() if mediaEntry is None: #create an entry mediaEntry = KalturaMediaEntry() mediaEntry.setName(name) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry.searchProviderId = ProviderId mediaEntry.setReferenceId = ProviderId uploadTokenId = client.media.upload(file('/tmp/tempfile', 'rb')) os.remove('/tmp/tempfile') catIds = mediaEntry.getCategoriesIds() if catIds is not NotImplemented: catIds = catIds.split(',') mediaEntry.setCategoriesIds(NotImplemented) else: catIds = [] mediaEntry = client.media.addFromUploadedFile(mediaEntry, uploadTokenId) KalturaLoggerInstance.log("uploaded. MediaEntry %s" % (mediaEntry.__repr__())) return mediaEntry
def kupload(FileObject, mediaEntry=None): """Provide an ATCTFileContent based object Upload attached contents to Kaltura Currently Treats all objects as 'videos' - this should change when other kaltura media types are implemented. If MediaEntry is provided, the uploaded video is associated with that media entry """ usingEntitlements = False #this check can be done better if not hasattr(FileObject, 'get_data'): print "nothing to upload to kaltura from object %s" % (str(FileObject),) return 1; #XXX Configure Temporary Directory and name better #XXX Turn into a file stream from context.get_data to avoid write to file... tempfh = open('/tmp/tempfile', 'wr') tempfh.write(FileObject.get_data()) tempfh.close() #XXX Not A good idea if we plan on not using the ZODB name = FileObject.Title() ProviderId = FileObject.UID() (client, session) = kconnect() if mediaEntry is None: #create an entry mediaEntry = KalturaMediaEntry() mediaEntry.setName(name) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry.searchProviderId = ProviderId mediaEntry.setReferenceId = ProviderId uploadTokenId = client.media.upload(file('/tmp/tempfile', 'rb')) os.remove('/tmp/tempfile') catIds = mediaEntry.getCategoriesIds() if catIds is not NotImplemented: catIds = catIds.split(',') mediaEntry.setCategoriesIds(NotImplemented) else: catIds = [] mediaEntry = client.media.addFromUploadedFile(mediaEntry, uploadTokenId) KalturaLoggerInstance.log("uploaded. MediaEntry %s" % (mediaEntry.__repr__())) return mediaEntry
def kcreateVideo(context): """given a plone content-type of kalturavideo, create a Kaltura MediaEntry object. The mediaEntry ReferenceId is set to the UID of the plone object to tie them together """ mediaEntry = KalturaMediaEntry() mediaEntry.setName(context.Title()) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry.searchProviderId = context.UID() #XXX Is this correct? We assign this to the file UID stored in plone. #kaltura referenceId == plone UID mediaEntry.setReferenceId(context.UID()) if len(context.getCategories()): mediaEntry.setCategoriesIds(','.join([c for c in context.getCategories() if c])) if len(context.getTags()): mediaEntry.setTags(','.join([t for t in context.getTags() if t])) return mediaEntry
def kcreateVideo(context): """given a plone content-type of kalturavideo, create a video entry on Kaltura The mediaEntry ReferenceId is set to the UID of the plone object to tie them together """ mediaEntry = KalturaMediaEntry() mediaEntry.setName(context.Title()) mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) mediaEntry.searchProviderId = context.UID() #XXX Is this correct? We assign this to the file UID stored in plone. #kaltura referenceId == plone UID mediaEntry.setReferenceId(context.UID()) if len(context.getCategories()): mediaEntry.setCategoriesIds(','.join([c for c in context.getCategories() if c])) if len(context.getTags()): mediaEntry.setTags(','.join([t for t in context.getTags() if t])) return mediaEntry