Module:Video citation: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Implementing timestamp)
m (Added if to external timestamp to prevent errors)
Line 24: Line 24:
if is_set(URL) then
if is_set(URL) then
extTimestamp = URL:match("?t=(%d+)")
extTimestamp = URL:match("?t=(%d+)")
local second = extTimestamp%60
if is_set(extTimestamp) then
local minute = math.floor(extTimestamp/60)
local second = extTimestamp%60
local hour = math.floor(minute/60)
local minute = math.floor(extTimestamp/60)
extTimestamp = second
local hour = math.floor(minute/60)
if minute>0 then
extTimestamp = second
extTimestamp = minute .. ":" .. extTimestamp
if minute>0 then
else
extTimestamp = minute .. ":" .. extTimestamp
extTimestamp = "00:" .. extTimestamp
else
end
extTimestamp = "00:" .. extTimestamp
if hour>0 then
end
extTimestamp = hour .. ":" .. extTimestamp
if hour>0 then
extTimestamp = hour .. ":" .. extTimestamp
end
end
end
end
end

Revision as of 02:36, 5 October 2022

local p = {}

local function is_set (var)
	return not (var == nil or var == '');
end

local function italics (var)
	return "<i>" .. var .. "</i>"
end

function p.cite(frame)
	local parent = frame:getParent()
	
	local Title = parent.args.title
	local Channel = parent.args.channel
	local Date = parent.args['date']
	local Timestamp = parent.args.timestamp
	local URL = parent.args.url

	local first_part = ''
	local second_part = ''
	
	local extTimestamp = ''
	if is_set(URL) then
		extTimestamp = URL:match("?t=(%d+)")
		if is_set(extTimestamp) then
			local second = extTimestamp%60
			local minute = math.floor(extTimestamp/60)
			local hour = math.floor(minute/60)
			extTimestamp = second
			if minute>0 then
				extTimestamp = minute .. ":" .. extTimestamp
				else
					extTimestamp = "00:" .. extTimestamp
			end
			if hour>0 then
				extTimestamp = hour .. ":" .. extTimestamp
			end
		end
	end

	if is_set(Channel) then
		first_part = first_part .. Channel
	end
	
	if is_set(Title) then
		if is_set(URL) then
			Title = '[' .. URL .. " " .. Title .. ']'
		end
		second_part = second_part .. '"' .. Title .. '"'
	end
	
	if is_set(extTimestamp) then
		second_part = second_part .. " (" .. extTimestamp .. ")"
		elseif is_set(Timestamp) then
			second_part = second_part .. " (" .. Timestamp .. ")"
	end
	
	if is_set(Date) then
		if is_set(Channel) then
			first_part = first_part .. ' (' .. Date .. ')'
		else
			second_part = second_part .. ' (' .. Date .. ')'
		end
	end
	
return first_part .. ". " .. second_part .. ". " .. "''[[YouTube]]''"
end
return p