Commit fa4e44a9 authored by Benjamin Graillot's avatar Benjamin Graillot

Nouvelle macro YouTube

parent a027b2f8
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - YouTube Macro
Jesus L. Alvaro 2006
v 0.0.2
You can include YouTube videos in the wiki by using this macro:
[[YouTube(V8tSRJ8e3b0)]] or
[[YouTube(http://www.youtube.com/v/V8tSRJ8e3b0)]]
visit "http://www.iesvaldebernardo.es/w/Post/2006-11-30-1447/YouTube_en_la_Wiki."
Benjamin « esum » « coq » Graillot
pour le Cr@ns
Syntaxe :
<<YouYube(V8tSRJ8e3b0)>>
<<YouTube(https://youtube.com/watch?v=wKDD1H-Hlpc)>>
<<YouTube(V8tSRJ8e3b0, loop=true)
<<YouTube(V8tSRJ8e3b0;wKDD1H-Hlpc)
Arguments:
* video: liste de liens ou d'identifiants de video
Arguments optionnels:
* loop: boucler la lecture.
* autoplay: lancer la vidéo à l'ouverture de la page.
* controls: afficher les contrôles de lecture de la vidéo.
"""
def execute(macro, text):
if text.find('http://')> -1 or text.find('https://')>-1:
try:
text = text.split('v=')[1]
except:
return u"URL non valide..."
url = 'https://www.youtube.com/v/%s' % text
html = u'''
<object width="425" height="350">
<param name="movie" value="%(youtubelink)s"></param>
<param name="wmode" value="transparent"></param>
<embed src="%(youtubelink)s" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>
''' % {"youtubelink": url}
return macro.formatter.rawHTML(html)
text = text.split(',')
videos = text[0].split(';')
args = []
kwargs = {}
for i, video in enumerate(videos):
video = video.strip()
if video.startswith('https://') or video.startswith('http://'):
video = video.split('v=')[1].strip()
if i == 0:
args.append(video)
elif i == 1:
kwargs['playlist'] = video
else:
kwargs['playlist'] += ',' + video
for arg in text[1:]:
kw = None
if '=' in arg:
arg = arg.split('=')
kw = arg[0].strip()
arg = arg[1]
arg = arg.strip()
if arg.lower() in {'true', 'false'}:
arg = int(bool(arg))
elif arg.isnum():
arg = int(arg)
if kw is None:
args.append(arg)
else:
kwargs[kw] = arg
return macro.formatter.rawHTML(html(*args, **kwargs))
def html(video, controls=1, loop=0, autoplay=0, playlist=None):
html = u'''<iframe width="420" height="315" src="https://www.youtube.com/embed/{}?loop={}&autoplay={}&controls={}{}"></iframe>'''.format(
video,
loop,
autoplay,
controls,
'&playlist={}'.format(playlist) if playlist is not None else '')
  • if playlist is not None s'écrit if playlist

  • Ce n'est pas exactement pareil mais ça ne change rien ici. Je préfère laisser comme ça c'est mieux pour voir le typage.

Please register or sign in to reply
return html
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment