예제 #1
0
def kconnect(partner_id=None):
    
    creds = getCredentials()
    if partner_id is not None:
        creds['PARTNER_ID'] = partner_id
    
    privacyString = ''    

    #may want to add 'disableentitlements' to the privacyString eventuall for users who want to
    # disable all entitlement checking
    if creds.get('PRIVACY_CONTEXT', '') not in ('', None):
        privacyString = 'privacycontext:' + creds['PRIVACY_CONTEXT']
        
    
    config = KalturaConfiguration(creds['PARTNER_ID'])
    config.serviceUrl = creds['SERVICE_URL']
    config.setLogger(KalturaLoggerInstance)
        
    client = KalturaClient(config)
    
    # start new session
    ks = client.generateSession(creds['ADMIN_SECRET'], 
                                creds['USER_NAME'],
                                KalturaSessionType.ADMIN, 
                                creds['PARTNER_ID'],
                                86400,
                                privacyString)
    client.setKs(ks)    
    
    return (client, ks)
예제 #2
0
def GetKS():
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    client = KalturaClient(config)
    return client.generateSession(secrets['admin_secret'], secrets['username'],
                                  KalturaSessionType.ADMIN,
                                  secrets['partner_id'], 86400, "")
예제 #3
0
def GetKS():
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    client = KalturaClient(config)
    return client.generateSession(secrets['admin_secret'],
                                  secrets['username'],
                                  KalturaSessionType.ADMIN,
                                  secrets['partner_id'],
                                  86400, "")
예제 #4
0
파일: kaltura.py 프로젝트: 9ae/djv
def get_ks():
    """Start new Kaltura API session and return key"""
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    #config.setLogger(logger)
    client = KalturaClient(config)
    return client.generateSession(secrets['admin_secret'], secrets['username'],
                                  KalturaSessionType.ADMIN,
                                  secrets['partner_id'], 86400, '')
예제 #5
0
파일: kaltura.py 프로젝트: algobunny/djv
def get_ks():
    """Start new Kaltura API session and return key"""
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    #config.setLogger(logger)
    client = KalturaClient(config)
    return client.generateSession(secrets['admin_secret'],
                                  secrets['username'],
                                  KalturaSessionType.ADMIN,
                                  secrets['partner_id'],
                                  86400,
                                  '')
예제 #6
0
def SampleMetadataOperations():
    # The metadata field we'll add/update
    metaDataFieldName = "SubtitleFormat"
    fieldValue = "VobSub"

    # The Schema file for the field
    # Currently, you must build the xsd yourself. There is no utility provided.
    xsdFile = "MetadataSchema.xsd"

    client = KalturaClient(GetConfig())

    # start new session (client session is enough when we do operations in a users scope)
    ks = client.generateSession(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "")
    client.setKs(ks)

    # Setup a pager and search to use
    pager = KalturaFilterPager()
    search = KalturaMediaEntryFilter()
    search.setOrderBy(KalturaMediaEntryOrderBy.CREATED_AT_ASC)
    search.setMediaTypeEqual(KalturaMediaType.VIDEO)  # Video only
    pager.setPageSize(10)
    pager.setPageIndex(1)

    print "List videos, get the first one..."

    # Get 10 video entries, but we'll just use the first one returned
    entries = client.media.list(search, pager).objects

    # make sure we have a metadata profile
    profile = KalturaMetadataProfile()
    profile.setName('TestProfile')
    profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
    viewsData = ""

    newProfile = client.metadata.metadataProfile.add(profile, file(xsdFile, 'rb').read(), viewsData)

    # Check if there are any custom fields defined in the KMC (Settings -> Custom Data)
    # for the first item returned by the previous listaction
    filter = KalturaMetadataProfileFilter()
    metadata = client.metadata.metadataProfile.list(filter, pager).objects

    name = entries[0].getName()
    id = entries[0].getId()
    if metadata[0].getXsd() != None:
        print "1. There are custom fields for video: " + name + ", entryid: " + id
    else:
        print "1. There are no custom fields for video: " + name + ", entryid: " + id

    # Add a custom data entry in the KMC  (Settings -> Custom Data)
    profile = KalturaMetadataProfile()
    profile.setName('TestProfile')
    profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
    viewsData = ""

    metadataResult = client.metadata.metadataProfile.update(newProfile.id, profile, file(xsdFile, 'rb').read(), viewsData)

    assert(metadataResult.xsd != None)

    # Add the custom metadata value to the first video
    filter2 = KalturaMetadataFilter()
    filter2.setObjectIdEqual(entries[0].id)
    xmlData = "<metadata><SubtitleFormat>" + fieldValue + "</SubtitleFormat></metadata>"
    metadata2 = client.metadata.metadata.add(newProfile.id, profile.metadataObjectType, entries[0].id, xmlData)

    assert(metadata2.xml != None)
    
    print "3. Successfully added the custom data field for video: " + name + ", entryid: " + id
    xmlStr = metadata2.xml
    print "XML used: " + xmlStr

    # Now lets change the value (update) of the custom field
    # Get the metadata for the video
    filter3 = KalturaMetadataFilter()
    filter3.setObjectIdEqual(entries[0].id)
    filter3.setMetadataProfileIdEqual(newProfile.id)
    metadataList = client.metadata.metadata.list(filter3).objects
    assert(metadataList[0].xml != None)

    print "4. Current metadata for video: " + name + ", entryid: " + id
    xmlquoted = metadataList[0].xml
    print "XML: " + xmlquoted
    xml = metadataList[0].xml
    # Make sure we find the old value in the current metadata
    pos = xml.find("<" + metaDataFieldName + ">" + fieldValue + "</" + metaDataFieldName + ">")
    assert(pos >= 0)

    pattern = re.compile("<" + metaDataFieldName + ">([^<]+)</" + metaDataFieldName + ">")
    xml = pattern.sub("<" + metaDataFieldName + ">Ogg Writ</" + metaDataFieldName + ">", xml)
    rc = client.metadata.metadata.update(metadataList[0].id, xml)
    print "5. Updated metadata for video: " + name + ", entryid: " + id
    xmlquoted = rc.xml
    print "XML: " + xmlquoted
예제 #7
0
    response = client.doMultiRequest()

    for subResponse in response:
        if isinstance(subResponse, KalturaException):
            print "Error occurred: " + subResponse.message

    # when accessing the response object we will use an index and not the response number (response number - 1)
    assert(isinstance(response[1], KalturaMixEntry))
    mixEntry = response[1]
    
    print "The new mix entry id is: " + mixEntry.id

# create session
client = KalturaClient(GetConfig())

ks = client.generateSession(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "")
client.setKs(ks)

# add media
uploadTokenId = client.media.upload(file('DemoVideo.flv', 'rb'))

mediaEntry = KalturaMediaEntry()
mediaEntry.setName("Media Entry Using Python Client")
mediaEntry.setMediaType(KalturaMediaType(KalturaMediaType.VIDEO))
mediaEntry = client.media.addFromUploadedFile(mediaEntry, uploadTokenId)

# serve
DATA_ENTRY_CONTENT = 'bla bla bla'
dataEntry = KalturaDataEntry()
dataEntry.setName('test data entry')
dataEntry.setDataContent(DATA_ENTRY_CONTENT)
        raise Exception('not enough room to create padding atom')
    return StringReader(inputData[:atomPos] + struct.pack('>L', atomHeaderSize + newSize) + inputData[(atomPos + 4):newAtomEndPos] +
        struct.pack('>L', atomEndPos - newAtomEndPos) + 'padd' + inputData[(newAtomEndPos + 8):])

# download and read the input file
if not os.path.exists(TEMP_DOWNLOAD_PATH):
    http_utils.downloadUrl(TEST_FLAVOR_URL, TEMP_DOWNLOAD_PATH)

inputData = file(TEMP_DOWNLOAD_PATH, 'rb').read()

inputAtoms = parseAtoms(inputData, 0, len(inputData), '')

# initialize the api client
client = KalturaClient(GetConfig())

ks = client.generateSession(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "")
client.setKs(ks)

# get source only conversion profile
sourceOnlyConvProfileId = None
for conversionProfile in client.conversionProfile.list().objects:
    if conversionProfile.name.lower() == 'source only':
        sourceOnlyConvProfileId = conversionProfile.id

if sourceOnlyConvProfileId == None:
    print('Failed to find a source only conversion profile')
    sys.exit(1)

