Skip to main content

rich media consuming/providing for django

Project description

Installation

First, you need to install OEmbed. It is available at http://github.com/worldcompany/djangoembed/

git clone git://github.com/worldcompany/djangoembed/
cd djangoembed
python setup.py install

Adding to your Django Project

After installing, adding OEmbed consumption to your projects is a snap. First, add it to your projects’ INSTALLED_APPs and run ‘syncdb’:

# settings.py
INSTALLED_APPS = [
    ...
    'oembed'
]

djangoembed uses a registration pattern like the admin’s. In order to be sure all apps have been loaded, djangoembed should run autodiscover() in the urls.py. If you like, you can place this code right below your admin.autodiscover() bits:

# urls.py
import oembed
oembed.autodiscover()

Consuming Resources

Now you’re ready to start consuming OEmbed-able objects. There are a couple of options depending on what you want to do. The most straightforward way to get up-and-running is to add it to your templates:

{% load oembed_tags %}

{% oembed %}blog.content{% endoembed %}

{# or use the filter #}

{{ blog.content|oembed }}

{# maybe you're working with some dimensional constraints #}

{% oembed "600x600" %}blog.content{% endoembed %}

{{ blog.content|oembed:"600x600" }}

You can consume oembed objects in python as well:

import oembed
oembed.autodiscover()

# just get the metadata
resource = oembed.site.embed('http://www.youtube.com/watch?v=nda_OSWeyn8')
resource.get_data()

{u'author_name': u'botmib',
 u'author_url': u'http://www.youtube.com/user/botmib',
 u'height': 313,
 u'html': u'<object width="384" height="313"><param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1" type="application/x-shockwave-flash" width="384" height="313" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
 u'provider_name': u'YouTube',
 u'provider_url': u'http://www.youtube.com/',
 u'title': u'Leprechaun in Mobile, Alabama',
 u'type': u'video',
 u'version': u'1.0',
 u'width': 384}

# get the metadata and run it through a template for pretty presentation
from oembed.consumer import OEmbedConsumer
client = OEmbedConsumer()
embedded = client.parse_text("http://www.youtube.com/watch?v=nda_OSWeyn8")

<div class="oembed oembed-video provider-youtube">
  <object width="384" height="313">
    <param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1"
           type="application/x-shockwave-flash"
           width="384"
           height="313"
           allowscriptaccess="always"
           allowfullscreen="true">
    </embed>
  </object>
  <p class="credit">
    <a href="http://www.youtube.com/watch?v=nda_OSWeyn8">Leprechaun in Mobile, Alabama</a>
    by
    <a href="http://www.youtube.com/user/botmib">botmib</a>
  </p>
</div>'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangoembed-0.1.tar.gz (32.2 kB view details)

Uploaded Source

File details

Details for the file djangoembed-0.1.tar.gz.

File metadata

  • Download URL: djangoembed-0.1.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for djangoembed-0.1.tar.gz
Algorithm Hash digest
SHA256 b12910a79496a54d22b36ea61c20099f9dccd5a6c1592f70c449513372abe43c
MD5 4caf9cf9c207fa5b6d5cd07c7919e8b2
BLAKE2b-256 7ba0053e44a92d08f67114a681424233c8a64374c58672ee9add02ebdbed39a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page