Module:Ep/Info

-- TO DO: use the functionality from Module:Ep/Matcher for code parsing

local p = {}

-- Functions for querying Module:Ep/Array to get title and/or pagename for output function p.epInfo(frame) local epCode = frame.args[1] local result = p.epIndividualEpisode(epCode) return result end function p.epIndividualInfo(epCode) local ep = epCode local result

local epInfos = mw.loadData('Module:Ep/Array') if epInfos[ep] == nil then result = "" else result = epInfos[ep] end

return result

end

p.title = function(epCode) return p.epInfo(epCode)['title'] end

p.pagename = function(epCode) if p.epInfo(epCode)['pagename'] then pagename = p.epInfo(epCode)['pagename'] else pagename = p.title(epCode) end return pagename end

-- functions to parse epcode into campaign, season and epnumber, using EPISODE_DECODER

p.parseCode = function(epCode) i, j = string.find(ep,"x") prefix, ep_num = ,  if i then prefix = string.sub(ep,1,i-1) ep_num = string.sub(ep,j+1) end return prefix, ep_num end

-- Parse out shows and (optionally) seasons -- TO DO: make it so it uses the Module:ep/decoder prefix (so it can handle any number of seasons) p.campSeason = function(epCode) local campaign local season local decoder = mw.loadData('Module:Ep/Decoder') prefix, ep_num = p.parseCode(epCode) if (not tonumber(prefix) and tonumber(prefix:sub(-1))) then campaign = decoder[prefix:sub(1, -2)] season = prefix:sub(-1) else campaign = decoder[prefix] season = '' end

-- ExU exceptions if (campaign == 'Exandria Unlimited' and season == '2') then season = "Exandria Unlimited: Kymal" elseif (campaign == 'Exandria Unlimited' and season == '3') then season = "Exandria Unlimited: Calamity" end -- Talks Machina exception if campaign == 'Talks Machina' then season = '' end return campaign, season end

p.prefix = function(epCode) prefix, ep_num = p.parseCode(epCode) return prefix end

p.campaign = function(epCode) campaign, season = p.campSeason(epCode) return campaign end

p.season = function(epCode) campaign, season = p.campSeason(epCode) return season end

return p