def _build_provider_list():
    """
    Construct the provider registry, using the app settings.
    """
    if appsettings.FLUENT_OEMBED_SOURCE == 'basic':
        registry = micawber.bootstrap_basic()
        # make sure http://youtu.be urls are also valid, see https://github.com/coleifer/micawber/pull/7
        registry.register('https?://(\S*.)?youtu(\.be/|be\.com/watch)\S*',
                          Provider('http://www.youtube.com/oembed'))
        return registry
    elif appsettings.FLUENT_OEMBED_SOURCE == 'embedly':
        params = {}
        if appsettings.MICAWBER_EMBEDLY_KEY:
            params['key'] = appsettings.MICAWBER_EMBEDLY_KEY
        return micawber.bootstrap_embedly(**params)
    elif appsettings.FLUENT_OEMBED_SOURCE == 'list':
        # Fi
        registry = ProviderRegistry()
        for regex, provider in appsettings.FLUENT_OEMBED_PROVIDER_LIST:
            registry.register(regex, Provider(provider))
        return registry
    else:
        raise ImproperlyConfigured(
            "Invalid value of FLUENT_OEMBED_SOURCE, only 'basic', 'list' or 'embedly' is supported."
        )
Esempio n. 2
0
def bootstrap_providers(cache=None):
    pr = ProviderRegistry(cache)
    pr.register('https?://\S*?flickr.com/\S*',
                Provider('http://www.flickr.com/services/oembed/'))
    # As of 2012-09-10, the default URLs provided by the "share"
    # button on a YouTube video use the youtu.be domain and no
    # "watch" parameter in the querystring, e.g.
    # http://youtu.be/KpichyyCutw
    pr.register('https?://youtu.be/\S*',
                Provider('http://www.youtube.com/oembed'))
    # Also match non-shortened YouTube URls
    pr.register('https?://\S*.youtu(\.be|be\.com)/watch\S*',
                Provider('http://www.youtube.com/oembed'))
    pr.register('https?://snd.sc/\S*',
                Provider('http://soundcloud.com/oembed'))
    pr.register('https?://soundcloud.com/\S*',
                Provider('http://soundcloud.com/oembed'))
    pr.register('https?://vimeo.com/\S*',
                Provider('http://vimeo.com/api/oembed.json'))
    pr.register('https?://www.slideshare.net/[^\/]+/\S*',
                Provider('http://www.slideshare.net/api/oembed/2'))
    pr.register('https?://instagr(\.am|am\.com)/\S*',
                Provider('http://api.instagram.com/oembed'))
    pr.register('https?://imgur.com\S*',
                Provider('http://api.imgur.com/oembed'))

    # Register our fake providers
    pr.register('https?://maps.google.com/maps.+', GoogleMapProvider(None))
    pr.register('https?://docs.google.com/spreadsheet/pub\?key=[0-9a-zA-Z]+',
                GoogleSpreadsheetProvider(None))
    return pr
Esempio n. 3
0
from django.core.cache import cache
from micawber.providers import Provider, ProviderRegistry

oembed_providers = ProviderRegistry(cache)

oembed_providers.register(r'https?://\S*?flickr.com/\S+',
                          Provider('https://www.flickr.com/services/oembed/'))
oembed_providers.register(r'https?://flic\.kr/\S*',
                          Provider('https://www.flickr.com/services/oembed/'))
oembed_providers.register(r'https://\S*?soundcloud.com/\S+',
                          Provider('http://soundcloud.com/oembed'))
oembed_providers.register(r'http://vimeo.com/\S+',
                          Provider('http://vimeo.com/api/oembed.json'))
oembed_providers.register(r'https://vimeo.com/\S+',
                          Provider('https://vimeo.com/api/oembed.json'))
oembed_providers.register(r'http://(\S*.)?youtu(\.be/|be\.com/watch)\S+',
                          Provider('http://www.youtube.com/oembed'))
oembed_providers.register(
    r'https://(\S*.)?youtu(\.be/|be\.com/watch)\S+',
    Provider('http://www.youtube.com/oembed?scheme=https&'))
oembed_providers.register(r'https?://www.instagr(\.am|am\.com)/p/\S+',
                          Provider('http://api.instagram.com/oembed'))
oembed_providers.register(
    r'https?://www.facebook.com/\S+/videos/\S+',
    Provider('https://www.facebook.com/plugins/video/oembed.json'))
oembed_providers.register(
    r'https?://www.facebook.com/video.php\?(id|v)=\S+',
    Provider('https://www.facebook.com/plugins/video/oembed.json'))