FANDOM


--Please see [[Template:Eps]] for documentation. Do not use #invoke directly.
--To update, simply add or change the per-season episode counts on lines 16/17.
--Line 51 (spellings) needs to be updated if there are more than nine seasons.
local p = {}
 
function p.test(frame)
    return p.call(frame.args)
end
 
function p.main(frame)
    return p.call(frame:getParent().args)
end
 
function p.call(args)
    --Update here: number of episodes per season.
    local seasonEpisodes = {26, 26, 13, 26, 26, 26, 26, 27, 32}
    local seasonEpisodesPonyLife = {26}
 
    local gs = tonumber(args.gs)
    local ponyLife = false
    if mw.text.trim(args.PonyLife or '') ~= '' then
        ponyLife = true
    end
 
    local cumulativeEpisodes = {}
    local cumulativeEpisodesPonyLife = {}
    local result
 
    --Generate cumulative count of episodes per season
    for season = 1, #seasonEpisodes do
        cumulativeEpisodes[season] = (cumulativeEpisodes[season-1] or 0) + seasonEpisodes[season]
    end
    for seasonPL = 1, #seasonEpisodesPonyLife do
        cumulativeEpisodesPonyLife[seasonPL] = (cumulativeEpisodesPonyLife[seasonPL-1] or 0) + seasonEpisodesPonyLife[seasonPL]
    end
 
    if gs then
        local cumulative = cumulativeEpisodes
        if ponyLife then cumulative = cumulativeEpisodesPonyLife end
 
        for getseason = 1, #cumulative do
            if (cumulative[getseason-1] or 0) < gs and gs < cumulative[getseason] + 1 then
                result = getseason
                break
            end
        end
 
        if not result then
            result = '<span class="error">Invalid episode number</span>'
        elseif args[1] then
           local spell = {'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'}
           result = spell[result]
        end
    else
        local count = {}
        if args[2] then
            if ponyLife then
                count = cumulativeEpisodesPonyLife
            else
                count = cumulativeEpisodes
            end
        else
            if ponyLife then
                count = seasonEpisodesPonyLife
            else
                count = seasonEpisodes
            end
        end
        result = count[tonumber(args[1])] or 0
    end
 
    return tostring(result)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.