Package: vishap
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):VimeoYoutubeInstallationInstall with latest stable version from PyPI:$ pip install vishapor install the latest stable version from bitbucket:$ pip install -e hg+https://bitbucket.org/barseghyanartur/vishap@stable#egg=vishapor install the latest stable version from github:$ pip install -e git+http://github.org/barseghyanartur/vishap@stable#egg=vishapThat’s all. See theUsage and examplessection for more.Usage and examplesSimple usageRequired importsfromvishapimportrender_videoRendering Vimeo codeThe following code:printrender_video('http://vimeo.com/45655450',500,281)Would result the following output:<iframesrc="//player.vimeo.com/video/45655450"width="500"height="281"frameborder="0"webkitallowfullscreenmozallowfullscreenallowfullscreen></iframe>Rendering Youtube codeThe following code:printrender_video('http://www.youtube.com/watch?v=LIPl7PtGXNI',560,315)Would result the following output:<iframewidth="560"height="315"src="//www.youtube.com/embed/LIPl7PtGXNI"frameborder="0"allowfullscreen></iframe>Filling available areaIf you want your embed code to fill the available area, render it withoutwidthandheightattributes 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:<iframesrc="//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-wrapperiframe{position:absolute;width:100%;height:100%;}Register a custom pluginclassExamplePlugin(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 pluginIf you want to replace/update existing plugin, you can force register it in
the registry.classUpdatedYoutubePlugin(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 integrationInstallationAddvishap.contrib.apps.django.vishaptoINSTALLED_APPSINSTALLED_APPS=(# ...'vishap.contrib.apps.django.vishap',# ...)UsageIn 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.LicenseGPL 2.0/LGPL 2.1SupportFor any issues contact me at the e-mail given in theAuthorsection.AuthorArtur Barseghyan <artur.barseghyan@gmail.com>