此模块的文档可以在模块:Video/doc创建

local p = {}

local i18n = {
	trackCategory = '[[Category:嵌入%s视频的页面]]',
	services = {	-- when video embeded with a new service provider, add it here
		youtube = 'YouTube',
		vimeo = 'Vimeo',
		bilibili = 'Bilibili',
	}
}

function p.genVideo( provider, id, width, height, align, caption, urlArgs, dimensions )
	if not id then
		return nil
	end
	provider = provider and provider:lower() or 'youtube'
	dimensions = dimensions or tonumber( width ) or 425
	height = tonumber( height )
	if height then
		dimensions = dimensions .. 'x' .. height
	end
	if urlArgs then
		return mw.getCurrentFrame():callParserFunction{ name = '#ev', args = { provider, id = id, dimensions = dimensions, alignment = align, description = caption, urlArgs = urlArgs } }
	else
		return mw.getCurrentFrame():extensionTag{ name = provider, content = id, args = { dimensions = dimensions, alignment = align, description = caption } }
	end
end

function p.main( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end

	local result
	if args.provider then
		result = p.genVideo(
			args.provider,
			args[ 1 ],
			args[ 2 ],
			args[ 3 ],
			args.align,
			args.caption,
			args.urlargs,
			nil
		)
	else
		result = p.genVideo(
			args[ 1 ],
			args[ 2 ] or args.id,
			nil,
			nil,
			args[ 4 ] or args.alignment,
			args[ 5 ] or args.description or args.caption,
			args[ 7 ] or args.urlargs,
			args[ 3 ] or args.dimensions
		)
	end
	if result then
		result = mw.html.create( 'div' ):wikitext( result )
		if not args.nocat then
			result = tostring( result ) .. i18n.trackCategory:format( i18n.services[ args.provider and args.provider:lower() or '' ] or '' )
		end
	end

	return result
end

return p