Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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