python Kaltura API Python脚本,用于向帐户中的所有条目添加标签
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Kaltura API Python脚本,用于向帐户中的所有条目添加标签相关的知识,希望对你有一定的参考价值。
# This script loops through all media entries in a given Kaltura account
# and sets tags to all entries (it also checks if a list of tags is not already set on the entry before adding)
# this script requires the Kaltura Python 2.7 client library: http://www.kaltura.com/api_v3/testme/client-libs.php
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from KalturaClient import *
from KalturaClient.Base import *
from KalturaClient.Plugins.Core import *
# set the tags (comma seperated string) and list of tags to check (if exist on the entry, will not add the tagsToAdd)
tagsToAdd = "captionasr"
tagsToCheck = [tagsToAdd,'processing','caption complete']
# Kaltura Account credentials (make sure to replace partner_id and admin_secret)
# from: http://kmc.kaltura.com/index.php/kmc/kmc4#account|integration
PARTNER_ID = 000000
ADMIN_SECRET = "your-Kaltura-API-Admin-Secret"
SERVICE_URL = "http://www.kaltura.com"
USER_NAME = "taggerUser"
PAGE_SIZE = 100
METADATA_PROFILE_COUNT = 1
# client setup
class KalturaLogger(IKalturaLogger):
def log(self, msg):
pass
def GetConfig():
config = KalturaConfiguration(PARTNER_ID)
config.serviceUrl = SERVICE_URL
config.setLogger(KalturaLogger())
return config
# create session
client = KalturaClient(GetConfig())
ks = client.generateSession(ADMIN_SECRET, USER_NAME, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "")
client.setKs(ks)
# initialize state
lastUpdatedAt = None
lastEntryIds = []
# template entry to update with:
templateMediaEntry = KalturaMediaEntry()
while True:
# build the filter
filter = KalturaMediaEntryFilter(
orderBy=KalturaMediaEntryOrderBy.UPDATED_AT_DESC)
if lastUpdatedAt != None:
filter.setUpdatedAtLessThanOrEqual(lastUpdatedAt)
if lastEntryIds != []:
filter.setIdNotIn(','.join(lastEntryIds))
# get the entries
results = client.media.list(filter, KalturaFilterPager(pageSize=PAGE_SIZE))
print 'got %d entries' % len(results.objects)
# update state (prepare all updates in one multirequest batch)
client.startMultiRequest()
for curEntry in results.objects:
if max(map(lambda x: curEntry.tags.find(x), tagsToCheck)) < 0:
templateMediaEntry.tags = curEntry.tags + ',' + tagsToAdd
updatedEntry = client.media.update(curEntry.id, templateMediaEntry)
print 'updated entry: %s with tags: %s' % (curEntry.id, templateMediaEntry.tags)
if lastUpdatedAt != curEntry.getUpdatedAt():
lastEntryIds = [] # clear the last ids, the entries will not be returned anyway due to the updatedAt<= condition
lastEntryIds.append(curEntry.id)
lastUpdatedAt = curEntry.getUpdatedAt()
# execute the update multirequest batch
updatedEntries = client.doMultiRequest()
if len(results.objects) < PAGE_SIZE:
break
以上是关于python Kaltura API Python脚本,用于向帐户中的所有条目添加标签的主要内容,如果未能解决你的问题,请参考以下文章