Module:RecentMusicVideos

local p = {}

I = {} A = {} T = {}

n_items = 0

function DataInsert(id, artist, title) table.insert(I, id) table.insert(A, artist) table.insert(T, title) n_items = n_items + 1 end

function RemoveData I = {} A = {} T = {} n_items = 0 end

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

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 GetContent(frame) local page_link = "List_of_Music_Videos" local page = mw.title.new(page_link) return page:getContent end

function BuildOutput(frame) local content = GetContent(frame) ParseContent(content) local 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 = I[n_items - i]		local artist = A[n_items - i]		local title = T[n_items - i] local link = "https://www.youtube.com/watch?v=" .. id		local desktop_embed = "" local mobile_embed = "" local desktop_video = frame:preprocess(desktop_embed) local mobile_video = frame:preprocess(mobile_embed) local description = "" .. artist .. " - [" .. link .. " " .. title .. "]"		local desktop_video_placeholder = "desktopvideo" .. (i + 1) local mobile_video_placeholder = "mobilevideo" .. (i + 1) local description_placeholder = "description" .. (i + 1) output = output:gsub(desktop_video_placeholder, desktop_video) output = output:gsub(mobile_video_placeholder, mobile_video) output = output:gsub(description_placeholder, description) end return output end

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

return p