Giter VIP home page Giter VIP logo

pyoembed's Introduction

pyoembed

https://ci.rgm.io/buildStatus/icon?job=pyoembed

A Python library for oEmbed that supports auto-discovered and manually included providers.

Installation

$ pip install pyoembed

Usage

The library provides a function that should be called to automatically embed the url content, and it is called oEmbed:

from pyoembed import oEmbed, PyOembedException

try:
    # maxwidth and maxheight are optional.
    data = oEmbed('http://www.youtube.com/watch?v=_PEdPBEpQfY',
                  maxwidth=640, maxheight=480)
except PyOembedException, e:
    print 'An error was ocurred: %s' % e

# data is a dict with keys that will depends on the media type. You should
# choose how to display the content based on the data['type'] value and
# the oEmbed spec ( http://oembed.com/ ).
if data['type'] == 'video':
    print data['html']

# and it goes... Someday we will provide default renderes for each media
# type.

Addition of new providers

pyoembed tries to cover the major oEmbed providers, and should works for any provider that supports oEmbed auto-discover out-of-the box, however your favorite provider may be unsupported yet! :(

To add it, create a file inside the pyoembed.providers package, based on the following example:

from pyoembed.providers import BaseProvider


class InstagramProvider(BaseProvider):

    # priority of the provider. Increase it if the provider isn't well known
    priority = 10

    # url schemas that are supported by the provider.
    # re.compile'd regex are allowed.
    oembed_schemas = ['http://instagram.com/p/*',
                      'http://instagr.am/p/*']

    # api endpoint that answers to oEmbed requests for the provider.
    oembed_endpoint = 'http://api.instagram.com/oembed'

You will also need to add some test urls of your provider to the integration_test.py file, and run it to see if everything is ok.

If everything works, feel free to send a pull request to add the provider:

https://github.com/rafaelmartins/pyoembed/pulls

That's it!

pyoembed's People

Contributors

rafaelmartins avatar chadpaulson avatar maparent avatar timabbott avatar

Watchers

 avatar James Cloos avatar

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.