The oembeditem plugin

The oembeditem plugin allows inserting an embedded online content in the page, such as a YouTube video, SlideShare presentation, Twitter status, Flickr photo, etc..

../_images/oembeditem-admin.png

The presentation is rendered with the embed code:

../_images/oembeditem-html.png

By default, the following services are supported:

By using the paid-for embed.ly service, many other sites can be supported too.

Installation

Install the dependencies via pip:

pip install django-fluent-contents[oembeditem]

This installs the micawber package.

Add the following settings to settings.py:

INSTALLED_APPS += (
    'fluent_contents.plugins.oembeditem',
)

Configuration

The following settings are available:

FLUENT_OEMBED_SOURCE = 'basic'   # "list", "basic" or "embedly"

FLUENT_OEMBED_EXTRA_PROVIDERS = (
    (r'http://\S+.wordpress\.com/\S*',  'http://public-api.wordpress.com/oembed/?for=my-domain-name'),
    (r'http://\S+.wp\.me/\S*',          'http://public-api.wordpress.com/oembed/?for=my-domain-name'),
)

MICAWBER_EMBEDLY_KEY = ''


FLUENT_OEMBED_PROVIDER_LIST = (
    (r'https?://(www\.)?youtube\.com/watch\S*',  'http://www.youtube.com/oembed'),
    (r'http://youtu\.be/\S*',                    'http://www.youtube.com/oembed'),
    (r'http://blip\.tv/\S*',                     'http://blip.tv/oembed/'),
    (r'https?://(www\.)?vimeo\.com/\S*',         'http://vimeo.com/api/oembed.json'),

    # ...
)

FLUENT_OEMBED_SOURCE

The source to use for the OEmbed provider list. This can be one the following values:

  • basic Use the list of well-known providers in the micawber package.
  • noembed Use the embed service from noembed
  • embedly Use the embed service from embed.ly
  • list Use the provides defined in FLUENT_OEMBED_PROVIDER_LIST.

The embed.ly service contains many providers, including sites which do not have an OEmbed implementation themselves. The service does cost money, and requires an API key. For a list of providers supported by embed.ly see http://embed.ly/providers

The basic setting is the default, and contains well known services that provide an OEmbed endpoint.

FLUENT_OEMBED_EXTRA_PROVIDERS

The OEmbed providers in this setting will be added to the existing set that FLUENT_OEMBED_SOURCE contains. Each item is a tuple with the regular expression and endpoint URL.

MICAWBER_EMBEDLY_KEY

The key to access the embed.ly service.

FLUENT_OEMBED_PROVIDER_LIST

A fixed hard-coded list of providers. Specify this setting to override the complete set of default OEmbed providers. To add additional providers to any existing source, use FLUENT_OEMBED_EXTRA_PROVIDERS instead.

Each item is a tuple with two fields:

  • The regular expression to match the URL.
  • The OEmbed provider endpoint.

Note that the regular expressions never test for .* but use \S* instead so micawber can also detect the URL within a larger fragment.

Security considerations

Note that an OEmbed element is fetched from another server, which specifies how the embed code looks like. Hence, only known online services are whitelisted via the FLUENT_OEMBED_PROVIDER_LIST setting. This reduces the risks for Cross-site scripting (XSS) attacks.

Hence, the OEmbed discovery protocol is not supported either.