Module:Ep time

local p = {} -- function to create and format the reference function p.epTime(frame) -- ep=|part=|vod=|START|END|cite=|hideep= -- 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

-- convert the input into the standardized epCode local epMatcher = require('Module:Ep/Matcher') 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(" ") 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 ref2') if isempty(hideep) and epCode ~= '0x00' then epInfo = epRef.epForRef(epCode) 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 eptimeString = epInfo if not isempty(endTime) then eptimeString = epInfo .. ' from ' .. eptimeString elseif not isempty(startTime) then eptimeString = epInfo .. ' at ' .. eptimeString end end return eptimeString end

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

return p