Skip to main content

Generate embed (HTML) code of services like Youtube or Vimeo from URLs given. Rules are specified in the plugins.

Project description

Package

vishap

Description

Generate embed (HTML) code of services like Youtube or Vimeo from URLs given. Rules are specified in the plugins.

Comes with plugins for the following services (listed in alphabetical order):

  • Vimeo

  • Youtube

Installation

Install with latest stable version from PyPI:

$ pip install vishap

or install the latest stable version from bitbucket:

$ pip install -e hg+https://bitbucket.org/barseghyanartur/vishap@stable#egg=vishap

or install the latest stable version from github:

$ pip install -e git+http://github.org/barseghyanartur/vishap@stable#egg=vishap

That’s all. See the Usage and examples section for more.

Usage and examples

Simple usage

Required imports

>>> from vishap import render_video

Rendering Vimeo code

>>> print render_video('http://vimeo.com/45655450', 500, 281)
<iframe src="//player.vimeo.com/video/45655450" width="500" height="281"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>

Rendering Youtube code

>>> print render_video('http://www.youtube.com/watch?v=LIPl7PtGXNI', 560, 315)
<iframe width="560" height="315" src="//www.youtube.com/embed/LIPl7PtGXNI"
frameborder="0" allowfullscreen></iframe>

Filling available area

If you want your embed code to fill the available area, render it without width and height attributes and place it in a container to which it shall stretch.

Example

>>> s = """<div class="video-wrapper">
>>> {embed_code}
>>> </div>""".format(
>>>     embed_code = render_video('http://www.youtube.com/watch?v=LIPl7PtGXNI')
>>> )

Your CSS file should then look similar to the following

>>> .video-wrapper {
>>>     width: 600px;
>>>     height: 500px;
>>>     padding: 0;
>>> }
>>>     .video-wrapper iframe {
>>>         position: absolute;
>>>         width: 100%;
>>>         height: 100%;
>>>     }

Register a custom plugin

>>> class ExamplePlugin(BaseVideoPlugin):
>>>     uid = "example"
>>>     name = "Example"
>>>     url_pattern = "^(?P<prefix>(http\:\/\/www\.youtube\.com\/watch\?v=)|(http\:\/\/www\.youtube\.com\/v\/)|(http\:\/\/youtu\.be\/))(?P<value>[A-Za-z0-9\-=_]{11})"
>>>     id_pattern = "^(?P<value>[A-Za-z0-9\-=_]{11})"
>>>     thumbnail_pattern = "//img.youtube.com/vi/{0}/{1}.jpg"
>>>     embed_code = """
>>>     <iframe src="//www.youtube.com/embed/{video_id}" {options} frameborder="0" allowfullscreen></iframe>
>>>     """
>>>
>>> plugin_registry.register(ExamplePlugin)

Replacing existing plugin

If you want to replace/update existing plugin, you can force register it in the registry.

>>> class UpdatedYoutubePlugin(BaseVideoPlugin):
>>>     uid = "youtube"
>>>     name = "Youtube"
>>>     url_pattern = "^(?P<prefix>(http\:\/\/www\.youtube\.com\/watch\?v=)|(http\:\/\/www\.youtube\.com\/v\/)|(http\:\/\/youtu\.be\/))(?P<value>[A-Za-z0-9\-=_]{11})"
>>>     id_pattern = "^(?P<value>[A-Za-z0-9\-=_]{11})"
>>>     thumbnail_pattern = "//img.youtube.com/vi/{0}/{1}.jpg"
>>>     embed_code = """
>>>     <iframe src="//www.youtube.com/embed/{video_id}" {options} frameborder="0" allowfullscreen></iframe>
>>>     """
>>>
>>> plugin_registry.register(UpdatedYoutubePlugin, force=True)

Missing a plugin?

Missing a plugin for your favourite service? Contribute to the project by making one and it will appear in a new version (which will be released very quickly) or request a feature.

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

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

vishap-0.1.tar.gz (10.7 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for vishap-0.1.tar.gz
Algorithm Hash digest
SHA256 7be7b698db19a633651d31a594c6632c08454dc12fe5561b2e9918c311f1af22
MD5 671f8f09f21d56c523964a11dbdf8ebe
BLAKE2b-256 539f3477e05e316d39bfb99c42ef2ec354a364a1b66e4f47a04d6db37aa80f68

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