Module:Live song: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
No edit summary
 
(28 intermediate revisions by the same user not shown)
Line 13: Line 13:
end
end


function p._entry(name, title, note, cover, tease, abandoned, length)
local function live_debut(name)
local page_title = mw.title.getCurrentTitle().text
local show_date = p._parse_date(page_title)
local cargo = mw.ext.cargo
local debut = cargo.query(
'live_songs, ',
'MIN(date)=min_date, MAX(date)=max_date, DATE_FORMAT(NOW(), "%Y-%m-%d")=today, DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), "%Y-%m-%d")=yesterday',
{
where = 'name = "' .. name .. '" AND abandoned = 0 AND soundcheck = 0 AND tease = 0'
}
)
 
if next(debut) == nil then
return false
end
 
-- 1 = live debut, 2 = final performance, 3 = only performance
if debut[1]['min_date'] == show_date then
if debut[1]['max_date'] == show_date then
return 3
end
return 1
elseif debut[1]['max_date'] == show_date and debut[1]['today'] ~= show_date and debut[1]['yesterday'] ~= show_date then
return 2
end
end
 
function p._entry(name, title, note, cover, tease, abandoned, length, acoustic, piano, soundcheck, prerecorded, vip, force_tour_status)
local out = '"'
local out = '"'


if cover ~= '' and (tease ~= '' or abandoned ~= '') then
if cover ~= '' or tease ~= '' or abandoned ~= '' then
local mw_title = mw.title.makeTitle(0, name)
local mw_title = mw.title.makeTitle(0, name)


if mw_title.exists then
if mw_title.exists then
out = out .. link(name, title)
out = out .. link(name, title)
elseif title == '' then
out = out .. name
else
else
out = out .. name
out = out .. title
end
end
else
else
Line 34: Line 63:
end
end


if tease ~= '' and abandoned ~= '' then
if vip ~= '' then
out = out .. '(tease / abandoned) '
out = out .. '(VIP) '
end
if prerecorded ~= '' then
out = out .. '(prerecorded) '
elseif tease ~= '' and abandoned ~= '' then
out = out .. '<span style="color:gray">(tease / abandoned)</span>&nbsp;'
elseif tease ~= '' then
elseif tease ~= '' then
out = out .. '(tease)&nbsp;'
out = out .. '<span style="color:gray">(tease)</span>&nbsp;'
elseif abandoned ~= '' then
elseif abandoned ~= '' then
out = out .. '(abandoned)&nbsp;'
out = out .. '<span style="color:gray">(abandoned)</span>&nbsp;'
end
 
if piano ~= '' then
out = out .. '<span style="color:gray">(piano)</span>&nbsp;'
elseif acoustic ~= '' then
out = out .. '<span style="color:gray">(acoustic)</span>&nbsp;'
end
end


Line 45: Line 85:
out = out .. '(' .. note .. ')&nbsp;'
out = out .. '(' .. note .. ')&nbsp;'
end
end
 
if length ~= '' then
if length ~= '' then
out = out .. '[' .. length .. ']'
out = out .. '[' .. length .. ']&nbsp;'
end
 
if not(soundcheck ~= '') then
local debut_status = 0
if force_tour_status == 'debut' then
debut_status = 1
elseif force_tour_status == 'final' then
debut_status = 2
elseif force_tour_status == 'only' then
debut_status = 3
elseif force_tour_status ~= 'none' then
debut_status = live_debut(name)
end
 
if debut_status == 1 then
out = out .. "<span style='color:green; font-variant:small-caps'>(live debut)</span>"
elseif debut_status == 2 then
out = out .. "<span style='color:#9d2b2b; font-variant:small-caps'>(final performance)</span>"
elseif debut_status == 3 then
out = out .. "<span style='color:#91681f; font-variant:small-caps'>(only performance)</span>"
end
end
end


Line 61: Line 122:
local abandoned = frame.args[6]
local abandoned = frame.args[6]
local length = frame.args[7]
local length = frame.args[7]
return p._entry(name, title, note, cover, tease, abandoned, length)
local acoustic = frame.args[8]
local piano = frame.args[9]
local soundcheck = frame.args[10]
local prerecorded = frame.args[11]
local vip = frame.args[12]
local force_tour_status = frame.args[13]
return p._entry(name, title, note, cover, tease, abandoned, length, acoustic, piano, soundcheck, prerecorded, vip, force_tour_status)
end
 
function p._parse_date(title)
return string.match(title, "%d%d%d%d%-%d%d%-%d%d")
end
 
function p.parse_date(frame)
local name = frame.args[1]
return p._parse_date(name)
end
 
function p._time_to_seconds(str)
local hours, minutes, seconds = string.match(str, '(%d+):(%d%d):(%d%d)')
if hours == nil then
hours = 0
minutes, seconds = string.match(str, '(%d+):(%d%d)')
end
 
return (60 * 60 * hours) + (60 * minutes) + seconds
end
 
function p.time_to_seconds(frame)
local str = frame.args[1]
return p._time_to_seconds(str)
end
 
function p.seconds_to_time(frame)
local given = frame.args[1]
local hours = math.floor(math.fmod(given, 86400) / 3600)
local minutes = math.floor(math.fmod(given, 3600) / 60)
local seconds = math.floor(math.fmod(given, 60))
 
if hours > 0 then
return string.format("%d:%02d:%02d", hours, minutes, seconds)
elseif minutes > 0 then
return string.format("%d:%02d", minutes, seconds)
elseif seconds > 0 then
return string.format("0:%02d", seconds)
else
return '0:00'
end
end
end


