[Bf-docboard-svn] bf-manual: [8204] trunk/blender_docs: Extensions: Add initial peertube extension

Aaron Carlisle noreply at blender.org
Sat Jul 17 03:25:27 CEST 2021


Revision: 8204
          https://developer.blender.org/rBM8204
Author:   Blendify
Date:     2021-07-17 03:25:27 +0200 (Sat, 17 Jul 2021)
Log Message:
-----------
Extensions: Add initial peertube extension

The allows to add videos from video.blender.org.

This solution should be GDPR compliant unlike youtube/vimeo

This is the first step in T75447

Modified Paths:
--------------
    trunk/blender_docs/manual/conf.py

Added Paths:
-----------
    trunk/blender_docs/exts/peertube.py

Added: trunk/blender_docs/exts/peertube.py
===================================================================
--- trunk/blender_docs/exts/peertube.py	                        (rev 0)
+++ trunk/blender_docs/exts/peertube.py	2021-07-17 01:25:27 UTC (rev 8204)
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import re
+from docutils import nodes
+from docutils.parsers.rst import directives, Directive
+
+CONTROL_HEIGHT = 30
+
+def get_size(d, key):
+    if key not in d:
+        return None
+    m = re.match("(\d+)(|%|px)$", d[key])
+    if not m:
+        raise ValueError("invalid size %r" % d[key])
+    return int(m.group(1)), m.group(2) or "px"
+
+def css(d):
+    return "; ".join(sorted("%s: %s" % kv for kv in d.items()))
+
+class peertube(nodes.General, nodes.Element): pass
+
+def visit_peertube_node(self, node):
+    aspect = node["aspect"]
+    width = node["width"]
+    height = node["height"]
+
+    if aspect is None:
+        aspect = 16, 9
+
+    div_style = {}
+    if (height is None) and (width is not None) and (width[1] == "%"):
+        div_style = {
+            "padding-top": "%dpx" % CONTROL_HEIGHT,
+            "padding-bottom": "%f%%" % (width[0] * aspect[1] / aspect[0]),
+            "width": "%d%s" % width,
+            "position": "relative",
+        }
+        style = {
+            "position": "absolute",
+            "top": "0",
+            "left": "0",
+            "width": "100%",
+            "height": "100%",
+            "border": "0",
+        }
+        attrs = {
+            "src": "<https://video.blender.org/videos/embed/%s" % node["id"],
+            "style": css(style),
+        }
+    else:
+        if width is None:
+            if height is None:
+                width = 560, "px"
+            else:
+                width = height[0] * aspect[0] / aspect[1], "px"
+        if height is None:
+            height = width[0] * aspect[1] / aspect[0], "px"
+        style = {
+            "width": "%d%s" % width,
+            "height": "%d%s" % (height[0] + CONTROL_HEIGHT, height[1]),
+            "border": "0",
+        }
+        attrs = {
+            "src": "https://video.blender.org/videos/embed/%s" % node["id"],
+            "style": css(style),
+        }
+    attrs["allowfullscreen"] = "true"
+    div_attrs = {
+        "CLASS": "peertube_wrapper",
+        "style": css(div_style),
+    }
+    self.body.append(self.starttag(node, "div", **div_attrs))
+    self.body.append(self.starttag(node, "iframe", **attrs))
+    self.body.append("</iframe></div>")
+
+def depart_peertube_node(self, node):
+    pass
+
+def visit_peertube_node_latex(self,node):
+    self.body.append(r'\begin{quote}\begin{center}\fbox{\url{https://video.blender.org/videos/watch/%s}}\end{center}\end{quote}'%node['id'])
+
+
+class PeerTube(Directive):
+    has_content = True
+    required_arguments = 1
+    optional_arguments = 0
+    final_argument_whitespace = False
+    option_spec = {
+        "width": directives.unchanged,
+        "height": directives.unchanged,
+        "aspect": directives.unchanged,
+    }
+
+    def run(self):
+        if "aspect" in self.options:
+            aspect = self.options.get("aspect")
+            m = re.match("(\d+):(\d+)", aspect)
+            if m is None:
+                raise ValueError("invalid aspect ratio %r" % aspect)
+            aspect = tuple(int(x) for x in m.groups())
+        else:
+            aspect = None
+        width = get_size(self.options, "width")
+        height = get_size(self.options, "height")
+        return [peertube(id=self.arguments[0], aspect=aspect, width=width, height=height)]
+
+
+def unsupported_visit_peertube(self, node):
+    self.builder.warn('PeerTube: unsupported output format (node skipped)')
+    raise nodes.SkipNode
+
+
+_NODE_VISITORS = {
+    'html': (visit_peertube_node, depart_peertube_node),
+    'latex': (visit_peertube_node_latex, depart_peertube_node),
+    'man': (unsupported_visit_peertube, None),
+    'texinfo': (unsupported_visit_peertube, None),
+    'text': (unsupported_visit_peertube, None)
+}
+
+
+def setup(app):
+    app.add_node(peertube, **_NODE_VISITORS)
+    app.add_directive("peertube", PeerTube)
+    return {
+        'parallel_read_safe': True,
+        'parallel_write_safe': True,
+    }


Property changes on: trunk/blender_docs/exts/peertube.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Modified: trunk/blender_docs/manual/conf.py
===================================================================
--- trunk/blender_docs/manual/conf.py	2021-07-17 00:40:54 UTC (rev 8203)
+++ trunk/blender_docs/manual/conf.py	2021-07-17 01:25:27 UTC (rev 8204)
@@ -51,6 +51,7 @@
 # ones.
 extensions = [
     'reference',
+    'peertube',
     'youtube',
     'vimeo',
     'sphinx.ext.mathjax',



More information about the Bf-docboard-svn mailing list