def facebook(request): if request.method == 'GET': secrets = get_api_secrets()['facebook'] verification_code = request.GET.get('code') args = dict(client_id=secrets['app_id'], scope='email,user_friends,user_photos', redirect_uri=request.build_absolute_uri()) if verification_code: args['client_secret'] = secrets['app_secret'] args['code'] = verification_code response = cgi.parse_qs( urllib.urlopen( 'https://graph.facebook.com/oauth/access_token?%s' % urllib.urlencode(args)).read()) access_token = response['access_token'][-1] # Download the user profile and cache a local instance of the # basic profile info profile = json.load( urllib.urlopen( 'https://graph.facebook.com/me?%s' % urllib.urlencode(dict(access_token=access_token)))) data = dict(fb_user=profile['id'], profile_url=profile['link'], access_token=access_token) response = HttpResponse(json.dumps(data)) set_cookie(response, 'fb_user', str(profile['id'])) return response else: return redirect('https://graph.facebook.com/oauth/authorize?%s' % urllib.urlencode(args)) return HttpResponseBadRequest()
def facebook(request): if request.method == 'GET': secrets = get_api_secrets()['facebook'] verification_code = request.GET.get('code') args = dict(client_id=secrets['app_id'], scope='email,user_friends,user_photos', redirect_uri=request.build_absolute_uri()) if verification_code: args['client_secret'] = secrets['app_secret'] args['code'] = verification_code response = cgi.parse_qs(urllib.urlopen('https://graph.facebook.com/oauth/access_token?%s' % urllib.urlencode(args)).read()) access_token = response['access_token'][-1] # Download the user profile and cache a local instance of the # basic profile info profile = json.load(urllib.urlopen('https://graph.facebook.com/me?%s' % urllib.urlencode(dict(access_token=access_token)))) data = dict(fb_user=profile['id'], profile_url=profile['link'], access_token=access_token) response = HttpResponse(json.dumps(data)) set_cookie(response, 'fb_user', str(profile['id'])) return response else: return redirect('https://graph.facebook.com/oauth/authorize?%s' % urllib.urlencode(args)) return HttpResponseBadRequest()
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, "")
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, '')
def list(request): secrets = get_api_secrets()['kaltura'] ks = GetKS() upload_token = get_upload_token(ks) content = { 'ks': ks, 'partnerId': secrets['partner_id'], 'uploadToken': upload_token } return render(request, 'brain/list.html', content)
def tag_objects(entry_id, image_url): secrets = get_api_secrets()['stockpodium'] tags = [] base_uri = STOCKPODIUM_URL args = urllib.urlencode(dict(api_key=secrets['key'], url=image_url)) url = '%(base_uri)s%(args)s' % locals() r = requests.get(url).json() scene_tags = r['tags'] for tag in scene_tags: if tag['confidence']>OBJECT_THRESHOLD and not(tag['tag'] in tags): tags.append(tag['tag']) return tags
def tree(self): secrets = get_api_secrets()['kaltura'] z = [] z += h.div(id=self.id, **self.kwargs) with h.script(type='text/javascript').into(z): z += h.Raw('''\ mw.setConfig("KalturaSupport.LeadWithHTML5",true); kWidget.embed({ 'targetId': '%s', 'wid': '_%s', 'uiconf_id': '24670302', 'entry_id': '%s', }); ''' % (self.id, secrets['partner_id'], self.entry_id)) return z
def tag_images_stock(entry_id): secrets = get_api_secrets()['stockpodium'] os.chdir(IMAGES_DIR) files_list = glob.glob(entry_id+'-*.jpg') tags = [] for filename in files_list: url = STOCKPODIUM_URL+'api_key='+secrets['key']+'&url='+IMAGES_BASE_URL+filename r = requests.get(url).json() scene_tags = r['tags'] for tag in scene_tags: if tag['confidence']>OBJECT_THRESHOLD and not(tag['tag'] in tags): tags.append(tag['tag']) update_tags(entry_id, tags)
def get_transcript(entry_id): """Return the transcript for a Kaltura entry Return None if transcript is not available. """ secrets = get_api_secrets()['voicebase'] params = { 'apikey': secrets['key'], 'password': secrets['password'], 'action': 'getTranscript', 'externalID': entry_id, 'confidence': 0.75, } ret = requests.post(API_URL, data=params).json() try: return ret['transcript'] except: logger.warn('Cannot find transcript for entry {}.'.format(entry_id)) logger.warn(ret) return None
def post_entry(entry_id, transcription_type='human'): """Post a Kaltura entry to VoiceBase for transcription Transcription type can be either human or machine. Return True of video is posted, False if not (meaning that we should retry a little later). Raises an exception to signal that task is not doable. """ duration = kaltura.get_entry_duration(entry_id) if duration is None: raise VoiceBasePostGiveUp('Cannot find entry {}'.format(entry_id)) if duration <= 4000: raise VoiceBasePostGiveUp( 'Entry {} is too short for voice tagging'.format(entry_id)) entry_url = kaltura.get_entry_download_url_with_flavor(entry_id) if entry_url is None: return False secrets = get_api_secrets()['voicebase'] params = { 'apikey': secrets['key'], 'password': secrets['password'], 'action': 'uploadMediaGet', 'mediaURL': entry_url, 'transcriptType': transcription_type, 'title': entry_id, 'externalid': entry_id, } ret = requests.get(API_URL, params=params).json() if ret.get('requestStatus', '') == 'SUCCESS': logger.debug('Successfully post entry {}'.format(entry_id)) return True elif ret.get('statusMessage', '') == 'External ID is not unique': logger.debug('Entry {} already exists.'.format(entry_id)) return True else: logger.warn('Failed to post entry {}'.format(entry_id)) logger.warn(ret) return False
def get_keywords(entry_id): """Return a list of keywords of a Kaltura entry Note that we are using the GetFileAnalytics API, which gives the real keywords. The GetKeywords/GetSEOKeywords API simply returns the transcript. """ secrets = get_api_secrets()['voicebase'] params = { 'apikey': secrets['key'], 'password': secrets['password'], 'action': 'getFileAnalytics', 'externalID': entry_id, 'format': 'txt', } ret = requests.post(API_URL, data=params).json() try: keywords = [kw['name'] for kw in ret['keywords']] logging.debug(keywords) return keywords except: logger.warn('Cannot find keywords for entry {}.'.format(entry_id)) logger.warn(ret) return None
import requests from KalturaClient import * from KalturaClient.Plugins.Metadata import * import concurrent.futures import os import os.path from djv import settings from djv.utils import get_api_secrets HERE = os.path.abspath(os.path.dirname(__file__)) API_BASE_URL = 'http://www.kaltura.com/api_v3/index.php?' PUBLIC_BASE_URL = 'http://www.kaltura.com/p/%(partner_id)s' % get_api_secrets( )['kaltura'] SERVICE_URL = "http://www.kaltura.com" def GetClient(): secrets = get_api_secrets()['kaltura'] config = KalturaConfiguration(secrets['partner_id']) config.serviceUrl = SERVICE_URL return KalturaClient(config) 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,
def GetClient(): secrets = get_api_secrets()['kaltura'] config = KalturaConfiguration(secrets['partner_id']) config.serviceUrl = SERVICE_URL return KalturaClient(config)
import requests from KalturaClient import * from KalturaClient.Plugins.Metadata import * import concurrent.futures import os import os.path from djv import settings from djv.utils import get_api_secrets HERE = os.path.abspath(os.path.dirname(__file__)) API_BASE_URL = 'http://www.kaltura.com/api_v3/index.php?' PUBLIC_BASE_URL = 'http://www.kaltura.com/p/%(partner_id)s' % get_api_secrets()['kaltura'] SERVICE_URL = "http://www.kaltura.com" def GetClient(): secrets = get_api_secrets()['kaltura'] config = KalturaConfiguration(secrets['partner_id']) config.serviceUrl = SERVICE_URL return KalturaClient(config) 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, "")
def list(request): secrets = get_api_secrets()['kaltura'] ks = GetKS() upload_token = get_upload_token(ks) content = {'ks':ks, 'partnerId': secrets['partner_id'], 'uploadToken':upload_token } return render(request, 'brain/list.html', content)
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) from djv.utils import get_api_secrets # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = get_api_secrets()['djv']['secret_key'] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True USE_ASYNC = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth',
def get_facepp_api(): from facepp import API from djv.utils import get_api_secrets return API(get_api_secrets()['facepp']['deja vu']['key'], get_api_secrets()['facepp']['deja vu']['secret'])
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) from djv.utils import get_api_secrets # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = get_api_secrets()['djv']['secret_key'] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True USE_ASYNC = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin',