def kaltura_session(): """ get ks from user """ ks = input("Enter ks: ") config = KalturaConfiguration() config.serviceUrl = "https://api.kaltura.nordu.net/" client = KalturaClient(config) client.clientConfiguration["clientTag"] = "appToken-helper" client.setKs(ks) return client
def kaltura_session(): """ get kaltura_session from user """ kaltura_session = input("Enter ks: ") config = KalturaConfiguration() config.serviceUrl = "https://api.kaltura.nordu.net/" client = KalturaClient(config) client.clientConfiguration["clientTag"] = "change_domain-helper" client.setKs(kaltura_session) return client
def app_token_session(self): """ create kaltura session using appToken """ self.statusbar.showMessage("Create kaltura session using appToken") options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog filename, _ = QFileDialog.getOpenFileName( self, "QFileDialog.getOpenFileName()", "", "Json Files (*.json)", options=options, ) try: with open(filename) as json_data_file: data = json.load(json_data_file) api_token_id = data["api_token_id"] api_token = data["api_token"] kaltura_partnerid = data["kaltura_partnerid"] kaltura_serviceurl = data["kaltura_serviceurl"] config = KalturaConfiguration(kaltura_partnerid) config.serviceUrl = kaltura_serviceurl self.kaltura_session = KalturaClient(config) user_id = "" widget_id = "_" + str(kaltura_partnerid) expiry = 86400 result = self.kaltura_session.session.startWidgetSession( widget_id, expiry) self.kaltura_session.setKs(result.ks) tokenHash = hashlib.sha256( result.ks.encode("ascii") + api_token.encode("ascii")).hexdigest() type = KalturaSessionType.ADMIN result = self.kaltura_session.appToken.startSession( api_token_id, tokenHash, user_id, type, expiry) self.kaltura_session.setKs(result.ks) MultiDl.session_type = "appToken" except: self.error_dialog.showMessage("Error creating Kaltura session")
def admin_secret_session(self): """ create kaltura session using adminsecret """ self.statusbar.showMessage("Create kaltura session using adminsecret") kaltura_partnerid, ok = QInputDialog.getText( self, "Input kaltura partnerid", "Input partnerid:") kaltura_adminsecret, ok = QInputDialog.getText(self, "Input adminsecret", "Input adminsecret:") try: config = KalturaConfiguration() config.serviceUrl = "https://api.kaltura.nordu.net/" self.kaltura_session = KalturaClient(config) ks = self.kaltura_session.session.start(kaltura_adminsecret, None, KalturaSessionType.ADMIN, kaltura_partnerid) self.kaltura_session.setKs(ks) MultiDl.session_type = "adminSecret" except: self.error_dialog.showMessage("Error creating Kaltura session")
def kaltura_client(self): admin_secret = app.config['KALTURA_ADMIN_SECRET'] unique_user_id = app.config['KALTURA_UNIQUE_USER_ID'] partner_id = self.kaltura_partner_id expiry = app.config['KALTURA_EXPIRY'] config = KalturaConfiguration() client = KalturaClient(config) ks = client.session.start( admin_secret, unique_user_id, KalturaSessionType.ADMIN, partner_id, expiry, 'appId:appName-appDomain', ) client.setKs(ks) return client
def __init__(self): expiry = app.config['KALTURA_EXPIRY'] partner_id = app.config['KALTURA_PARTNER_ID'] self.client = KalturaClient(KalturaConfiguration()) result = self.client.session.startWidgetSession( expiry=expiry, widgetId=f'_{partner_id}', ) self.client.setKs(result.ks) token_hash = hashlib.sha256( (result.ks + app.config['KALTURA_APP_TOKEN']).encode('ascii')).hexdigest() result = self.client.appToken.startSession( expiry=expiry, id=app.config['KALTURA_APP_TOKEN_ID'], tokenHash=token_hash, type=KalturaSessionType.ADMIN, ) self.client.setKs(result.ks)
def GetConfig(): config = KalturaConfiguration() config.requestTimeout = 500 config.serviceUrl = SERVICE_URL config.setLogger(KalturaLogger()) return config
def GetConfig(): config = KalturaConfiguration(PARTNER_ID) config.serviceUrl = SERVICE_URL config.setLogger(KalturaLogger()) return config
from KalturaClient.exceptions import KalturaException parser = argparse.ArgumentParser(description="Helper for kaltura sessions") group = parser.add_mutually_exclusive_group(required=True) group.add_argument("-s", "--start", help="start session", action="store_true") group.add_argument("-e", "--end", help="end session", action="store_true") group.add_argument("-g", "--get", help="get session", action="store_true") parser.add_argument("-c", "--client-tag", help="client tag", metavar="client-tag") args = parser.parse_args() if args.start: partnerId = input("Enter partnerId: ") adminSecret = input("Enter adminSecret: ") conf = KalturaConfiguration() conf.serviceUrl = "https://api.kaltura.nordu.net" kc = KalturaClient(conf) kc.clientConfiguration["clientTag"] = args.client_tag ks = kc.session.start(adminSecret, None, 2, partnerId) print("New kalturaSession: " + ks) elif args.get: kalturaSession = input("Enter kalturaSession: ") conf = KalturaConfiguration() conf.serviceUrl = "https://api.kaltura.nordu.net" kc = KalturaClient(conf) kc.setKs(kalturaSession) try: ks = kc.session.get(kalturaSession) print("\nkalturaSession:") print("sessionType: " + str(ks.sessionType.value))
def mediaCreation(self) -> DataSourceStatus: """ Update data with Kaltura media metadata from Kaltura API. :return: DataSourceStatus """ self._kalturaInit() KALTURA_MAX_MATCHES_ERROR: str = 'QUERY_EXCEEDED_MAX_MATCHES_ALLOWED' tableName: str = 'mivideo_media_created' logger.info('Starting procedure...') kClient: KalturaRequestConfiguration = KalturaClient(KalturaConfiguration()) kClient.setKs( # pylint: disable=no-member KalturaSessionService(kClient).start( self.kUserSecret, type=KalturaSessionType.ADMIN, partnerId=self.kPartnerId)) kMedia = KalturaMediaService(kClient) lastTime: datetime = self._readTableLastTime( tableName, 'created_at', self.defaultLastTimestamp) createdAtTimestamp: float = lastTime.timestamp() kFilter = KalturaMediaEntryFilter() kFilter.createdAtGreaterThanOrEqual = createdAtTimestamp kFilter.categoriesFullNameIn = self.categoriesFullNameIn kFilter.orderBy = KalturaMediaEntryOrderBy.CREATED_AT_ASC kPager = KalturaFilterPager() kPager.pageSize = 500 # 500 is maximum kPager.pageIndex = 1 results: Sequence[KalturaMediaEntry] = None lastCreatedAtTimestamp: Union[float, int] = createdAtTimestamp lastId: Union[str, None] = None numberResults: int = 0 queryPageNumber: int = kPager.pageIndex # for logging purposes totalNumberResults: int = numberResults # for logging purposes endOfResults = False while not endOfResults: try: results = kMedia.list(kFilter, kPager).objects except KalturaException as kException: if (KALTURA_MAX_MATCHES_ERROR in kException.args): # set new filter timestamp, reset pager to page 1, then continue kFilter.createdAtGreaterThanOrEqual = lastCreatedAtTimestamp logger.debug( f'New filter timestamp: ({kFilter.createdAtGreaterThanOrEqual})') # to avoid dupes, also filter out the last ID returned by previous query # because Kaltura compares createdAt greater than *or equal* to timestamp kFilter.idNotIn = lastId kPager.pageIndex = 1 continue logger.info(f'Other Kaltura API error: "{kException}"') break numberResults = len(results) logger.debug( f'Query page ({queryPageNumber}); number of results: ({numberResults})') if (numberResults > 0): resultDictionaries: Sequence[Dict] = tuple(r.__dict__ for r in results) creationData: pd.DataFrame = self._makeCreationData(resultDictionaries) creationData.to_sql( tableName, self.appDb.engine, if_exists='append', index=False) courseData: pd.DataFrame = self._makeCourseData(resultDictionaries) courseData.to_sql('mivideo_media_courses', self.appDb.engine, if_exists='append', index=False, method=self._queryRunner) lastCreatedAtTimestamp = results[-1].createdAt lastId = results[-1].id totalNumberResults += numberResults endOfResults = (numberResults < kPager.pageSize) kPager.pageIndex += 1 queryPageNumber += 1 logger.info(f'Total number of results: ({totalNumberResults})') logger.info('Procedure complete.') return DataSourceStatus(ValidDataSourceName.KALTURA_API)