Module:Ep/Info

-- TO DO: update this so other modules don't need to call Module:Ep/Matcher directly

local p = {}

-- For templates to use this module. First unnamed arg is the value to be interpreted. function p.ep(frame) local ep = frame.args[1] local title = frame.args['title'] or nil local pagename = frame.args['pagename'] or nil local epMatcher = require('Module:Ep/Matcher') local epCode = epMatcher.matchCode(ep) local data if not isempty(title) then data = p.title(epCode) elseif not isempty(pagename) then data = p.pagename(epCode) elseif not isempty(campaign) then data = p.campaign(epCode) elseif not isempty(season) then data = p.season(epCode) else data = epCode end return data end

-- Functions for querying Module:Ep/Array to get title and/or pagename for output function p.epInfo(epCode) local result

local epInfos = mw.loadData('Module:Ep/Array') if epInfos[epCode] == nil then result = "" else result = epInfos[epCode] 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) if type(epCode) ~= "string" then epCode = epCode.args[1] end i, j = string.find(epCode,"x") prefix, epNum = ,  if i then prefix = string.sub(epCode,1,i-1) epNum = string.sub(epCode,j+1) end return prefix, epNum 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, epNum = 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, epNum = 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

--function to determine if a string is empty function isempty(s) return s == nil or s == '' end

return p