Skip to main content

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

The following code:

print render_video('http://vimeo.com/45655450', 500, 281)

Would result the following output:

<iframe src="//player.vimeo.com/video/45655450" width="500" height="281"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>

Rendering Youtube code

The following code:

print render_video('http://www.youtube.com/watch?v=LIPl7PtGXNI', 560, 315)

Would result the following output:

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

It would then result the following output:

<iframe src="//www.youtube.com/embed/LIPl7PtGXNI"
frameborder="0" allowfullscreen></iframe>

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)

Django integration

Installation

Add vishap.contrib.apps.django.vishap to INSTALLED_APPS

INSTALLED_APPS = (
    # ...
    'vishap.contrib.apps.django.vishap',
    # ...
)

Usage

In your template:

Example #1:

{% load vishap_tags %}
{% render_video 'http://www.youtube.com/watch?v=LIPl7PtGXNI' 560 315 as rendered_video_example_1 %}
{{ rendered_video_example_1|safe }}

Example #2:

{% load vishap_tags %}
{% with video_url='http://vimeo.com/41055612' video_width='500' video_height='281' %}
{% render_video video_url video_width video_height as rendered_video_example_2 %}
{{ rendered_video_example_2|safe }}
{% endwith %}

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>

Release files for vishap 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vishap 0.1.5
File Size Uploaded
vishap-0.1.5.tar.gz 29.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vishap 0.1.5
File Interpreter ABI Platform
vishap-0.1.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 49.1 kB

Release files / vishap-0.1.5.tar.gz

Download URL vishap-0.1.5.tar.gz
Size 29.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5a2cb56c77cd40c8a9967ba9975a23667b765d4e2d216a8b3aea7ef70a0bae3a
BLAKE2b-256 checksum
How to use checksums
cb2f62ac8855dc53db935210fea18edb7312dcb2c779f1391f5d9c1185991a99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / vishap-0.1.5-py2.py3-none-any.whl

Download URL vishap-0.1.5-py2.py3-none-any.whl
Size 19.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
05b396b7996c83acf127a2100ba022b0f1365d88ba066de7f28b5185351e1112
BLAKE2b-256 checksum
How to use checksums
4e05ba296b996a424867d1e63aaeec20b90aa0b8f87ad31e89d6cc7064e546ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page