Module:Live song

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 .. '" '

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

if vip ~= '' then out = out .. '(VIP) ' end if prerecorded ~= '' then out = out .. '(prerecorded) ' elseif tease ~=  and abandoned ~=  then out = out .. ' (tease / abandoned) ' elseif tease ~= '' then out = out .. ' (tease) ' elseif abandoned ~= '' then out = out .. ' (abandoned) ' end

if piano ~= '' then out = out .. ' (piano) ' elseif acoustic ~= '' then out = out .. ' (acoustic) ' end

if note ~= '' then out = out .. '(' .. note .. ') ' end

if length ~= '' then out = out .. '[' .. length .. '] '	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 .. " (live debut) " elseif debut_status == 2 then out = out .. " (final performance) " elseif debut_status == 3 then out = out .. " (only performance) " 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(frame) local str = frame.args[1] 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.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