Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 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, "")
Ejemplo n.º 4
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, "")
Ejemplo n.º 5
0
Archivo: kaltura.py Proyecto: 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, '')
Ejemplo n.º 6
0
Archivo: views.py Proyecto: 9ae/djv
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)
Ejemplo n.º 7
0
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,
                                  '')
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
Archivo: voicebase.py Proyecto: 9ae/djv
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
Archivo: voicebase.py Proyecto: 9ae/djv
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
Archivo: voicebase.py Proyecto: 9ae/djv
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
Ejemplo n.º 17
0
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,
Ejemplo n.º 18
0
def GetClient():
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    return KalturaClient(config)
Ejemplo n.º 19
0
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, "")
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
Archivo: settings.py Proyecto: 9ae/djv
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',
Ejemplo n.º 22
0
def GetClient():
    secrets = get_api_secrets()['kaltura']
    config = KalturaConfiguration(secrets['partner_id'])
    config.serviceUrl = SERVICE_URL
    return KalturaClient(config)
Ejemplo n.º 23
0
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'])
Ejemplo n.º 24
0
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',