Module:Media

-- Module: Media -- Author: "The JoTS" -- Allows the creation of embedded media objects solely by url, and sizing params.

--

--[==[Modules]==]-- local getArgs = require("Dev:Arguments").getArgs; local utils = require "Module:Utils";

local protocols = { = function(url) -- Wiki File return "" .. url .. ""; end, ["soundcloud.com/"] = function(url, args) -- Soundcloud return mw.html.create "soundcloud" :attr("url", url) :attr("height", args.height or 75) :attr("width", args.width or 200) :attr("auto_play", args.auto_play or 0); end, ["youtube.com/"] = function(url, args) -- YouTube local vidId = url:match("?v=([%w_-]+)"); return mw.html.create "youtube" :wikitext(vidId) :attr({               width  = args.width or 150,                height = args.height or 25}); end }

return { url_to_widget = utils.create_wrapper(function(args)       local url = args.url; -- cannot be the first positional argument as youtube has a "v=", getting interpreted as an param name        local widget_markup;        for pr,func in pairs(protocols) do            if url:match(pr) then                widget_markup = tostring( func(url, args) );                break;            end        end        return widget_markup or url;    end) }