def testTwoTags(self): """Places 3 videos on the server: one with two tags: 'tag1' and 'tag2' one with the tag 'tag1' one with the tag 'tag2' the kalutra object with two tags is provided to 'getRelated' we expect to get all three objects back from getRelated """ #MediaEntry1 mediaEntry = KalturaMediaEntry() mediaEntry.setName('rfa.kaltura.GetRelatedTests.testTwoTags1') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(u'tag1 tag2') mediaEntry1 = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry1.getId()) #MediaEntry2 mediaEntry = KalturaMediaEntry() mediaEntry.setName('rfa.kaltura.GetRelatedTests.testTwoTags2') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(u'tag1') mediaEntry2 = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry2.getId()) #MediaEntry3 mediaEntry = KalturaMediaEntry() mediaEntry.setName('rfa.kaltura.GetRelatedTests.testTwoTags3') mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) ulFile = getTestFile('DemoVideo.flv') uploadTokenId = self.client.media.upload(ulFile) mediaEntry.setTags(u'tag2') mediaEntry3 = self.client.media.addFromUploadedFile( mediaEntry, uploadTokenId) self.addCleanup(self.client.media.delete, mediaEntry3.getId()) self.readyWait(mediaEntry1.getId()) self.readyWait(mediaEntry2.getId()) self.readyWait(mediaEntry3.getId()) #do it. results = kutils.getRelated(mediaEntry1) self.assertEqual( 3, len(results), "Did not get expected # of objects back from kutils.getRelated()")
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_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_utf8_name(self): test_unicode = '\u03dd\xf5\xf6' #an odd representation of the word 'FOO' mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_UTF8_name'+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 test_createRemote(self): mediaEntry = KalturaMediaEntry() mediaEntry.setName('pytest.MediaTests.test_createRemote') 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(), str) #cleanup self.client.media.delete(mediaEntry.id)
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 __init__(self, context): self.mediaEntry = KalturaMediaEntry() directlyProvides(self.mediaEntry, IKalturaMediaEntry) self.mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO)) self.mediaEntry.setReferenceId(context.UID()) self.mediaEntry.setName(context.title) #set Description self.mediaEntry.setDescription(context.description) #Set Tags #make a comma delimited string, and pass that in. tags = ','.join([t for t in context.tags if t]) self.mediaEntry.setTags(tags)
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
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_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())
class KalturaVideo(ATBlob, KalturaBase.KalturaContentMixin): """Kaltura Video Content Type - stores the video file on your Kaltura account""" implements(IKalturaVideo, IATBlobFile, IATFile, IFileContent) # CMF FTI setup global_allow = True default_view = 'kvideo_main' #immediate_view = 'generic_preview' # CompositePack setup layout = 'kvideo_main' layouts = ('kvideo_main', ) meta_type = "KalturaVideo" schema = KalturaVideoSchema KalturaObject = None categoryEntries = None security = ClassSecurityInfo() #what this class represents in Kaltura's terms: KalturaMediaType = KalturaMediaType(KalturaMediaType.VIDEO) fieldmap = ( { 'name': 'Title', 'pgetter': 'Title', 'psetter': 'setTitle', 'kgetter': 'getName', 'ksetter': 'setName' }, { 'name': 'Description', 'pgetter': 'Description', 'psetter': 'setDescription', 'kgetter': 'getDescription', 'ksetter': 'setDescription' }, { 'name': 'tags', 'pgetter': 'getKalturaTags', 'psetter': 'setKalturaTags', 'kgetter': 'getTags', 'ksetter': 'setTags' }, #note that categories are not a property of a kalturaObject #see self.updateCategories method ) def __init__(self, oid, **kwargs): super(KalturaVideo, self).__init__(oid, **kwargs) self.KalturaObject = None #holds local list of category entries for this video - matching what's on the KMC. self.categoryEntries = [] self.uploadToken = None #Storage on File field should set this sentry if it uploads a new file to remote. self.fileChanged = False security.declarePublic("getPlaybackUrl") def getPlaybackUrl(self): if self.KalturaObject is not None: return self.KalturaObject.getDataUrl() else: return None playbackUrl = property(getPlaybackUrl) security.declarePrivate('getDefaultPlayerId') def getDefaultPlayerId(self): registry = getUtility(IRegistry) settings = registry.forInterface(IRfaKalturaSettings) return settings.defaultVideoPlayer ### These may get duplicated in base.py - we'll see ### def syncCategories(self, client=None, categories=None): """update the category entries on remote for this object's associated Media Entry categories are stored remotely through the categoryEntry service They are not a property of the Media Entry. """ if categories is None: categories = self.getCategories() newCatEntries = [] if client is None: (client, session) = kconnect() #refresh list of categories from server, and sync to plone object filt = KalturaCategoryEntryFilter() filt.setEntryIdEqual(self.KalturaObject.getId()) self.categoryEntries = client.categoryEntry.list(filt).objects currentSet = set( [catEntry.categoryId for catEntry in self.categoryEntries]) newSet = set([int(catId) for catId in categories]) #determine what categories need to be added addCats = newSet.difference(currentSet) #determine what categories need to be removed delCats = currentSet.difference(newSet) #do adds for catId in addCats: newCatEntry = KalturaCategoryEntry() newCatEntry.setCategoryId(catId) newCatEntry.setEntryId(self.KalturaObject.getId()) try: client.categoryEntry.add(newCatEntry) except KalturaException, e: if e.code == "CATEGORY_ENTRY_ALREADY_EXISTS": pass #should never happen, tho #do removes for catId in delCats: client.categoryEntry.delete(self.KalturaObject.getId(), catId) #sync the categories to plone object self.categoryEntries = client.categoryEntry.list(filt).objects