Module:Soundtrack/motifs
Helper submodule to load and cache motif data for frequent reuse.
--- Helper submodule to load and cache motif data for frequent reuse.
-- @file motifs
-- @author [[User:KockaAdmiralac|KockaAdmiralac]]
require('strict')
local motifs = {}
local motifsPage = mw.title.new('Leitmotifs')
if not motifsPage.exists then
error('Fatal error: Motifs page does not exist!')
end
local currentMotif
local major = true
for line in mw.text.gsplit(motifsPage:getContent(), '\n', true) do
local s = mw.ustring.sub(line, 1, 3)
if s == '== ' then
local title = mw.ustring.sub(line, 4, -4)
if title ~= 'Minor Leitmotifs' then
currentMotif = title
motifs[title] = {major = true}
end
elseif s == '===' then
currentMotif = mw.ustring.sub(line, 5, -5)
motifs[currentMotif] = {major = false}
elseif s == '* \'' and currentMotif and currentMotif ~= 'Other' then
local linkContent = mw.ustring.match(line, '%* \'\'%[%[([^%]]+)%]%]\'\'')
if linkContent then
local trackTitle = mw.text.split(linkContent, '|', true)[1]
table.insert(motifs[currentMotif], trackTitle)
end
end
end
return motifs