Added OpenWebVideo as a demonstration.
This commit is contained in:
parent
d061fabfd8
commit
638e5c9195
|
@ -13,7 +13,6 @@ __all__ = ["VideoTag", "YoutubeTag"]
|
|||
|
||||
_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.
|
||||
|
@ -49,21 +48,23 @@ class VideoTag(_BlockTag):
|
|||
else None
|
||||
self._align = None
|
||||
self._float = False
|
||||
self._ratio = _defaultratio
|
||||
self._ratio = None
|
||||
|
||||
for arg in map(str.strip, (value or "").split('|')):
|
||||
if not arg:
|
||||
pass
|
||||
elif arg[0] in '0123456789:':
|
||||
rx, ry = _defaultratio_w, _defaultratio_h
|
||||
rn = 0
|
||||
rat = arg.split(':')
|
||||
|
||||
try: rx = int(rat[0])
|
||||
try: rx = int(rat[0]); rn += 1
|
||||
except: pass
|
||||
try: ry = int(rat[1])
|
||||
try: ry = int(rat[1]); rn += 1
|
||||
except: pass
|
||||
|
||||
self._ratio = round(ry / rx, 4)
|
||||
if rn:
|
||||
self._ratio = round(ry / rx, 4)
|
||||
elif arg in _align:
|
||||
al, fl = _align[arg]
|
||||
if al != None:
|
||||
|
@ -91,23 +92,24 @@ class VideoTag(_BlockTag):
|
|||
align = "float-" + (self._align or "left") if self._align \
|
||||
else self._align
|
||||
|
||||
ratio = self._ratio
|
||||
if ratio == _defaultratio:
|
||||
ratio = None
|
||||
if self._ratio:
|
||||
ratio = self._ratio * 100
|
||||
elif hasattr(self._video, 'ratio'):
|
||||
ratio = self._video.ratio * 100
|
||||
else:
|
||||
ratio *= 100
|
||||
iratio = int(ratio)
|
||||
if ratio == iratio:
|
||||
ratio = iratio
|
||||
ratio = str(ratio)
|
||||
ratio = round(_defaultratio_w / _defaultratio_h, 4)
|
||||
iratio = int(ratio)
|
||||
if ratio == iratio:
|
||||
ratio = iratio
|
||||
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: {ratio}%"' if ratio else "")
|
||||
f' style="padding-bottom: {ratio}%"')
|
||||
|
||||
code += '<iframe src="{}" frameborder="0" allowfullscreen>' \
|
||||
'</iframe>'.format(self._video.embed())
|
||||
'</iframe>'.format(self._video.embed)
|
||||
|
||||
return code + '</div>'
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ class YouTubeVideo(_Video):
|
|||
else:
|
||||
raise ValueError("unknown URL")
|
||||
|
||||
def embed(self):
|
||||
return f"https://www.youtube.com/embed/{self._id}"
|
||||
self.embed = f"https://www.youtube.com/embed/{self._id}"
|
||||
|
||||
class DailymotionVideo(_Video):
|
||||
""" Get a video from Dailymotion. """
|
||||
|
@ -52,8 +51,7 @@ class DailymotionVideo(_Video):
|
|||
else:
|
||||
raise ValueError("unknown URL")
|
||||
|
||||
def embed(self):
|
||||
return f"https://www.dailymotion.com/embed/video/{self._code}"
|
||||
self.embed = f"https://www.dailymotion.com/embed/video/{self._code}"
|
||||
|
||||
class VimeoVideo(_Video):
|
||||
""" Get a video from Vimeo. """
|
||||
|
@ -72,8 +70,28 @@ class VimeoVideo(_Video):
|
|||
else:
|
||||
raise ValueError("unknown URL")
|
||||
|
||||
def embed(self):
|
||||
return f"https://player.vimeo.com/video/{self._code}" \
|
||||
self.embed = f"https://player.vimeo.com/video/{self._code}" \
|
||||
"?title=0&byline=0&portrait=0"
|
||||
|
||||
# WARNING: This is only for demonstration sake. Do not use without a cache!
|
||||
# This demonstration class uses the `embed-python` module.
|
||||
#
|
||||
#from embed import Embed as _Embed
|
||||
#
|
||||
#class OpenWebVideo(_Video):
|
||||
# """ Decentralized way to gather a video data. """
|
||||
#
|
||||
# def __init__(self, url):
|
||||
# u = _urlparse.urlparse(url)
|
||||
# if not u.scheme in ('https'):
|
||||
# raise Exception
|
||||
#
|
||||
# embed = _Embed(url)
|
||||
# embed = embed.embed
|
||||
# assert embed['type'] == 'video'
|
||||
#
|
||||
# self.embed = embed['url']
|
||||
# if 'ratio' in embed:
|
||||
# self.ratio = embed['ratio'] / 100
|
||||
|
||||
# End of file.
|
||||
|
|
Loading…
Reference in New Issue