mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-04-29 17:04:43 +00:00
Merge pull request #8 from sayadn/custom-embed-code-on-backends
Thanks, it's much better solution.
This commit is contained in:
commit
d9f3a1d1c1
2 changed files with 20 additions and 24 deletions
|
|
@ -9,8 +9,7 @@ except:
|
|||
|
||||
|
||||
from .utils import import_by_path
|
||||
from .settings import EMBED_VIDEO_BACKENDS, EMBED_VIDEO_CACHE, \
|
||||
EMBED_VIDEO_CACHE_TIMEOUT
|
||||
from .settings import EMBED_VIDEO_BACKENDS, EMBED_VIDEO_CACHE
|
||||
|
||||
cache = None
|
||||
if EMBED_VIDEO_CACHE:
|
||||
|
|
@ -141,6 +140,18 @@ class VideoBackend(object):
|
|||
"""
|
||||
return self.pattern_thumbnail_url % self.code
|
||||
|
||||
def get_embed_code(self, width, height):
|
||||
"""
|
||||
Returns embed code.
|
||||
"""
|
||||
return '<iframe width="%(width)d" height="%(height)d" ' \
|
||||
'src="%(url)s" frameborder="0" allowfullscreen>' \
|
||||
'</iframe>' % {
|
||||
'url': self.url,
|
||||
'width': width,
|
||||
'height': height,
|
||||
}
|
||||
|
||||
|
||||
class YoutubeBackend(VideoBackend):
|
||||
"""
|
||||
|
|
@ -246,3 +257,6 @@ class SoundCloudBackend(VideoBackend):
|
|||
def get_code(self):
|
||||
match = self.re_code.search(self.response.get('html'))
|
||||
return match.group('code')
|
||||
|
||||
def get_embed_code(self, width, height):
|
||||
return super(SoundCloudBackend, self).get_embed_code(width=width, height=self.height)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from django.template import Library, Node, TemplateSyntaxError
|
||||
from django.utils.safestring import mark_safe, SafeText
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..backends import detect_backend, SoundCloudBackend, VideoBackend
|
||||
from ..backends import detect_backend, VideoBackend
|
||||
|
||||
register = Library()
|
||||
|
||||
|
|
@ -99,13 +99,9 @@ def embed(backend, size='small'):
|
|||
backend = detect_backend(backend)
|
||||
|
||||
_size = _embed_get_size(size)
|
||||
params = _embed_get_params(backend, _size)
|
||||
|
||||
return mark_safe(
|
||||
'<iframe width="%(width)d" height="%(height)d" '
|
||||
'src="%(url)s" frameborder="0" allowfullscreen>'
|
||||
'</iframe>' % params
|
||||
)
|
||||
return mark_safe(backend.get_embed_code(width=_size[0],
|
||||
height=_size[1]))
|
||||
|
||||
|
||||
def _embed_get_size(size):
|
||||
|
|
@ -122,17 +118,3 @@ def _embed_get_size(size):
|
|||
elif 'x' in size:
|
||||
return [int(x) for x in size.split('x')]
|
||||
|
||||
|
||||
def _embed_get_params(backend, size):
|
||||
params = {
|
||||
'url': backend.url,
|
||||
'width': size[0],
|
||||
'height': size[1],
|
||||
}
|
||||
|
||||
if isinstance(backend, SoundCloudBackend):
|
||||
params.update({'height': backend.height})
|
||||
|
||||
return params
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue