def unset(self, name, instance, **kwargs): (client, ks) = kconnect() mediaEntry = instance.KalturaObject try: client.media.delete(mediaEntry.getId) except: #XXX ENTRY_ID_NOT_FOUND exception, specifically pass AnnotationStorage.unset(self, name, instance, **kwargs)
def createRemote(self, client=None): """Create a new media entry on the remote server return the mediaEntry returned from the server """ mediaEntry = self._createKobj() if client is None: (client, session) = kconnect() mediaEntry = client.media.addFromUploadedFile(mediaEntry, self.uploadToken.getId()) self.setKalturaObject(mediaEntry) self.fileChanged = False self.syncCategories(client)
def syncMetadata(self, client=None): """sync up remote Kaltura Server with data in plone Note that we construct an entire MediaEntry with all metadata""" newMediaEntry = self._createKobj() if client is None: (client, session) = kconnect() mediaEntry = client.media.update(self.entryId, newMediaEntry) self.setKalturaObject(mediaEntry) self.syncCategories(client) #Makes method name 'syncMetadata' a misnomer, we sync the file too if changed. if self.fileChanged: #video exists on remote, but replace media content - File. self.replaceFileOnRemote(client) self.fileChanged = False
def syncMetadata(self, client=None): """sync up remote Kaltura Server with data in plone Note that we construct an entire MediaEntry with all metadata""" newMediaEntry = self._createKobj() if client is None: (client, session) = kconnect() mediaEntry = client.media.update(self.entryId, newMediaEntry) self.setKalturaObject(mediaEntry) self.syncCategories(client) # Makes method name 'syncMetadata' a misnomer, we sync the file too if changed. if self.fileChanged: # video exists on remote, but replace media content - File. self.replaceFileOnRemote(client) self.fileChanged = False
def _updateRemote(self, **kwargs): """will set the specified attribute on the matching object in Kaltura Try not to modify self.KalturaObject directly -use this method instead to keep things in sync with the remote server. For example, to update the name of the kaltura video: self._updateRemote(name='NewName') """ (client, session) = kconnect() newVideo = API_KalturaMediaEntry() for (attr, value) in kwargs.iteritems(): setter = getattr(newVideo, 'set'+attr) setter(value) result = client.media.update(self.getEntryId(), newVideo) self.setKalturaObject(result)
def _updateRemote(self, **kwargs): """will set the specified attribute on the matching object in Kaltura Try not to modify self.KalturaObject directly -use this method instead to keep things in sync. For example, to update the name of the kaltura playlist: self._updateRemote(name='NewName') """ (client, session) = kconnect() newPlaylist = API_KalturaPlaylist() for (attr, value) in kwargs.iteritems(): setter = getattr(newPlaylist, 'set' + attr) setter(value) resultPlaylist = client.playlist.update(self.getEntryId(), newPlaylist) self.setKalturaObject(resultPlaylist)
def _updateRemote(self, **kwargs): """will set the specified attribute on the matching object in Kaltura Try not to modify self.KalturaObject directly -use this method instead to keep things in sync. For example, to update the name of the kaltura playlist: self._updateRemote(name='NewName') """ (client, session) = kconnect() newPlaylist = API_KalturaPlaylist() for (attr, value) in kwargs.iteritems(): setter = getattr(newPlaylist, 'set'+attr) setter(value) resultPlaylist = client.playlist.update(self.getEntryId(), newPlaylist) self.setKalturaObject(resultPlaylist)
def set(self, name, instance, value, **kwargs): """Store video on Kaltura, create media entry if required """ initializing = kwargs.get('_initializing_', False) if initializing: AnnotationStorage.set(self, name, instance, value, **kwargs) return self.value = aq_base(value) if self.value.filename is None: return #only interested in running set when instance is ready to save. #get a filehandle for the video content we are uploading to Kaltura Server fh_blob = openBlob(self.value.blob, mode='r') #find the temp dir that ZODB is using. tempdir = os.path.dirname(fh_blob.name) #connect to Kaltura Server (client, ks) = kconnect() #upload video content. token = KalturaUploadToken() token = client.uploadToken.add(token) token = client.uploadToken.upload(token.getId(), fh_blob) fh_blob.close() #instance needs to know the upload token to finalize the media entry # typically, a call to Kaltura's addFromUploadedFile or updateContent services does this. instance.uploadToken = token instance.fileChanged = True #if "no local storage" is set, we clobber the blob file. registry = getUtility(IRegistry) settings = registry.forInterface(IRfaKalturaSettings) if settings.storageMethod == u"No Local Storage": filename_aside = self.makeDummyData(dir=tempdir) value.blob.consumeFile(filename_aside) AnnotationStorage.set(self, name, instance, value, **kwargs)
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
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