Module:YouTube embed
Jump to navigation
Jump to search
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Convert a string to a number, stripping non-digit characters
-- Strips decimals
local function toNumber(s, default)
if not s then return default end
local numStr = tostring(s):match("%d+%.?%d*") -- capture digits and decimal
return tonumber(numStr) or default
end
function p.main(frame)
local args = getArgs(frame)
-- Width: extract number, default 330
local width = toNumber(args.width or args[2], 330)
-- Height: extract number if provided, else calculate 16:9 rounded
local height = toNumber(args.height or args[3], math.floor(width * 9 / 16 + 0.5))
return frame:extensionTag{
name = 'youtube',
content = args[1] or args.id or 'dQw4w9WgXcQ',
args = {
width = width,
height = height
}
}
end
return p