Module:YouTube embed
Jump to navigation
Jump to search
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)
-- Width: extract number, default 325
local width = toNumber(frame.args.width, 325)
-- Height: extract number if provided, else calculate 16:9 rounded
local height = toNumber(frame.args.height, math.floor(width * 9 / 16 + 0.5))
return frame:extensionTag{
name = 'youtube',
content = frame.args[1] or frame.args.id or 'dQw4w9WgXcQ',
args = {
width = width,
height = height
}
}
end
return p