Module:Live song: Difference between revisions
MusikAnimal (talk | contribs) No edit summary |
MusikAnimal (talk | contribs) No edit summary |
||
(35 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p._entry(name, title, note, cover, tease, abandoned) | 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 = '"' | local out = '"' | ||
if cover ~= '' | 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 | out = out .. name | ||
else | else | ||
Line 11: | Line 54: | ||
end | end | ||
else | else | ||
out = out .. | out = out .. link(name, title) | ||
end | end | ||
Line 25: | Line 60: | ||
if cover ~= '' then | if cover ~= '' then | ||
out = out .. ' | out = out .. '[' .. cover .. '] ' | ||
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> ' | |||
elseif tease ~= '' then | elseif tease ~= '' then | ||
out = out .. '(tease) ' | out = out .. '<span style="color:gray">(tease)</span> ' | ||
elseif abandoned ~= '' then | elseif abandoned ~= '' then | ||
out = out .. '(abandoned) ' | out = out .. '<span style="color:gray">(abandoned)</span> ' | ||
end | |||
if piano ~= '' then | |||
out = out .. '<span style="color:gray">(piano)</span> ' | |||
elseif acoustic ~= '' then | |||
out = out .. '<span style="color:gray">(acoustic)</span> ' | |||
end | end | ||
if note ~= '' then | if note ~= '' then | ||
out = out .. '(' .. note .. ')' | 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 .. "<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 50: | Line 121: | ||
local tease = frame.args[5] | local tease = frame.args[5] | ||
local abandoned = frame.args[6] | local abandoned = frame.args[6] | ||
return p._entry(name, title, note, cover, tease, abandoned) | 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 | 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 .. '" '
if cover ~= '' then
out = out .. '[' .. cover .. '] '
end
if vip ~= '' then
out = out .. '(VIP) '
end
if prerecorded ~= '' then
out = out .. '(prerecorded) '
elseif tease ~= '' and abandoned ~= '' then
out = out .. '<span style="color:gray">(tease / abandoned)</span> '
elseif tease ~= '' then
out = out .. '<span style="color:gray">(tease)</span> '
elseif abandoned ~= '' then
out = out .. '<span style="color:gray">(abandoned)</span> '
end
if piano ~= '' then
out = out .. '<span style="color:gray">(piano)</span> '
elseif acoustic ~= '' then
out = out .. '<span style="color:gray">(acoustic)</span> '
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 .. "<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