return p
return p

Latest revision as of 22:12, 3 August 2023

Documentation for this module may be created at Module:Live song/doc

local p = {}

local function link(name, title)
	local out = '[['

	if title == '' then
		out = out .. name
	else
		out = out .. name .. '|' .. title
	end

	return out .. ']]'
end

local function live_debut(name)
	local page_title = mw.title.getCurrentTitle().text
	local show_date = p._parse_date(page_title)
	local cargo = mw.ext.cargo
	local debut = cargo.query(
		'live_songs, ',
		'MIN(date)=min_date, MAX(date)=max_date, DATE_FORMAT(NOW(), "%Y-%m-%d")=today, DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), "%Y-%m-%d")=yesterday',
		{
			where = 'name = "' .. name .. '" AND abandoned = 0 AND soundcheck = 0 AND tease = 0'
		}
	)

	if next(debut) == nil then
		return false
	end

	-- 1 = live debut, 2 = final performance, 3 = only performance
	if debut[1]['min_date'] == show_date then
		if debut[1]['max_date'] == show_date then
			return 3
		end
		return 1
	elseif debut[1]['max_date'] == show_date and debut[1]['today'] ~= show_date and debut[1]['yesterday'] ~= show_date then
		return 2
	end
end

function p._entry(name, title, note, cover, tease, abandoned, length, acoustic, piano, soundcheck, prerecorded, vip, force_tour_status)
	local out = '"'

	if cover ~= '' or tease ~= '' or abandoned ~= '' then
		local mw_title = mw.title.makeTitle(0, name)

		if mw_title.exists then
			out = out .. link(name, title)
		elseif title == '' then
			out = out .. name
		else
			out = out .. title
		end
	else
		out = out .. link(name, title)
	end

	out = out .. '"&nbsp;'

	if cover ~= '' then
		out = out .. '&#91;' .. cover .. '&#93;&nbsp;'
	end

	if vip ~= '' then
		out = out .. '(VIP)&nbsp;'
	end
	if prerecorded ~= '' then
		out = out .. '(prerecorded)&nbsp;'
	elseif tease ~= '' and abandoned ~= '' then
		out = out .. '<span style="color:gray">(tease / abandoned)</span>&nbsp;'
	elseif tease ~= '' then
		out = out .. '<span style="color:gray">(tease)</span>&nbsp;'
	elseif abandoned ~= '' then
		out = out .. '<span style="color:gray">(abandoned)</span>&nbsp;'
	end

	if piano ~= '' then
		out = out .. '<span style="color:gray">(piano)</span>&nbsp;'
	elseif acoustic ~= '' then
		out = out .. '<span style="color:gray">(acoustic)</span>&nbsp;'
	end

	if note ~= '' then
		out = out .. '(' .. note .. ')&nbsp;'
	end

	if length ~= '' then
		out = out .. '[' .. length .. ']&nbsp;'
	end

	if not(soundcheck ~= '') then
		local debut_status = 0
		if force_tour_status == 'debut' then
			debut_status = 1
		elseif force_tour_status == 'final' then
			debut_status = 2
		elseif force_tour_status == 'only' then
			debut_status = 3
		elseif force_tour_status ~= 'none' then
			debut_status = live_debut(name)
		end

		if debut_status == 1 then
			out = out .. "<span style='color:green; font-variant:small-caps'>(live debut)</span>"
		elseif debut_status == 2 then
			out = out .. "<span style='color:#9d2b2b; font-variant:small-caps'>(final performance)</span>"
		elseif debut_status == 3 then
			out = out .. "<span style='color:#91681f; font-variant:small-caps'>(only performance)</span>"
		end
	end

	return out
end

function p.entry(frame)
	local name = frame.args[1]
	local title = frame.args[2]
	local note = frame.args[3]
	local cover = frame.args[4]
	local tease = frame.args[5]
	local abandoned = frame.args[6]
	local length = frame.args[7]
	local acoustic = frame.args[8]
	local piano = frame.args[9]
	local soundcheck = frame.args[10]
	local prerecorded = frame.args[11]
	local vip = frame.args[12]
	local force_tour_status = frame.args[13]
	return p._entry(name, title, note, cover, tease, abandoned, length, acoustic, piano, soundcheck, prerecorded, vip, force_tour_status)
end

function p._parse_date(title)
	return string.match(title, "%d%d%d%d%-%d%d%-%d%d")
end

function p.parse_date(frame)
	local name = frame.args[1]
	return p._parse_date(name)
end

function p._time_to_seconds(str)
	local hours, minutes, seconds = string.match(str, '(%d+):(%d%d):(%d%d)')
	if hours == nil then
		hours = 0
		minutes, seconds = string.match(str, '(%d+):(%d%d)')
	end

	return (60 * 60 * hours) + (60 * minutes) + seconds
end

function p.time_to_seconds(frame)
	local str = frame.args[1]
	return p._time_to_seconds(str)
end

function p.seconds_to_time(frame)
	local given = frame.args[1]
	local hours = math.floor(math.fmod(given, 86400) / 3600)
	local minutes = math.floor(math.fmod(given, 3600) / 60)
	local seconds = math.floor(math.fmod(given, 60))

	if hours > 0 then
		return string.format("%d:%02d:%02d", hours, minutes, seconds)
	elseif minutes > 0 then
		return string.format("%d:%02d", minutes, seconds)
	elseif seconds > 0 then
		return string.format("0:%02d", seconds)
	else
		return '0:00'
	end
end

return p