![]() |
VOOZH | about |
This module implements {{YouTube}} and {{Vimeo}}, and allows invocations from other modules.
See their documentations to learn how to use through a template.
Other modules can invoke this module, to implement more advanced features.
Exported functions listed below.
This function generates a pure video instance.
Syntax: genVideo( VideoServiceProvider, VideoID, VideoWidth, VideoHeight, VideoAlign, VideoCaption, URLArgs )
VideoServiceProvider: Optional. The video service provider. If not set, youtube will used.VideoID: A video ID. If not set, this function will directly return a nil value.VideoWidth: Optional. The width of the video instance, non-number will be ignored, defaults to 425.VideoHeight: Optional. The height of the video instance, non-number will be ignored. If not set, it will be calculated by width automatically to keep aspect ratio to 16:9.VideoAlign: Optional. The type of video alignment.VideoCaption: Optional. The small text below the video.URLArgs: Optional. The arguments which should append to the URL of the video.This function is used for template invocation, and without any extra parameters accepted, and should not be invocated by other modules.
localp={} locali18n={ trackCategory='[[Category:Pages with%s videos]]', services={-- when video embeded with a new service provider, add it here youtube=' YouTube', youtubeplaylist=' YouTube', vimeo=' Vimeo', bilibili=' Bilibili', } } functionp.genVideo(provider,id,width,height,align,caption,urlArgs) ifnotidthen returnnil end provider=providerandprovider:lower()or'youtube' localdimensions=tonumber(width)or425 height=tonumber(height) ifheightthen dimensions=dimensions..'x'..height end ifurlArgsthen returnmw.getCurrentFrame():callParserFunction{name='#ev',args={provider,id=id,dimensions=dimensions,alignment=align,description=caption,urlArgs=urlArgs}} else returnmw.getCurrentFrame():extensionTag{name=provider,content=id,args={dimensions=dimensions,alignment=align,description=caption}} end end functionp.main(f) localargs=f iff==mw.getCurrentFrame()then args=require('Module:ProcessArgs').merge(true) end localresult=p.genVideo(args.provider,args[1],args[2],args[3],args.align,args.caption,args.urlargs) ifresultthen --result = mw.html.create( 'div' ):wikitext( result ) ifnotargs.nocatthen result=tostring(result)..i18n.trackCategory:format(i18n.services[args.providerandargs.provider:lower()or'']or'') end end returnresult end returnp