Skip to content

Instantly share code, notes, and snippets.

@supermasita
Created September 25, 2016 21:20
Show Gist options
  • Save supermasita/a5a74494754ba69f1ed6a93c12f3c240 to your computer and use it in GitHub Desktop.
Save supermasita/a5a74494754ba69f1ed6a93c12f3c240 to your computer and use it in GitHub Desktop.
Kaltura - Basic session and media list with Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Kaltura API
Very basic example of how to start a session on Python get a list of entries
Should print something like
1; 1457540065; '1_u92di4mp'; 'SAP: Internal Social Video Portal in Enterprises';
2; 1457540075; '1_3jswnxf7'; 'iCEV: Monetizing HQ EDU Videos on the Web';
3; 1457540080; '1_roe9igcy'; 'Intro to MediaSpace';
4; 1457540083; '1_52g2gdub'; 'MediaSpace Admin Basics';
5; 1457540087; '1_4q1kz42l'; 'Kaltura Enterprise Video Solutions';
6; 1457540094; '1_6fmkj6p4'; 'Oregon State: Creating a Campus Media Portal';
7; 1457540099; '1_n3j5z7uc'; 'Columbia Business School:Video as a Marketing Tool in Education';
8; 1457540103; '1_rwx4gtm0'; 'Cornell Uni: Scaling the Video Infrastructure';
9; 1457540107; '1_wg3xpqzv'; 'MediaSpace Categories';
"""
## Kaltura Libraries - Install from http://www.kaltura.com/api_v3/testme/client-libs.php
from KalturaClient import *
from KalturaClient.Plugins.Core import *
#from KalturaClient.Plugins.Metadata import KalturaMetadata, KalturaMetadataProfile, KalturaMetadataFilter, KalturaMetadataListResponse, KalturaMetadataObjectType
## Config (with ADMIN - beware)
partnerId = 000000000000
config = KalturaConfiguration(partnerId)
config.serviceUrl = "https://admin.kaltura.com/"
client = KalturaClient(config)
secret = "xxxxxxxxxxxxxxxxxxxxxxxx"
userId = None
ktype = KalturaSessionType.ADMIN
expiry = 432000 # 432000 = 5 days
privileges = "disableentitlement"
def startsession():
""" Use configuration to generate KS
"""
ks = client.session.start(secret, userId, ktype, partnerId, expiry, privileges)
client.setKs(ks)
def getentries():
""" List entries - Returns strings - Requires a KS generated for the client
"""
startsession()
# Get list
filter = KalturaMediaEntryFilter()
#filter.orderBy = "-createdAt" # Newest first
filter.orderBy = "+createdAt" # Oldest first
pager = KalturaFilterPager()
pager.pageSize = 500
pager.pageIndex = 1
entrylist = client.media.list(filter, pager)
totalcount = entrylist.totalCount
# Loop
nid = 1
while nid < totalcount :
entrylist = client.media.list(filter, pager)
for entry in entrylist.objects:
print "%i; %i; '%s'; '%s';" % (nid, entry.createdAt, entry.id, entry.name)
nid = nid + 1
pager.pageIndex = pager.pageIndex + 1
# Get entries
getentries()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment