local hlist = require('Module:List')local exception = mw.loadData('Module:Sandbox/Premeditated/WDTracklist/exception')
local p = local allCredits =
local function parseDate(totalSeconds) local seconds = math.fmod(tonumber(totalSeconds),60) local minutes = math.floor(tonumber(totalSeconds) / 60) local hours = math.floor(minutes / 60) return string.format("%d:%02d", minutes, seconds)end
local function TableConcat(t1,t2) for i=1,#t2 do t1[#t1+1] = t2[i] end return t1end
local function getOrder(qualifiers) local out = nil if qualifiers then local qualifierID = "P1545" -- sorting order / rank / series ordinal if qualifiers[qualifierID] then for k, v in pairs(qualifiers[qualifierID]) do if v.snaktype
local function has_value (tab, val) for index, value in ipairs(tab) do if value
return falseend
local function getWDName(id, pid) local num = 0 local name = if id["claims"][pid] and not id["claims"][pid][2] then local famNameItem = mw.wikibase.getEntity(id["claims"][pid][1]["mainsnak"]["datavalue"]["value"]['id']) table.insert(name, famNameItem:getLabel) return name end for index, claims in pairs(id["claims"][pid]) do local famNameItem = mw.wikibase.getEntity(claims["mainsnak"]["datavalue"]["value"]['id']) if claims.qualifiers then name[tonumber(getOrder(claims.qualifiers))] = famNameItem:getLabel else table.insert(name, famNameItem:getLabel) end end if name then return name end return end
local function getName(id) if id["claims"] and id["claims"]["P1477"] and id["claims"]["P1477"][1] then for index, claims in pairs(id["claims"]["P1477"]) do if claims["mainsnak"]["datavalue"]["value"]["language"]
local function getFamilyName(label) local words = local suffix = for word in label:gmatch("[%w\128-\244]+") do table.insert(words, word) end if has_value(suffix, words[#words]:lower) then return words[#words - 1] .. ' ' .. words[#words] .. '.' end return words[#words]end
local function findLast(haystack, needle) local i = haystack:match(".*"..needle.."") if i
local function replace_char(pos, str, r) return str:sub(1, pos-1) .. r .. str:sub(pos+1)end
local function getFeature(performer, frame) local feat = for index22, table22 in pairs(performer) do if table22["qualifiers"] and table22["qualifiers"]["P3831"] and table22["qualifiers"]["P3831"][1]["datavalue"]["value"]["id"] then for index23, table23 in pairs(table22["qualifiers"]["P3831"]) do if table23["datavalue"]["value"]["id"]
nil then return text else return replace_char(last, text, ' and') end end return end
local function getCredits(frame, credits) local credit =
for index, we in pairs(credits) do if not we["mainsnak"]["datavalue"] then return end local id = mw.wikibase.getEntity(we["mainsnak"]["datavalue"]["value"]["id"]) if has_value(allCredits, id:getLabel) then local name = getName(id) if has_value(exception['name_exception_qid'], id:getId) or has_value(exception['name_exception'], id:getLabel) then table.insert(credit, id:getLabel) else table.insert(credit, getFamilyName(name)) end else if id:getSitelink ~= nil then table.insert(credit, frame:preprocess("" .. getName(id) .. "")) else table.insert(credit, getName(id)) end table.insert(allCredits, id:getLabel) end end return hlist.makeList('horizontal', credit)end
function p.parseNames(frame) if mw.wikibase.getEntity
then return end local wikiEntity = mw.wikibase.getEntity(frame.args[1]) or mw.wikibase.getEntity if wikiEntity
then return end local funcArgs = for index, table in pairs(wikiEntity:getAllStatements('tracklist')) do local trackEntity = mw.wikibase.getEntity(table["mainsnak"]["datavalue"]["value"]["id"]) local order = tonumber(getOrder(table.qualifiers)) or index if trackEntity:getSitelink
false then funcArgs["title" .. order] = trackEntity:getLabel end else funcArgs["title" .. order] = frame:preprocess("" .. trackEntity:getLabel .. "") end if trackEntity["claims"]["P2047"] ~= nil then funcArgs["length" .. order] = parseDate(tonumber(trackEntity["claims"]["P2047"][1]["mainsnak"]["datavalue"]["value"]["amount"])) end if trackEntity["claims"]["P676"] ~= nil then funcArgs["writer" .. order] = getCredits(frame, trackEntity["claims"]["P676"]) end if trackEntity["claims"]["P175"] ~= nil then funcArgs["note" .. order] = getFeature(trackEntity:getAllStatements('performer'), frame) end if trackEntity["claims"]["P162"] ~= nil then funcArgs["extra_column"] = 'Producer(s)' funcArgs["extra" .. order] = getCredits(frame, trackEntity["claims"]["P162"]) end if table["qualifiers"] ~= nil then if table["qualifiers"]["P2047"] ~= nil then local timeInSeconds = table["qualifiers"]["P2047"][1]["datavalue"]["value"]["amount"] funcArgs["length" .. order] = parseDate(timeInSeconds) end end end if wikiEntity['claims']['P2047'] ~= nil then local totalTime = tonumber(wikiEntity:getAllStatements('duration')[1]["mainsnak"]["datavalue"]["value"]["amount"]) funcArgs["total_length"] = parseDate(totalTime) end return frame:expandTemplate end
return p