Corrected ratio management.
This commit is contained in:
parent
8f7732a07f
commit
5e9790b613
|
@ -166,7 +166,7 @@ __test_cases = {
|
|||
'</script></a></p>',
|
||||
'[video=left|float|4:3]https://www.youtube.com/watch?v=XEjLoHdbVeE': \
|
||||
'<div class="video-wrapper img-float-left" ' \
|
||||
'style="padding-bottom: 0.75%"><iframe ' \
|
||||
'style="padding-bottom: 75%"><iframe ' \
|
||||
'src="https://www.youtube.com/embed/XEjLoHdbVeE" frameborder="0" ' \
|
||||
'allowfullscreen></iframe></div>',
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ from .. import BlockTag as _BlockTag
|
|||
|
||||
__all__ = ["VideoTag"]
|
||||
|
||||
_defaultratio_w = 16
|
||||
_defaultratio_h = 9
|
||||
_defaultratio = round(_defaultratio_w / _defaultratio_h, 4)
|
||||
|
||||
class VideoTag(_BlockTag):
|
||||
""" The video tag, puts a preview of the video whose URL is given.
|
||||
Only a few 'big' services are supported for now.
|
||||
|
@ -45,13 +49,13 @@ class VideoTag(_BlockTag):
|
|||
else None
|
||||
self._align = None
|
||||
self._float = False
|
||||
self._ratio = round(9 / 16, 4)
|
||||
self._ratio = _defaultratio
|
||||
|
||||
for arg in map(str.strip, (value or "").split('|')):
|
||||
if not arg:
|
||||
pass
|
||||
elif arg[0] in '0123456789:':
|
||||
rx, ry = 16, 9
|
||||
rx, ry = _defaultratio_w, _defaultratio_h
|
||||
rat = arg.split(':')
|
||||
|
||||
try: rx = int(rat[0])
|
||||
|
@ -87,11 +91,21 @@ class VideoTag(_BlockTag):
|
|||
align = "float-" + (self._align or "left") if self._align \
|
||||
else self._align
|
||||
|
||||
ratio = self._ratio
|
||||
if ratio == _defaultratio:
|
||||
ratio = None
|
||||
else:
|
||||
ratio *= 100
|
||||
try:
|
||||
ratio = int(ratio)
|
||||
except:
|
||||
pass
|
||||
ratio = str(ratio)
|
||||
|
||||
code = '<div class="video-wrapper{}{}"{}>' \
|
||||
.format(f" {self._sizeclass}" if self._sizeclass else "",
|
||||
f' img-{align}' if align else "",
|
||||
f' style="padding-bottom: {self._ratio}%"' \
|
||||
if self._ratio != round(9 / 16, 4) else "")
|
||||
f' style="padding-bottom: {ratio}%"' if ratio else "")
|
||||
|
||||
code += '<iframe src="{}" frameborder="0" allowfullscreen>' \
|
||||
'</iframe>'.format(self._video.embed())
|
||||
|
|
Loading…
Reference in New Issue