Module:Ep time

local p = {} -- function to create and format the reference function p.epTime(frame) -- receiving parameters local ep = frame.args["ep"] or "" local part = frame.args["part"] or nil local vod = frame.args["vod"] or nil local startTime = frame.args[1] or "" local endTime = frame.args[2] or nil local cite = frame.args["cite"] or nil local hideep = frame.args["hideep"] or nil local noShow = frame.args["noShow"] or nil

-- convert the input into the standardized epCode local epMatcher = require('Module:Ep/Matcher') local epCode = epMatcher.matchCode(ep) local title = mw.title.getCurrentTitle local namespace = title.namespace local subpageText = title.subpageText local errorMsg local category -- appropriate error message if code doesn't exist; otherwise, get the full episode string if (epCode == '0x00' and isempty(vod)) or isempty(ep) then local args = frame:getParent.args local vodCheck = false for key, value in pairs(args) do       	if tostring(key):find('http') then vodCheck = true break end end if startTime:find('http') or endTime:find('http') then vodCheck = true end if vodCheck then errorMsg = "Custom episode missing 'vod=' label for url " category = getErrorCategory("Category:Ep times with unlabeled custom vods", namespace, subpageText) else errorMsg = "Undefined Episode " category = getErrorCategory("Category:Ep times missing episode parameter", namespace, subpageText) end return errorMsg .. category

end

-- get YouTube URL from Module:Ep/YTURLSwitcher/URLs local ytURL = mw.loadData('Module:Ep/YTURLSwitcher/URLs') local url if not isempty(vod) then url = vod elseif not isempty(part) then url = ytURL[epCode .. part] else url = ytURL[epCode] or ytURL["default"] end

-- get formatted episode info (unless hideep) local epInfo local epRef = require('Module:Ep ref') if isempty(hideep) and epCode ~= '0x00' then epInfo = epRef.epForRef(epCode, noShow) if not isempty(part) then epInfo = epInfo .. ", part " .. part .. ',' end elseif epCode == '0x00' and isempty(hideep) then epInfo = ep   else epInfo = '' end -- format timestamp if not isempty(startTime) then startTime = epRef.formatTimestamp(startTime) end -- get wikilinked timestamped YouTube URL local epTimestamp if not isempty(url) and not isempty(startTime) then epTimestamp = epRef.buildLinkedTimestamp(url, startTime) else epTimestamp = startTime end local eptimeString = epTimestamp -- add endTime if not isempty(endTime) then endTime = epRef.formatTimestamp(endTime) eptimeString = epTimestamp .. ' to ' .. endTime end -- prepend episode info if isempty(hideep) then if not isempty(endTime) then eptimeString = epInfo .. ' from ' .. eptimeString elseif not isempty(startTime) then eptimeString = epInfo .. ' at ' .. eptimeString else eptimeString = epInfo end end

-- +error msg and cat if timestring has invalid timecodes errorMsg = 'Invalid Timecode ' category = getErrorCategory('Category:Ep times with invalid timecode calls', namespace, subpageText) eptimeString = string.gsub(		eptimeString,		'invalid timecode',		errorMsg .. category)

-- handle cite local supCite = mw.html.create('sup') supCite :wikitext("[citation needed]") local citeCategory if not isempty(cite) then citeCategory = getErrorCategory("Category:Articles needing citations/" .. epCode, namespace, subpageText) eptimeString = eptimeString .. tostring(supCite) .. citeCategory end return eptimeString end

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

-- for including error categories to only certain namespaces function getErrorCategory(category, namespace, subpageText) -- in article namespace, add page to article maintenance category if namespace == 0 then category = "" .. category .. "" -- in a testing space, print out the error on the page itself elseif subpageText == 'test' or subpageText == 'testcases' then category = ' would be in ' .. category .. ' ' -- if it's not a test page, don't add to category else category = '' end return category end

return p