GithubHelp home page GithubHelp logo

worldcompany / djangoembed Goto Github PK

View Code? Open in Web Editor NEW
138.0 9.0 38.0 964 KB

rich media consuming and providing with django

Home Page: http://djangoembed.readthedocs.org

License: MIT License

JavaScript 11.58% Python 88.42%

djangoembed's Introduction

THIS PROJECT IS UNMAINTAINED

Please use micawber -- it has much of the same functionality along with many improvements.

Getting Started with OEmbed

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>'

Troubleshooting

Problem: You try the youtube embed example, but all you get is a link to the youtube video.

Solution: Djangoembed uses fixtures to load data about oembed providors like Youtube in to the database. Try fooling around with syncdb (or migrations, if you're running South) until there are objects of type oembed.storedprovider.

If you have another problem, consider looking through the more extensive docs in the project's doc subdirectory.

djangoembed's People

Contributors

arlolra avatar carljm avatar chrisdickinson avatar coleifer avatar ericholscher avatar jefftriplett avatar paltman avatar silentworks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangoembed's Issues

adding a provider

perhaps I did not get everything but I tested Slideshare : working

I tried to modify the endpoint to use the official one, took the URL from Slideshare site

http://www.slideshare.net/api/oembed/2

But this doesn't work (the endpoint returns XML)
Is this app tied to embedly specific flow ?

Twitter doesn't work

Hi,

thanks for this job. I just tested it wis something like this:
{{twitter_url|oembed}}

And the URL is get back, I suppose oembed do something weird.

Allow stripping "a" tags

Currently it's very difficult (if not impossible) to use djangoembed with
any markup format. I'm using restructured text, with the same goes for
textile, markdown, etc.

The big problem is that in markup rich text all links are enclosed in a "a"
element, so djangoembed never changes those links.

It would be great if I could set OEMBED_STRIP_LINKS=True or something
like that in django settings.

I have played a bit with the code and could send a patch or pull request
for this, but I'm not very confident with my proposal. Maybe there's a
better way to get this working?

Syncdb doesn't load fixtures

I'm using Django 1.1.2 with MySQL, how to manually load the providers?

EDIT: I used pip to install djangoembed from source (git+http://...), and for some reason it didn't download the fixtures dir, so this is solved.

Youtube provider with additional parameters

Hello

I'm using oembed on my site to include Youtube videos. Problem is that my site includes navigation and the video if always on top. Solution is to include wmode=opaque in url.

Solution was to modify StoredProvider to http://api.embed.ly/v1/api/oembed?wmode=opaque but checking the code, in providers.py on line 113, url is built by joining parts with ?. With my new provider this does not work.

Could you please modify the code and correctly build url?

Problem with mock_request() function and Context Processors

I am getting a template error when using OEmbed tags, which I believe is due to the behaviour of the mock_request() function in utils.py.

It seems that mock_request() does not add a user object to the request object when it runs the context processors, normally provided by django.contrib.auth.context_processors.auth. This means that context processors of other apps that depend on the existence of a user object throw an exception.

In my case I have django_messages installed, whose context processor requires a user object to be present on Request. When the template is rendered, I get:

Caught AttributeError while rendering: 'HttpRequest' object has no attribute 'user'

safe (autoescape) errors in template

anyone else getting an autoescape error when the oembed html is rendered in a template?

I'm testing with a youtube URL.

When my database table stores the actual iframe embed code, the video is shown in the template correctly.

However, if the database stores just the youtube URL, oembed shows the iframe embed code with ascii codes for the angle brackets and quotation marks.

How do I fix this?

Using the safe filter doesn't help: {{ post.body|safe|oembed }}

Neither does using {% autoescape off %}

Might this be an error using beautifulsoup v.3 instead of beautifulsoup v.4?

Or might implementing mark_safe() help? https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#filters-and-auto-escaping

Is beautiful soup entity encoding your inserted html?

Hi,
I could be wrong here but just in case, I said I'd bring this to your attention.

At the end of the parse_data method of the HTMLParser where you call "replaceWith" on the matched url;
It appears that with the step from BeautifulSoup 3.2.0 to BeautifulSoup 3.2.1
the inserted html is now being entity encoded, thus breaking things.

from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup("")
soup.insert(0, "<b>YAY</b>")
print unicode(soup)

The above under BS 3.2.0 printed:

`````` YAY```

Under BS 3.2.1 it prints:
&lt;b&gt;YAY&lt;/b&gt;

I haven't had the time to dig an awful lot but the solution might be to create a BS representation of the replacement html and pass that to replaceWith.

Thanks,
Dave

OEmbedResource.create() fails on '%' in width value returned by SoundCloud oembed response

Calling the SoundCloud endpoint with minimal parameters returns a width="100%" in the response. For example http://soundcloud.com/oembed?url=http://soundcloud.com/ghing/the-calling-for-diychi-comp&format=json produces this response:

{
    "version": 1,
    "type": "rich",
    "provider_name": "SoundCloud",
    "provider_url": "http://soundcloud.com",
    "height": 166,
    "width": "100%",
    "title": "The Calling (for DIYCHI comp) by ghing",
    "description": "Finished version of \"The Calling\" for the DIY CHI comp",
    "html": "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F27467434&show_artwork=true\"></iframe>"
}

I'm not sure whether or not this adheres to the oEmbed spec, but it's a popular service, so it should be handled.

The problem is in these lines in OEmbedResource.create():

data['width'] = data.get('width') and int(data['width']) or None
data['height'] = data.get('height') and int(data['height']) or None

the call to int(data['width']) raises a ValueError because of the '%' in data['width']

A simple workaround would be to wrap those lines in a try/except like this:

try:
    data['width'] = data.get('width') and int(data['width']) or None
except ValueError:
   data['width'] = None
try:
    data['height'] = data.get('height') and int(data['height']) or None
except ValueError:
    data['height'] = None

Update package on pypi

When installing djangoembed with pip it installs an old version. And it's from before the dependencies were specified, so they do not get installed.

Could you update the pypi package? I saw that you wrote that the project is not maintained anymore, but it could be great if the pypy package at least reflected the latest code in the repo.

Document requirements

Dependencies aren't noted in INSTALL.txt or required by setup.py. In addition to the ones in pip_requirements.txt, I also had to install httplib2 and simplejson (could the Python2.6+ json be used if it is available?)

unique_together problem with MySQL

I got this error when I tried syncdb:
_mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column 'match' used in key specification without a key length")
To solve the problem i removed 'match' from the StoredOEmbed unique_together Meta.

embedly requires API key

Using embed.ly as an endpoint is really cool, but requires an api key. It will work, but after a while the response will be a 403:

 403: Forbidden - Embedly has blocked your client ip. Sign up for an API key at http://embed.ly.

However, I don't see a way to supply an API key using djangoembed

installation errors

running 'manage.py syncdb' after install djangoembed fails with errors (abridged):
for (app_name, error) in get_app_errors().items():
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/db/models/loading.py", line 83, in load_app
if not module_has_submodule(app_module, 'models'):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/utils/module_loading.py", line 14, in module_has_submodule
for entry in package.path: # No path, then not a package.
AttributeError: 'module' object has no attribute 'path'

Python version: 2.7
Unlike previous issue filed against this code, my djangoembed egg has a fixtures directory. Any help appreciated.

Remove ImageField limitation on photo resource providers

Currently the resize method of DjangoProvider raises an exception if the
image field is not a ImageFieldFile. However this requirement is used only
to get images heigth and width, and in the same function is already the
code to get those fields with PIL.

With this patch any FileField-like field could be used;
sorl.thumbnail.fields.ImageField for example. (I pasted the patch directly
since didn't find a way to attach files).

diff --git a/oembed/providers.py b/oembed/providers.py
index 58f4399..faf8d4c 100644
--- a/oembed/providers.py
+++ b/oembed/providers.py
@@ -459,13 +459,11 @@ class DjangoProvider(BaseProvider):
         the url to the new image and the new width & height
         (http://path-to-new-image, 300, 300)
         """
-        if not isinstance(image_field, ImageFieldFile):
-            raise ValueError('image_field must be an instance of django.db.models.fields.files.ImageFieldFile')
-        
-        if image_field.field.width_field and image_field.field.height_field:
-            # use model fields
-            current_width = getattr(image_field.instance, image_field.field.width_field)
-            current_height = getattr(image_field.instance, image_field.field.height_field)
+        if isinstance(image_field, ImageFieldFile):
+            if image_field.field.width_field and image_field.field.height_field:
+                # use model fields
+                current_width = getattr(image_field.instance, image_field.field.width_field)
+                current_height = getattr(image_field.instance, image_field.field.height_field)
         else:
             # use PIL
             try:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.