Module:Ep time/sandbox

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/sandbox') 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/sandbox') 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) epTimeCodes = string.gsub(		epTimeCodes,		'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) 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) if namespace == 0 then category = "" .. category .. "" elseif subpageText == 'test' or subpageText == 'testcases' then category = category else category = '' end return category end

return p