Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Video citation: Difference between revisions

From ProleWiki, the proletarian encyclopedia
(Very rough sketch of YouTube citation template)
 
(Adding Odysee and Vimeo links)
 
(14 intermediate revisions by the same user not shown)
Line 15: Line 15:
local Channel = parent.args.channel
local Channel = parent.args.channel
local Date = parent.args['date']
local Date = parent.args['date']
local Timestamp = parent.args.timestamp
local Quote = parent.args.quote
local URL = parent.args.url
local URL = parent.args.url
local ArchiveURL = parent.args['archive-url']
local ArchiveDate = parent.args['archive-date']
local Retrieved = parent.args.retrieved


local first_part = ''
local first_part = ''
local second_part = ''
local second_part = ''
local third_part = ''
local platform = ''
if is_set(URL) then
local linkDomain = URL:match("(%a+.%a+)/")
-- YouTube links and Odysee use the same logic for links with timestamps, so they are treated withing the same code block
if linkDomain == 'youtube.com' or linkDomain == 'youtu.be' or linkDomain == 'odysee.com' then
-- Differentiating between links
if linkDomain == 'youtube.com' or linkDomain == 'youtu.be' then
platform = '[[YouTube]]'
-- Only YouTube and Odysee get to this point, so the only one left is Odysee
else
platform = 'Odysee'
end
-- Checks if the youtube link has a timestamp
local extTimestamp = URL:match("?t=(%d+)")
if is_set(extTimestamp) then
-- Extracts seconds, minutes and hours from timestamp
local second = extTimestamp%60
local minute = math.floor(extTimestamp/60)%60
local hour = math.floor(minute/60)
local timestampString = second
timestampString = string.format("%02d", minute) .. ":" .. timestampString
-- Display hours only if it's larger than 0
if hour>0 then
timestampString = string.format("%02d", hour) .. ":" .. timestampString
end
second_part = second_part .. " (" .. timestampString .. ")"
end
elseif linkDomain == 'vimeo.com' then
platform = 'Vimeo'
elseif linkDomain == 'dailymotion.com' then
platform = 'DailyMotion'
end
end
if is_set (Quote) then
Quote = string.gsub(Quote,"\n","<br>")
Quote = "“" .. Quote .. "”"
local div = mw.html.create ('div')
div
:attr("style", "width:80%; margin-left:10%;")
:wikitext(Quote)
local br = mw.html.create ('br', selfClosing)
first_part = italics(tostring(div)) .. tostring(br) .. first_part
end


if is_set(Channel) then
if is_set(Channel) then
Line 27: Line 79:
if is_set(Title) then
if is_set(Title) then
if is_set(URL) then
if is_set(URL) then
Title = '[' .. URL .. " " .. Title .. ']'
Title = '[' .. URL .. " " .. '"' .. Title .. '"' .. ']'
end
end
second_part = second_part .. italics(Title)
second_part = Title .. second_part
end
end
if is_set(Date) then
if is_set(Date) then
if is_set(Channel) then
if is_set(Channel) then
first_part = first_part .. '(' .. Date .. ')'
first_part = first_part .. ' (' .. Date .. ')'
else
else
second_part = second_part .. '(' .. Date .. ')'
second_part = second_part .. ' (' .. Date .. ')'
end
end
if is_set(platform) then
second_part = second_part .. ". ''" .. platform .. "''"
end
if is_set(ArchiveURL) then
if is_set(ArchiveDate) then
third_part = " [" .. ArchiveURL .. " " .. "Archived" .. "]" .. " " .. " from the original on" .. " " .. ArchiveDate .. "."
else
third_part = " [" .. ArchiveURL .. " " .. "Archived" .. "]" .. " from the original."
end
end
end
if is_set (Retrieved) then
third_part = third_part .. " Retrieved" .. " " .. Retrieved
end
-- Concatenating all strings and adding the dot punctuations at the end of every part if they are set
local finalString = ''
if is_set(first_part) then
finalString = first_part .. "."
end
if is_set(second_part) then
finalString = finalString .. " " .. second_part .. "."
end
if is_set(third_part) then
finalString = finalString .. " " .. third_part .. "."
end
end
return first_part .. ". " .. second_part .. "''YouTube''"
return finalString
end
end
return p
return p

Latest revision as of 23:59, 28 April 2024

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 Quote = parent.args.quote
	local URL = parent.args.url
	local ArchiveURL = parent.args['archive-url']
	local ArchiveDate = parent.args['archive-date']
	local Retrieved = parent.args.retrieved

	local first_part = ''
	local second_part = ''
	local third_part = ''
	
	local platform = ''
	
	if is_set(URL) then
		local linkDomain = URL:match("(%a+.%a+)/")
		-- YouTube links and Odysee use the same logic for links with timestamps, so they are treated withing the same code block
		if linkDomain == 'youtube.com' or linkDomain == 'youtu.be' or linkDomain == 'odysee.com' then
			-- Differentiating between links
			if linkDomain == 'youtube.com' or linkDomain == 'youtu.be' then
				platform = '[[YouTube]]'
				-- Only YouTube and Odysee get to this point, so the only one left is Odysee
				else
					platform = 'Odysee'
			end
			
			-- Checks if the youtube link has a timestamp
			local extTimestamp = URL:match("?t=(%d+)")
			if is_set(extTimestamp) then
				-- Extracts seconds, minutes and hours from timestamp
				local second = extTimestamp%60
				local minute = math.floor(extTimestamp/60)%60
				local hour = math.floor(minute/60)
				
				local timestampString = second
				timestampString = string.format("%02d", minute) .. ":" .. timestampString
				-- Display hours only if it's larger than 0
				if hour>0 then
					timestampString = string.format("%02d", hour) .. ":" .. timestampString
				end
				second_part = second_part .. " (" .. timestampString .. ")"
			end
		elseif linkDomain == 'vimeo.com' then
			platform = 'Vimeo'
		elseif linkDomain == 'dailymotion.com' then
			platform = 'DailyMotion'
		end
	end

	if is_set (Quote) then
		Quote = string.gsub(Quote,"\n","<br>")
		Quote = "“" .. Quote .. "”"
		local div = mw.html.create ('div')
		div
		:attr("style", "width:80%; margin-left:10%;")
		:wikitext(Quote)
		local br = mw.html.create ('br', selfClosing)
		first_part = italics(tostring(div)) .. tostring(br) .. first_part
	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 = Title .. second_part 
	end
	
	if is_set(Date) then
		if is_set(Channel) then
			first_part = first_part .. ' (' .. Date .. ')'
		else
			second_part = second_part .. ' (' .. Date .. ')'
		end
	end
	
	if is_set(platform) then
		second_part = second_part .. ". ''" .. platform .. "''"
	end
	
	if is_set(ArchiveURL) then
		if is_set(ArchiveDate) then
			third_part = " [" .. ArchiveURL .. " " .. "Archived" .. "]" .. " " .. " from the original on" .. " " .. ArchiveDate .. "."
			else
				third_part = " [" .. ArchiveURL .. " " .. "Archived" .. "]" .. " from the original."
		end
	end
			
	if is_set (Retrieved) then
		third_part = third_part .. " Retrieved" .. " " .. Retrieved
	end
	
	-- Concatenating all strings and adding the dot punctuations at the end of every part if they are set
	local finalString = ''
	if is_set(first_part) then
		finalString = first_part .. "."
	end
	if is_set(second_part) then
		finalString = finalString .. " " .. second_part .. "."
	end
	if is_set(third_part) then
		finalString = finalString .. " " .. third_part .. "."
	end
	
return finalString
end
return p