Module:EpisodeList

-- Module that generates a formatted episode list from a list of episode names

local p = {}

function p.guests(frame) -- had an idea where there could be an alternate version of this function that displays the episodes with guestsperts. local display_list = list_process(frame, true, false) return display_list end

function p.list(frame) local display_list = list_process(frame, false, true) return display_list end

function p.notrx(frame) -- alternate version that excludes the transcript column (useful for donor episodes) local display_list = list_process(frame, false, false) return display_list end

function list_process(frame, guests, trxlist) local episodereference = require( "Module:EpisodeReference" ) -- made a little cheat sheet here to reference while I add explicit mp3 links to the episodes local mp3list = episodereference.mp3links local episode_digits = 3 -- When the brothers get past episode 1000, I may wish to increase this to 4 local gridparameters = { -- might not be quite as efficient as just initializing the string with them written in, but figured I'd make this easier to modify in the future border = "0", cellpadding = "1", cellspacing = "1", fifthcolumnname = "Transcript", width = { main = "90%", name = "45%", ["date"] = "24%", -- avoiding some sort of reserved word situation, I'm not familiar enough with lua to know if that would be an issue audio = "12%", transcript = "12%", guestspert = "24%", notrx = "57%", -- The size of the name column, if the list doesn't have a transcript column fifthcolumn = "12%", name_guest = "34%" }	}	if guests == true then gridparameters.width.fifthcolumn = gridparameters.width.guestspert gridparameters.fifthcolumnname = 'Guestspert(s)' gridparameters.width.name = gridparameters.width.name_guest elseif trxlist == false then gridparameters.width.name = gridparameters.width.notrx else gridparameters.width.fifthcolumn = gridparameters.width.transcript end local list = mw.html.create('table') list :addClass('article-table') :addClass('sortable') :attr('border', gridparameters.border) :attr('cellpadding', gridparameters.cellpadding) :attr('cellspacing', gridparameters.cellspacing) :attr('width', gridparameters.width.main) :css('margin', '0 0 0 0') if trxlist == true or guests == true then -- this can't be the best way to do this, can it? list :tag('tr') :tag('th') :attr('scope', 'col') :wikitext('#') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.name) :wikitext('Name') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.date) :wikitext('Date') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.audio) :wikitext('Audio') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.fifthcolumn) :wikitext(gridparameters.fifthcolumnname) :done :done else list :tag('tr') :tag('th') :attr('scope', 'col') :wikitext('#') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.name) :wikitext('Name') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.date) :wikitext('Date') :done :tag('th') :attr('scope', 'col') :css('width', gridparameters.width.audio) :wikitext('Audio') :done :done end for k,v in pairs(frame.args) do -- looping through all the parameters, producing one row per episode local list_chunk = list:tag('tr') local parameter_name = string.gsub(v,"[\n\r]","") -- sanitizing the input local episode_name, episode_number, episode_date, episode_audio, episode_transcript, episode_donor, episode_guests = "", "", "", "", "", "", "" episode_number, episode_name = string.match(parameter_name, "Episode%s+(%d+):%s+(.*)") -- breaking the episode name into its number and name local number_length = 0 if episode_number ~= nil then number_length = string.len(episode_number) -- checking the length of the number. end if episode_name ~= nil and episode_number ~= nil and number_length ~= 0 and number_length <= episode_digits then -- if the number is longer than 3-4 digits, or the name is blank, assume it's not a numbered episode episode_number = string.rep("0",episode_digits - number_length) .. episode_number -- pad the number with zeroes else episode_name = parameter_name -- reset the name episode_number = "Sp" -- call it a special episode end episode_name = "" .. episode_name .. "" episode_date, episode_audio, episode_transcript, episode_donor, episode_guests = getdata(parameter_name) if episode_name == "Adventure Zone" or episode_name == "The Adventure Zone" then -- hacky way of handling the adventure zone episode, since it doesn't have an episode infobox episode_date = "August 18, 2014" elseif episode_date == nil then -- I know it's bad form to compare directly to nil, but I couldn't find another way to logically organize it			episode_date = "" -- if the episode didn't have a date, make the variable an empty string end if episode_audio ~= nil and string.len(episode_audio) > 1 then -- some episodes have empty mp3 links. This prevents them from causing it to create an empty link on the list local episode_audio_link = "link" if string.find(episode_audio,".mp3",1,true) ~= nil then episode_audio_link = "mp3" end episode_audio = "[" .. episode_audio .. " " .. episode_audio_link .. "]" -- put the mp3 link into brackets to make it a proper wikitext link elseif episode_donor ~= nil and string.len(episode_donor) > 1 then -- if it's a donor episode, use a special link episode_audio = "link" elseif mp3list[parameter_name] ~= nil then -- if an explicit mp3 link can't be found, use our cheat sheet episode_audio = "[" .. mp3list[parameter_name] .. " mp3]" else episode_audio = "" end if episode_transcript ~= nil and string.len(episode_transcript) > 1 then if string.find(episode_transcript,"http",1,true) ~= nil then -- if the transcript is an external link (based on the http), treat it as one episode_transcript = "[" .. episode_transcript .. " TRX]" else episode_transcript = "TRX" -- otherwise, assume its an internal link end else episode_transcript = "" end local fifthcolumn = "" if trxlist == true then fifthcolumn = episode_transcript elseif guests == true and episode_guests ~= nil then fifthcolumn = episode_guests end list_chunk :tag('td') :wikitext(episode_number) :done :tag('td') :wikitext(episode_name) :done :tag('td') :wikitext(episode_date) :done :tag('td') :wikitext(episode_audio) :done if trxlist == true or guests == true then list_chunk :tag('td') :wikitext(fifthcolumn) :done end end

return list end

function getdata(page_name) local title = mw.title.new(page_name) local content = title:getContent -- probably very expensive, sorry Fandom local search_string = "%s*=%s*(.-)[|\n\r}]" -- search for template named parameters local datevar, mp3, transcript, donor, guests = "", "", "", "", "" if content ~= nil then datevar = string.match(content, "[Dd]ate" .. search_string) mp3 = string.match(content, "[Mm]p3link" .. search_string) -- searches for explicit MP3 links. transcript = string.match(content, "[Tt]ranscript" .. search_string) donor = string.match(content, "[Dd]onor" .. search_string) guests = string.match(content, "[Gg]uest" .. search_string) end return datevar, mp3, transcript, donor, guests end

return p