Attachment 'EmbedVideo-1.0.py'

Download

   1 """
   2     MoinMoin - EmbedVideo macro
   3     v1.0 [2018-10-29]
   4 
   5     This macro allows you to include a video based on its URL.
   6     Syntax: <<EmbedVideo("https://...."))>>
   7 
   8     Optional additional arguments: width and height, e.g.:
   9     Syntax: <<EmbedVideo("https://....", 480, 320))>>
  10 
  11     Links to attachments are also supported (beware: quotes are required):
  12     Syntax: <<EmbedVideo("attachment:foo.ogv"))>>
  13 
  14     @copyright: 2018 Lars Kruse <devel@sumpfralle.de>
  15     @license: GNU GPL3 or later
  16 """
  17 
  18 from MoinMoin import wikiutil
  19 from MoinMoin.action.AttachFile import absoluteName, getAttachUrl
  20 
  21 
  22 def execute(macro, parameter_string):
  23     parameter_parser = wikiutil.ParameterParser("%(url)s%(width)s%(height)s")
  24     fixed_count, parsed_parameters = parameter_parser.parse_parameters(
  25         parameter_string)
  26     video_url = wikiutil.escape(parsed_parameters["url"])
  27     width = wikiutil.escape(parsed_parameters["width"])
  28     height = wikiutil.escape(parsed_parameters["height"])
  29     # manually parse attachment URLs
  30     if video_url.startswith("attachment:"):
  31         given_attachment_name = video_url.split(":", 1)[1]
  32         current_pagename = macro.formatter.page.page_name
  33         attach_page, real_attach_name = absoluteName(
  34             given_attachment_name, current_pagename)
  35         video_url = getAttachUrl(attach_page, real_attach_name, macro.request)
  36     tag_attributes = {}
  37     if width is not None:
  38         tag_attributes["width"] = width
  39     if height is not None:
  40         tag_attributes["height"] = height
  41     tag_attributes_text = " ".join('{}="{}"'.format(key, value)
  42                                    for key, value in tag_attributes.items())
  43     html = ('<video {} controls="controls"><source src="{}" /></video>'
  44             .format(tag_attributes_text, video_url))
  45     return macro.formatter.rawHTML(html)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2018-11-02 02:26:17, 1.8 KB) [[attachment:EmbedVideo-1.0.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.