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) -- error message if code doesn't exist; otherwise, get the full episode string if (epCode == '0x00' and isempty(vod)) or isempty(ep) then return frame:preprocess("Undefined Episode ") 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 eptimeString = string.gsub(		eptimeString,		'invalid timecode',		'Invalid Timecode ')

-- handle cite local supCite = mw.html.create('sup') supCite :wikitext("[citation needed]") if not isempty(cite) then local citeCategory = "" 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

return p