def getTimeScaleOffset():
    return getAtomDataPos('moov.trak.mdia.mdhd') + 12
def SampleMetadataOperations():
    # The metadata field we'll add/update
    metaDataFieldName = "SubtitleFormat"
    fieldValue = "VobSub"

    # The Schema file for the field
    # Currently, you must build the xsd yourself. There is no utility provided.
    xsdFile = "MetadataSchema.xsd"

    client = KalturaClient(GetConfig())

    # start new session (client session is enough when we do operations in a users scope)
    ks = client.generateSession(ADMIN_SECRET, USER_NAME,
                                KalturaSessionType.ADMIN, PARTNER_ID, 86400,
                                "")
    client.setKs(ks)

    # Setup a pager and search to use
    pager = KalturaFilterPager()
    search = KalturaMediaEntryFilter()
    search.setOrderBy(KalturaMediaEntryOrderBy.CREATED_AT_ASC)
    search.setMediaTypeEqual(KalturaMediaType.VIDEO)  # Video only
    pager.setPageSize(10)
    pager.setPageIndex(1)

    print "List videos, get the first one..."

    # Get 10 video entries, but we'll just use the first one returned
    entries = client.media.list(search, pager).objects

    # make sure we have a metadata profile
    profile = KalturaMetadataProfile()
    profile.setName('TestProfile')
    profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
    viewsData = ""

    newProfile = client.metadata.metadataProfile.add(
        profile,
        file(xsdFile, 'rb').read(), viewsData)

    # Check if there are any custom fields defined in the KMC (Settings -> Custom Data)
    # for the first item returned by the previous listaction
    filter = KalturaMetadataProfileFilter()
    metadata = client.metadata.metadataProfile.list(filter, pager).objects

    name = entries[0].getName()
    id = entries[0].getId()
    if metadata[0].getXsd() != None:
        print "1. There are custom fields for video: " + name + ", entryid: " + id
    else:
        print "1. There are no custom fields for video: " + name + ", entryid: " + id

    # Add a custom data entry in the KMC  (Settings -> Custom Data)
    profile = KalturaMetadataProfile()
    profile.setName('TestProfile')
    profile.setMetadataObjectType(KalturaMetadataObjectType.ENTRY)
    viewsData = ""

    metadataResult = client.metadata.metadataProfile.update(
        newProfile.id, profile,
        file(xsdFile, 'rb').read(), viewsData)

    assert (metadataResult.xsd != None)

    # Add the custom metadata value to the first video
    filter2 = KalturaMetadataFilter()
    filter2.setObjectIdEqual(entries[0].id)
    xmlData = "<metadata><SubtitleFormat>" + fieldValue + "</SubtitleFormat></metadata>"
    metadata2 = client.metadata.metadata.add(newProfile.id,
                                             profile.metadataObjectType,
                                             entries[0].id, xmlData)

    assert (metadata2.xml != None)

    print "3. Successfully added the custom data field for video: " + name + ", entryid: " + id
    xmlStr = metadata2.xml
    print "XML used: " + xmlStr

    # Now lets change the value (update) of the custom field
    # Get the metadata for the video
    filter3 = KalturaMetadataFilter()
    filter3.setObjectIdEqual(entries[0].id)
    filter3.setMetadataProfileIdEqual(newProfile.id)
    metadataList = client.metadata.metadata.list(filter3).objects
    assert (metadataList[0].xml != None)

    print "4. Current metadata for video: " + name + ", entryid: " + id
    xmlquoted = metadataList[0].xml
    print "XML: " + xmlquoted
    xml = metadataList[0].xml
    # Make sure we find the old value in the current metadata
    pos = xml.find("<" + metaDataFieldName + ">" + fieldValue + "</" +
                   metaDataFieldName + ">")
    assert (pos >= 0)

    pattern = re.compile("<" + metaDataFieldName + ">([^<]+)</" +
                         metaDataFieldName + ">")
    xml = pattern.sub(
        "<" + metaDataFieldName + ">Ogg Writ</" + metaDataFieldName + ">", xml)
    rc = client.metadata.metadata.update(metadataList[0].id, xml)
    print "5. Updated metadata for video: " + name + ", entryid: " + id
    xmlquoted = rc.xml
    print "XML: " + xmlquoted