mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-05-01 18:04:41 +00:00
Add hability to overwrite embed code on the backend
This commit is contained in:
parent
bb370d8163
commit
fdfce70fbf
2 changed files with 17 additions and 20 deletions
|
|
@ -141,6 +141,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 +258,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)
|
||||
|
|
|
|||
|
|
@ -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