Skip to content

Commit

Permalink
add support for sphinxcontrib-video
Browse files Browse the repository at this point in the history
Added support to process video nodes and publish assets to Confluence.

sphinxcontrib-video - https://github.com/sphinx-contrib/video

Signed-off-by: Aleksandr Musorin <aleksandr.musorin@semrush.com>
  • Loading branch information
AVMusorin committed Jun 8, 2023
1 parent f0ad65f commit aaa36ef
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Type Notes
time.
`sphinxcontrib-svgbob`_ Supported
`sphinxcontrib-youtube`_ Supported
`sphinxcontrib-video`_ Supported
================================= =====

.. raw:: latex
Expand Down Expand Up @@ -359,6 +360,7 @@ brings up another concern, feel free to bring up an issue:
.. _sphinxcontrib-seqdiag: https://pypi.org/project/sphinxcontrib-seqdiag/
.. _sphinxcontrib-svgbob: https://pypi.org/project/sphinxcontrib-svgbob/
.. _sphinxcontrib-youtube: https://pypi.org/project/sphinxcontrib-youtube/
.. _sphinxcontrib-video: https://pypi.org/project/sphinxcontrib-video/
.. _tables: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#tables
.. _toctree: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents
.. _transitions: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#transitions
Expand Down
31 changes: 31 additions & 0 deletions sphinxcontrib/confluencebuilder/storage/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,37 @@ def visit_vimeo(self, node):
def visit_youtube(self, node):
self._visit_video(node, 'https://www.youtube.com/watch?v=' + node['id'])

# ---------------------------------------------------
# sphinx -- extension (third party) -- sphinx-video
# ---------------------------------------------------

def visit_video_node(self, node):
autoplay = node.get("autoplay")
height = node.get("height")
width = node.get("width")
source_path, _ = node.get("primary_src") or (None, None)

img_key, _, _ = self.assets.add(source_path, self.docname)

if not img_key:
self.warn(f"Couldn't find video name {source_path}")
raise nodes.SkipNode

ri_filename = self._start_ri_attachment(node, img_key) + self._end_ri_attachment(node)

self.body.append(self._start_tag(node, 'div'))
self.body.append(self._start_ac_macro(node, 'multimedia'))
self.body.append(self._build_ac_param(node, 'name', ri_filename))
if width:
self.body.append(self._build_ac_param(node, "width", str(width)))
if height:
self.body.append(self._build_ac_param(node, "height", str(height)))
if autoplay:
self.body.append(self._build_ac_param(node, "autostart", str(autoplay).lower()))
self.body.append(self._end_ac_macro(node))
self.body.append(self._end_tag(node))
raise nodes.SkipNode

# -------------
# miscellaneous
# -------------
Expand Down
4 changes: 4 additions & 0 deletions tests/sample-sets/sphinx-video/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extensions = [
'sphinxcontrib.video',
'sphinxcontrib.confluencebuilder',
]
8 changes: 8 additions & 0 deletions tests/sample-sets/sphinx-video/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
video
=======

.. video:: video-example.mp4
:alt: video-example
:muted:
:width: 70
:height: 50
13 changes: 13 additions & 0 deletions tests/sample-sets/sphinx-video/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tox]
package_root={toxinidir}{/}..{/}..{/}..

[testenv]
deps =
sphinxcontrib-video
commands =
{envpython} -m tests.test_sample {posargs}
setenv =
PYTHONDONTWRITEBYTECODE=1
TOX_INI_DIR={toxinidir}
passenv = *
use_develop = true
Binary file added tests/sample-sets/sphinx-video/video.mp4
Binary file not shown.

0 comments on commit aaa36ef

Please sign in to comment.