diff --git a/pelican-peertube/__init__.py b/pelican_peertube/__init__.py similarity index 76% rename from pelican-peertube/__init__.py rename to pelican_peertube/__init__.py index 066f030..59f640e 100644 --- a/pelican-peertube/__init__.py +++ b/pelican_peertube/__init__.py @@ -4,9 +4,9 @@ __version__ = '0.1.0' __author__ = 'Melon Bread' __credits__ = ["Melon Bread", "Kura", "Peter Bittner"] __maintainer__ = "Melon Bread" -__email__ = "kura@kura.io" +__email__ = "rain@melonbread.dev" __status__ = "Unstable" __license__ = 'GPL3' __copyright__ = 'Copyright 2019' -from pelican-peertube.peertube import register +from pelican_peertube.peertube import register diff --git a/pelican_peertube/peertube.py b/pelican_peertube/peertube.py new file mode 100644 index 0000000..5b7b19d --- /dev/null +++ b/pelican_peertube/peertube.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals + +from docutils import nodes +from docutils.parsers.rst import directives, Directive + + +class PeerTube(Directive): + """ Embeds PeerTube video in posts. + + Based on pelican_peertube by kura + https://github.com/kura/pelican_youtube/ + + INSTANCE_URL & VIDEO_ID is required, other arguments are optional + + Usage: + ..peertube:: INSTANCE_URL VIDEO_ID + """ + + def boolean(self, argument): + """Conversion function for yes/no Trues/False.""" + value = directives.choice(argument, ("yes", "True", "no", "False")) + return value in ("yes", "True") + + required_arguments = 2 + optional_arguments = 8 + optional_spec = { + "width": directives.positive_int, + "height": directives.positive_int, + "fullscreen": boolean, + "seamless": boolean, + "autoplay": boolean, + "muted": boolean, + "loop": boolean, + "title_show": boolean, + "privacy_show": boolean, + "controls_show": boolean, + } + + final_argument_whitespace = False + has_content = False + + def run(self): + instanceURL = self.arguments[0].strip() + videoID = self.arguments[1].strip() + + url = f"https://{instanceURL}/videos/embed/{videoID}?" + + width = self.options["width"] if "width" in self.options else "560" + height = self.options["height"] if "height" in self.options else "315" + fullscreen = ( + self.options["fullscreen"] if "fullscreen" in self.options else True + ) + seamless = self.options["seamless"] if "seamless" in self.options else True + autoplay = self.options["autoplay"] if "autoplay" in self.options else False + muted = self.options["muted"] if "muted" in self.options else False + loop = self.options["loop"] if "loop" in self.options else False + title_show = ( + self.options["title_show"] if "title_show" in self.options else True + ) + privacy_show = ( + self.options["privacy_show"] if "privacy_show" in self.options else True + ) + controls_show = ( + self.options["controls_show"] if "controls_show" in self.options else True + ) + + iframe_arguments = [ + (width, "width='{}'"), + (height, "height='{}'"), + (fullscreen, "allowfullscreen"), + (seamless, "frameborder='0'"), + ] + + url_arguments = [ + (autoplay, "autoplay='{}'"), + (muted, "muted='{}'"), + (loop, "loop='{}'"), + (title_show, "title='{}'"), + (privacy_show, "warningTitle='{}'"), + (controls_show, "controls='{}'"), + ] + + for value, format in url_arguments: + toggle = 1 if value == True else 0 + url += (format).format(toggle) if value else "" + + embed_block = f"" + + return [ + nodes.raw("", "