Module:RecentMusicVideos

local p = {}

videos = {}

OUTPUT_PATTERN = [=[ desktopvideo1 description1 desktopvideo2 description2 desktopvideo3 description3 desktopvideo4 description4 desktopvideo5 description5 desktopvideo6 description6 mobilevideo1 description1 mobilevideo2 description2 mobilevideo3 description3 mobilevideo4 description4 mobilevideo5 description5 mobilevideo6 description6 ]=]

function GetVideos(content) for artist, id, title in content:gmatch "%[%[(.-)%]%]%s-|%s-%[https?://m?w?w?w?%.?youtube%.com/watch%?v=(.-)%s(.-)%]" do		videos.insert({id=id, artist=artist, title=title}) end end

function GetContent(frame, delay) local month_delay = delay .. " month" local curr_year = frame:callParserFunction{name="#time", args={"Y", month_delay}} local curr_month = frame:callParserFunction{name="#time", args={"F", month_delay}} local page_link = "Template:" .. curr_year .. " Music Videos/" .. curr_month return mw.title.new(page_link):getContent end

function BuildOutput(frame) local content = GetContent(frame) GetVideos(content) local output = OUTPUT_PATTERN local DESKTOP_WIDTH = "220" local DESKTOP_HEIGHT = "150" local MOBILE_WIDTH = "300" local MOBILE_HEIGHT = "180" for i = 0,5,1 do local id = videos[#videos - i].id		local artist = videos[#videos - i].artist local title = videos[#videos - i].title local link = "https://www.youtube.com/watch?v=" .. id

local desktop_video = frame:preprocess("") local mobile_video = frame:preprocess("") local description = "" .. artist .. " - [" .. link .. " " .. title .. "]"		output = output:gsub("desktopvideo" .. (i + 1), desktop_video) output = output:gsub("mobilevideo" .. (i + 1), mobile_video) output = output:gsub("description" .. (i + 1), description) end return output end

function p.Main(frame) return BuildOutput(frame) end

return p