Module:ArtistSong:修订间差异

来自Arcaea中文维基
(发布版本)
(Unicode序)
 
(未显示4个用户的29个中间版本)
第1行: 第1行:
p={}
local p = {}
local CAL = mw.loadJsonData 'Template:ComplexArtistsList.json'
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local trans = mw.loadJsonData 'Template:Transition.json'
local SL = mw.loadJsonData 'Template:Song Length.json'
 
local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
local data = require "Module:Arcaea Data"
local data = require 'Module:Arcaea Data'
local trans = mw.loadJsonData 'Template:Transition.json'
local CL = require 'Module:ConvertLink'
local CL = require 'Module:ConvertLink'
local SL = mw.loadJsonData 'Template:Song Length.json'
local tt = require 'Module:TableTools'


local queryMO = data.allSongInformation("id", "mobile")
local lang = mw.language.getContentLanguage()
local queryNS = data.allSongInformation("id", "ns")


local NotJaName = {[' 旅人E']='Tabibito E'}
local queryMO = data.allSongInformation('id', 'mobile')
local queryNS = data.allSongInformation('id', 'ns')


-- byd?=>id=>c-artist
local function readList()
local function readList()
   local pickList = {}
local pickList = {}
   local pickListBYD = {}
local pickListBYD = {}
   for _, song in ipairs(mad.listOf('songs', 'mobile')) do
for _, song in ipairs(mad.listOf('songs', 'mobile')) do
   local artist = song.artist
if not song.deleted then
     pickList[song.id] = song.artist
local artist = song.artist
     if song.difficulties[4] and (song.difficulties[4].artist or song.difficulties[4].title_localized) then
pickList[song.id] = song.artist
     local bydArtist = song['difficulties'][4]['artist'] or song.artist
if song.difficulties[4] and (song.difficulties[4].artist or song.difficulties[4].title_localized) then
       pickListBYD[song['id']] = bydArtist
local bydArtist = song['difficulties'][4]['artist'] or song.artist
     end
pickListBYD[song['id']] = bydArtist
   end
end
  
end
   for _, song in ipairs(mad.listOf('songs', 'ns')) do
end
     if not pickList[song.id] and not multiId[song.id] then
 
for _, song in ipairs(mad.listOf('songs', 'ns')) do
if not pickList[song.id] and not trans.multiId[song.id] then
pickList[song.id] = song.artist
pickList[song.id] = song.artist
if song.difficulties[4] and song.difficulties[4].artist or song.difficulties[4].title_localized then
if song.difficulties[4] and song.difficulties[4].artist or song.difficulties[4].title_localized then
     local bydArtist = song['difficulties'][4]['artist'] or song.artist
local bydArtist = song['difficulties'][4]['artist'] or song.artist
pickListBYD[song['id']] = bydArtist
pickListBYD[song['id']] = bydArtist
end
end
第35行: 第39行:
end
end


   return pickList, pickListBYD
return pickList, pickListBYD
end
end


-- groupby: c-artist=>byd?=>[id]
local function convertPick(pickList, pickListBYD)
local function convertPick(pickList, pickListBYD)
   convertList = {}
convertList = {}
   for _id,_ in pairs(pickList) do
for id, artist in pairs(pickList) do
     local artist = pickList[_id]
if not convertList[artist] then convertList[artist] = {} end
     if not convertList[artist] then convertList[artist] = {} end
if not convertList[artist].normal then convertList[artist]['normal'] = {} end
     if not convertList[artist].normal then convertList[artist]['normal'] = {} end
table.insert(convertList[artist]['normal'], id)
     table.insert(convertList[artist]['normal'], _id)
end
   end


   for _id in pairs(pickListBYD) do
for id, artist in pairs(pickListBYD) do
   local artist = pickListBYD[_id]
if not convertList[artist] then convertList[artist] = {} end
   if not convertList[artist] then convertList[artist] = {} end
if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
   if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
table.insert(convertList[artist]['beyond'], id)
   table.insert(convertList[artist]['beyond'], _id)
end
   end


   return convertList
return convertList
end
end


-- n-n map: s-artist=>byd?=>[id]
local zhName = {}
local function genList(convertList)
local function genList(convertList)
-- TODO:既然convertList都闭包了那singleList也可以
local function cate(singleList, cArtist, artist)
local function cate(singleList, cArtist, artist)
local artist = artist or cArtist
local artist = artist or cArtist
if not singleList[artist] then singleList[artist] = {} end
if not singleList[artist] then singleList[artist] = {} end
     if convertList[cArtist].beyond then
if convertList[cArtist].beyond then
       if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
       for _,i in pairs(convertList[cArtist]['beyond']) do
tt.extend(singleList[artist]['beyond'], convertList[cArtist]['beyond'])
       table.insert(singleList[artist]['beyond'],i)
end
       end
if convertList[cArtist].normal then
     end
if not singleList[artist].normal then singleList[artist]['normal'] = {} end
     if convertList[cArtist].normal then
tt.extend(singleList[artist]['normal'], convertList[cArtist]['normal'])
     if not singleList[artist].normal then singleList[artist]['normal'] = {} end
end
       for _,i in pairs(convertList[cArtist]['normal']) do
return singleList
       table.insert(singleList[artist]['normal'],i)
       end
     end
     return singleList
   end
   local singleList = {}
   for cArtist in pairs(convertList) do
     if CAL[cArtist] then
     local artistlist={}
       for _,text in pairs(CAL[cArtist]) do
         if text.link then
           local artist = text['link']
           if not artistlist[artist] then
           singleList = cate(singleList, cArtist, artist)
           artistlist[artist]=1
           end
         end
       end
     else
       singleList = cate(singleList, cArtist)
     end
end
end
   return singleList
 
 
local singleList = {}
for cArtist in pairs(convertList) do
local artistlist = {}
if CALv2[cArtist] then
if CALv2[cArtist].__FullData__ then
for _, text in pairs(CALv2[cArtist].__FullData__) do
if text.link then
local artist = text.link
if not artistlist[artist] then
singleList = cate(singleList, cArtist, artist)
artistlist[artist] = 1
if text.zh then
zhName[artist] = true
end
end
end
end
else
for link in pairs(CALv2[cArtist]) do
local artist = link
if not artistlist[artist] then
singleList = cate(singleList, cArtist, artist)
artistlist[artist] = 1
end
end
end
else
singleList = cate(singleList, cArtist)
end
end
return singleList
end
 
local function isLetter(char)
return char:match '%a' ~= nil
end
end


-- 排序
-- 排序
local function customSort(a, b)
local function customSort(a, b)
   local function isLetter(char)
     return char:match("%a") ~= nil
   end
  
local a1 = a:sub(1, 1)
local a1 = a:sub(1, 1)
local b1 = b:sub(1, 1)
local b1 = b:sub(1, 1)
   local la1 = isLetter(a:sub(1, 1))
local la1 = isLetter(a:sub(1, 1))
   local lb1 = isLetter(b:sub(1, 1))
local lb1 = isLetter(b:sub(1, 1))


   if la1 and not lb1 then
if la1 and not lb1 then
     return true
return true
   elseif lb1 and not la1 then
elseif lb1 and not la1 then
     return false
return false
   elseif string.lower(a1) == string.lower(b1) then
elseif string.lower(a1) == string.lower(b1) then
   local la2 = isLetter(a:sub(2, 2))
local la2 = isLetter(a:sub(2, 2))
   local lb2 = isLetter(b:sub(2, 2))
local lb2 = isLetter(b:sub(2, 2))
   if la2 and not lb2 then
if la2 and not lb2 then
     return true
return true
   elseif lb2 and not la2 then
elseif lb2 and not la2 then
     return false
return false
   else
else
   return string.lower(a) < string.lower(b)
return string.lower(a) < string.lower(b)
   end
end
   else
else
     return string.lower(a) < string.lower(b)
return string.lower(a) < string.lower(b)
   end
end


   return string.lower(a) < string.lower(b)
return string.lower(a) < string.lower(b)
end
end


local function songTitle(id,byd)
local function songTitle(id, byd)
local display
local display
local title = queryMO(id, 'title') or queryNS(id, 'title')
local title = queryMO(id, 'title') or queryNS(id, 'title')
if byd then
if byd then
display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD'
display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD'
else 
else
display = title
display = title
end
end
local res = trans.songNameToDisplayName[title]
local res = trans.songNameToDisplayName[title]
if res then return res..'|'..display end
if res then return res .. '|' .. display end
res = trans.sameName[title]
res = trans.sameName[title]
if res then return res[id]..'|'..display end
if res then return res[id] .. '|' .. display end
if title then return title..'|'..display
if title then
else return id end
return title .. '|' .. display
else
return id
end
end
end


第151行: 第170行:
end
end
bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
if bpm then return bpm 
if bpm then
else return id end
return bpm
else
return nil
end
end
end


第162行: 第184行:
end
end
date = queryMO(id, 'date') or queryNS(id, 'date')
date = queryMO(id, 'date') or queryNS(id, 'date')
if date then return date
if date then return date else return 0 end
else return id end
end
end


第173行: 第194行:
end
end
ver = queryMO(id, 'version') or queryNS(id, 'version')
ver = queryMO(id, 'version') or queryNS(id, 'version')
if ver then return ver
if ver then return ver else return id end
else return id end
end
end


local function songPack(id)
local function songPack(id)
local packid,plat,isNS
local packid, plat, isNS
-- if queryNS(id, 'set') then
-- if queryNS(id, 'set') then
-- packid = queryNS(id, 'set')
-- packid = queryNS(id, 'set')
第186行: 第206行:
packid = queryMO(id, 'set')
packid = queryMO(id, 'set')
else
else
return id
return nil
end
end
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
local packLink = CL.packLink(packName,1,isNS)
local packLink = CL.packLink(packName, 1, isNS)
return packLink
return packLink
end
end
 
local function songLength(id, byd)
if byd then
return SL.beyond[id]
else
return SL.normal[id]
end
end
 
 


function p.main(frame)
function p.main(frame)
local parentArgs = frame:getParent().args
local parentArgs = frame:getParent().args
   local rl, rlb = readList()
local Args = frame.args
   local cl = convertPick(rl, rlb)
 
   local gl = genList(cl)
local rl, rlb = readList()
   rl,rlb,cl = nil
local cl = convertPick(rl, rlb)
   local wikiText = ""
local gl = genList(cl)
rl, rlb, cl = nil


   local a2z = {}
local appendList = Args['appendList']
   local gl2 = {}
if appendList then
for name in pairs(gl) do
local list = mw.text.split(appendList, '\n')
local enName
for _, id in pairs(list) do
if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
local artists = Args[id .. '.' .. 'artist']
enName = frame.args[name .. '.enName'] or name--nil
if artists then
gl2[enName] = gl[name]
local artistList = mw.text.split(artists, '/')
gl2[enName].localName = name
for _, artist in pairs(artistList) do
if NotJaName[name] then
if not gl[artist] then gl[artist] = {} end
gl2[enName].notJa = 1
if not gl[artist].normal then gl[artist].normal = {} end
table.insert(gl[artist].normal, id)
end
end
end
end
end
local render = mw.html.create()
local a2z = {}
local gl2 = {}
for name, artistData in pairs(gl) do
if mw.ustring.match(name, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
artistData.notAllLatin = 1
local notJaName = parentArgs[name .. '.notJaName'] or zhName[name]
if not notJaName then artistData.ja = 1 end
end
artistData.name = name
artistData.enName = parentArgs[name .. '.enName'] or nil
artistData.otherName = parentArgs[name .. '.otherName'] or nil
artistData.description = parentArgs[name .. '.description'] or nil
local sortName = mw.ustring.gsub(name, '[A-Z]+', string.lower)
gl2[sortName] = artistData
table.insert(a2z, sortName)
end
table.sort(a2z)
-- 生成页首
local function alpha()
local ret, cla, cua = {}, string.byte 'a', string.byte 'A'
for i = 0, 25 do
table.insert(ret, {string.char(i + cua), string.char(i + cla)})
end
return ret
end
local menuItems = tt.merge(
{{'#', ''}},
alpha(),
{{'か', 'ぁ'}, {'汉', '一'}}
)
local ia2z = 1
for _, menuItem in ipairs(menuItems) do
while a2z[ia2z] < menuItem[2] do
ia2z = ia2z + 1
end
menuItem[3] = a2z[ia2z]
end
-- span id=toc
render:wikitext('__NOTOC__',
frame:expandTemplate {title = '通用框', args = {'normal narrow'}},
"'''目录'''<br>")
for _, menuItem in ipairs(menuItems) do
render:wikitext('[[#', gl2[menuItem[3]].name, '|', menuItem[1], ']] ')
end
render:wikitext(frame:expandTemplate {title = '通用框-end'})
:newline()
local function songArg(artist, id, byd, arg)
arg = '.' .. arg
artist = artist .. '.'
local function fun(a) return a and artist .. a .. arg end
if byd then
return parentArgs[fun(queryMO(id, 'bydSongName'))] or parentArgs[fun(id .. '.byd')]
else
else
enName = name
return parentArgs[fun(queryMO(id, 'title'))] or parentArgs[fun(id)]
gl2[enName] = gl[name]
end
end
gl2[enName].otherName = frame.args[name .. '.otherName'] or nil
gl2[enName].description = frame.args[name .. '.description'] or nil
table.insert(a2z,enName)
end
end
table.sort(a2z, customSort)
 
  
local function aslAppend(artist, songid, date, byd)
   local function tableAppend(line,newStr) return line..'|'..newStr..'\n' end
local theList = {}
   for _, name in pairs(a2z) do
local function Input(arg) return songid .. (byd and '.byd' or '') .. (arg and '.' .. arg or '') end
   local item = gl2[name]
local function aInput(arg) return artist .. '.' .. Input(arg) end
   local displayName, usingName,other
local function none(arg) return '<span title="' .. aInput(arg) .. '">' .. '--' .. '</span>' end
   if item.otherName then
theList.title = ('[[' .. (Args[Input 'title'] or songTitle(songid, byd)) .. ']]') or none()
   other = (' ('..item.otherName..')') or nil
theList.length = Args[Input 'length'] or songLength(songid, byd) or none()
   end
theList.bpm = Args[Input 'bpm'] or songBPM(songid, byd) or none()
   if item.localName then
theList.pack = Args[Input 'pack'] or songPack(songid) or none()
   usingName = item.localName
local releaseVer, releaseDate = CL.fullVersionNum(songVer(songid, byd), date)
   if item.notJa then
local ver = Args[Input 'ver'] or releaseVer or none()
   displayName = usingName ..' (' .. name ..')'
theList.date = Args[Input 'date'] or releaseDate
   else
local AprilFoolVer = Args[Input 'AprilFoolVer']
   displayName = '<span lang="ja">' .. usingName .. '</span>' .. (other or '') ..' (' .. name ..')'
theList.AprilFoolDate = Args[Input 'AprilFoolDate']
   end
local afVer
   else
if AprilFoolVer and theList.AprilFoolDate then
   usingName = name
afVer = ("'''愚人节'''<br>" .. 'v' .. AprilFoolVer .. '<br />(' .. theList.AprilFoolDate .. ")<br>'''常驻'''<br>") or ''
   displayName = name
   end
   -- wikiText = wikiText .. '*' .. usingName .. '\n'
  
   wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
   wikiText = wikiText .. "==".. displayName .." ==\n"
   wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
   wikiText = wikiText .. (item.description or '') .. '\n'
   wikiText = wikiText .. '{| class="wikitable" border="1" cellspacing="1" cellpadding="5" style="text-align:center;width: 80%"\n'
wikiText = wikiText .. '! style="width: 30.5%;"|曲目名称\n'
wikiText = wikiText .. '! style="width: 8%;"|时长\n'
wikiText = wikiText .. '! style="width: 8%;"|BPM\n'
wikiText = wikiText .. '! style="width: 18.5%;"|曲包\n'
wikiText = wikiText .. '! style="width: 15%;"|发布版本\n'
wikiText = wikiText .. '! style="width: 20%;"|备注\n'
  
   local function aslAppend(artist,songid,date,byd
local theList={}
local none = '<span title="'.. songid .. '">' .. '|--'..'</span>'
theList.title = "[[" .. songTitle(songid,byd) .. "]]"
theList.time = (byd and SL.beyond[songid] or SL.normal[songid]) or none
theList.bpm = songBPM(songid,byd)
theList.pack = songPack(songid)
theList.date = songVer(songid,byd) .. '<br />('.. os.date('%Y/%m/%d',date) .. ')'
theList.text = frame.args[artist .. '.' .. songid.. ( byd and '.byd' or '') .. '.text'] or none
return theList
end
end
  
theList.displayVer = (afVer or '') .. 'v' .. ver .. '<br />(' .. theList.date .. ')' or none()
   local artistSongList = {}
theList.text = songArg(artist, songid, byd, 'text') or none 'text'
   local listSort = {}
return theList
   if item.normal then
end
   for _,songid in ipairs(item.normal) do
 
   local date = songDate(songid)
for _, name in ipairs(a2z) do
   local aslId = date..songid
local item = gl2[name]
   artistSongList[aslId]=aslAppend(usingName,songid, date)
local usingName = item.name
local displayName = mw.html.create()
if item.ja then
displayName:wikitext('-{<span lang="ja">', usingName, '</span>}-')
else
displayName:wikitext(usingName)
end
displayName:wikitext(item.otherName and (' (' .. item.otherName .. ')') or '')
if item.notAllLatin then
displayName:wikitext(item.enName and (' (' .. item.enName .. ')') or '')
end
displayName = tostring(displayName)
 
render
:wikitext(('<h2 id="%s"><span title="%s">%s</span></h2>')
:format(usingName, usingName, displayName))
:newline()
:wikitext(item.description)
:newline()
local wt = render:tag 'table'
wt:attr {
class = 'wikitable', border = '1', cellspacing = '1', cellpadding = '5', style = 'text-align:center;width: 100%'
}:tag 'tr'
:tag 'th':attr {style = 'width: 30.5%;'}:wikitext '曲目名称':done()
:tag 'th':attr {style = 'width: 6%;'}:wikitext '时长':done()
:tag 'th':attr {style = 'width: 10%;'}:wikitext 'BPM':done()
:tag 'th':attr {style = 'width: 18.5%;'}:wikitext '曲包':done()
:tag 'th':attr {style = 'width: 15%;'}:wikitext '发布版本':done()
:tag 'th':attr {style = 'width: 20%;'}:wikitext '备注':done()
 
local artistSongList = {}
local listSort = {}
if item.normal then
for _, songid in ipairs(item.normal) do
local date = songDate(songid)
local theList = aslAppend(usingName, songid, date)
local aslId = (theList.AprilFoolDate or theList.date) .. songid
artistSongList[aslId] = theList
table.insert(listSort, aslId)
table.insert(listSort, aslId)
   end
end
   end
end
   if item.beyond then
if item.beyond then
   for _,songid in ipairs(item.beyond) do
for _, songid in ipairs(item.beyond) do
   local date = songDate(songid, 1)
local date = songDate(songid, 1)
   local aslId = date..songid..'byd'
local theList = aslAppend(usingName, songid, date, 1)
   artistSongList[aslId]=aslAppend(usingName,songid, date, 1)
local aslId = (theList.AprilFoolDate or theList.date) .. songid .. 'byd'
artistSongList[aslId] = theList
table.insert(listSort, aslId)
table.insert(listSort, aslId)
   end
end
   end
end
   table.sort(listSort)
table.sort(listSort)
   for _,id in ipairs(listSort) do
for _, id in ipairs(listSort) do
   wikiText = tableAppend(wikiText, '-')
local theList = artistSongList[id]
   wikiText = tableAppend(wikiText, artistSongList[id].title)
wt:tag 'tr'
   wikiText = tableAppend(wikiText, artistSongList[id].time)
:tag 'td':wikitext(theList.title):done()
   wikiText = tableAppend(wikiText, artistSongList[id].bpm)
:tag 'td':wikitext(theList.length):done()
   wikiText = tableAppend(wikiText, artistSongList[id].pack)
:tag 'td':wikitext(theList.bpm):done()
   wikiText = tableAppend(wikiText, artistSongList[id].date)
:tag 'td':wikitext(theList.pack):done()
   wikiText = tableAppend(wikiText, artistSongList[id].text)
:tag 'td':wikitext(theList.displayVer):done()
   end
:tag 'td':wikitext(theList.text):done()
     wikiText = wikiText .. "|}\n"
end
   end
end
   return wikiText
return tostring(render)
end
end


return p
return p

2024年10月27日 (日) 23:30的最新版本

可在Module:ArtistSong/doc创建此模块的帮助文档

local p = {}
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
local trans = mw.loadJsonData 'Template:Transition.json'
local SL = mw.loadJsonData 'Template:Song Length.json'

local mad = require 'Module:AnotherData'
local data = require 'Module:Arcaea Data'
local CL = require 'Module:ConvertLink'
local tt = require 'Module:TableTools'

local lang = mw.language.getContentLanguage()

local queryMO = data.allSongInformation('id', 'mobile')
local queryNS = data.allSongInformation('id', 'ns')

-- byd?=>id=>c-artist
local function readList()
	local pickList = {}
	local pickListBYD = {}
	for _, song in ipairs(mad.listOf('songs', 'mobile')) do
		if not song.deleted then
			local artist = song.artist
			pickList[song.id] = song.artist
			if song.difficulties[4] and (song.difficulties[4].artist or song.difficulties[4].title_localized) then
				local bydArtist = song['difficulties'][4]['artist'] or song.artist
				pickListBYD[song['id']] = bydArtist
			end
		end
	end

	for _, song in ipairs(mad.listOf('songs', 'ns')) do
		if not pickList[song.id] and not trans.multiId[song.id] then
			pickList[song.id] = song.artist
			if song.difficulties[4] and song.difficulties[4].artist or song.difficulties[4].title_localized then
				local bydArtist = song['difficulties'][4]['artist'] or song.artist
				pickListBYD[song['id']] = bydArtist
			end
		end
	end

	return pickList, pickListBYD
end

-- groupby: c-artist=>byd?=>[id]
local function convertPick(pickList, pickListBYD)
	convertList = {}
	for id, artist in pairs(pickList) do
		if not convertList[artist] then convertList[artist] = {} end
		if not convertList[artist].normal then convertList[artist]['normal'] = {} end
		table.insert(convertList[artist]['normal'], id)
	end

	for id, artist in pairs(pickListBYD) do
		if not convertList[artist] then convertList[artist] = {} end
		if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
		table.insert(convertList[artist]['beyond'], id)
	end

	return convertList
end

-- n-n map: s-artist=>byd?=>[id]
local zhName = {}
local function genList(convertList)
	-- TODO:既然convertList都闭包了那singleList也可以
	local function cate(singleList, cArtist, artist)
		local artist = artist or cArtist
		if not singleList[artist] then singleList[artist] = {} end
		if convertList[cArtist].beyond then
			if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
			tt.extend(singleList[artist]['beyond'], convertList[cArtist]['beyond'])
		end
		if convertList[cArtist].normal then
			if not singleList[artist].normal then singleList[artist]['normal'] = {} end
			tt.extend(singleList[artist]['normal'], convertList[cArtist]['normal'])
		end
		return singleList
	end


	local singleList = {}
	for cArtist in pairs(convertList) do
		local artistlist = {}
		if CALv2[cArtist] then
			if CALv2[cArtist].__FullData__ then
				for _, text in pairs(CALv2[cArtist].__FullData__) do
					if text.link then
						local artist = text.link
						if not artistlist[artist] then
							singleList = cate(singleList, cArtist, artist)
							artistlist[artist] = 1
							if text.zh then
								zhName[artist] = true
							end
						end
					end
				end
			else
				for link in pairs(CALv2[cArtist]) do
					local artist = link
					if not artistlist[artist] then
						singleList = cate(singleList, cArtist, artist)
						artistlist[artist] = 1
					end
				end
			end
		else
			singleList = cate(singleList, cArtist)
		end
	end
	return singleList
end

local function isLetter(char)
	return char:match '%a' ~= nil
end

-- 排序
local function customSort(a, b)
	local a1 = a:sub(1, 1)
	local b1 = b:sub(1, 1)
	local la1 = isLetter(a:sub(1, 1))
	local lb1 = isLetter(b:sub(1, 1))

	if la1 and not lb1 then
		return true
	elseif lb1 and not la1 then
		return false
	elseif string.lower(a1) == string.lower(b1) then
		local la2 = isLetter(a:sub(2, 2))
		local lb2 = isLetter(b:sub(2, 2))
		if la2 and not lb2 then
			return true
		elseif lb2 and not la2 then
			return false
		else
			return string.lower(a) < string.lower(b)
		end
	else
		return string.lower(a) < string.lower(b)
	end

	return string.lower(a) < string.lower(b)
end

local function songTitle(id, byd)
	local display
	local title = queryMO(id, 'title') or queryNS(id, 'title')
	if byd then
		display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD'
	else
		display = title
	end
	local res = trans.songNameToDisplayName[title]
	if res then return res .. '|' .. display end
	res = trans.sameName[title]
	if res then return res[id] .. '|' .. display end
	if title then
		return title .. '|' .. display
	else
		return id
	end
end

local function songBPM(id, byd)
	local bpm
	if byd then
		bpm = queryMO(id, 'bydBPM') or queryNS(id, 'bydBPM')
		if bpm then return bpm end
	end
	bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
	if bpm then
		return bpm
	else
		return nil
	end
end

local function songDate(id, byd)
	local date, ver
	if byd then
		date = queryMO(id, 'bydDate') or queryNS(id, 'bydDate')
		if date then return date end
	end
	date = queryMO(id, 'date') or queryNS(id, 'date')
	if date then return date else return 0 end
end

local function songVer(id, byd)
	local date, ver
	if byd then
		ver = queryMO(id, 'bydVersion') or queryNS(id, 'bydVersion')
		if ver then return ver end
	end
	ver = queryMO(id, 'version') or queryNS(id, 'version')
	if ver then return ver else return id end
end

local function songPack(id)
	local packid, plat, isNS
	-- if queryNS(id, 'set') then
	-- 	packid = queryNS(id, 'set')
	-- 	plat = 'ns'
	-- 	isNS = 1
	if queryMO(id, 'set') then
		packid = queryMO(id, 'set')
	else
		return nil
	end
	local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
	local packLink = CL.packLink(packName, 1, isNS)
	return packLink
end

local function songLength(id, byd)
	if byd then
		return SL.beyond[id]
	else
		return SL.normal[id]
	end
end



function p.main(frame)
	local parentArgs = frame:getParent().args
	local Args = frame.args

	local rl, rlb = readList()
	local cl = convertPick(rl, rlb)
	local gl = genList(cl)
	rl, rlb, cl = nil

	local appendList = Args['appendList']
	if appendList then
		local list = mw.text.split(appendList, '\n')
		for _, id in pairs(list) do
			local artists = Args[id .. '.' .. 'artist']
			if artists then
				local artistList = mw.text.split(artists, '/')
				for _, artist in pairs(artistList) do
					if not gl[artist] then gl[artist] = {} end
					if not gl[artist].normal then gl[artist].normal = {} end
					table.insert(gl[artist].normal, id)
				end
			end
		end
	end

	local render = mw.html.create()

	local a2z = {}
	local gl2 = {}
	for name, artistData in pairs(gl) do
		if mw.ustring.match(name, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
			artistData.notAllLatin = 1
			local notJaName = parentArgs[name .. '.notJaName'] or zhName[name]
			if not notJaName then artistData.ja = 1 end
		end
		artistData.name = name
		artistData.enName = parentArgs[name .. '.enName'] or nil
		artistData.otherName = parentArgs[name .. '.otherName'] or nil
		artistData.description = parentArgs[name .. '.description'] or nil
		local sortName = mw.ustring.gsub(name, '[A-Z]+', string.lower)
		gl2[sortName] = artistData
		table.insert(a2z, sortName)
	end
	table.sort(a2z)

	-- 生成页首
	local function alpha()
		local ret, cla, cua = {}, string.byte 'a', string.byte 'A'
		for i = 0, 25 do
			table.insert(ret, {string.char(i + cua), string.char(i + cla)})
		end
		return ret
	end
	local menuItems = tt.merge(
		{{'#', ''}},
		alpha(),
		{{'か', 'ぁ'}, {'汉', '一'}}
	)
	local ia2z = 1
	for _, menuItem in ipairs(menuItems) do
		while a2z[ia2z] < menuItem[2] do
			ia2z = ia2z + 1
		end
		menuItem[3] = a2z[ia2z]
	end
	-- span id=toc
	render:wikitext('__NOTOC__',
		frame:expandTemplate {title = '通用框', args = {'normal narrow'}},
		"'''目录'''<br>")
	for _, menuItem in ipairs(menuItems) do
		render:wikitext('[[#', gl2[menuItem[3]].name, '|', menuItem[1], ']] ')
	end
	render:wikitext(frame:expandTemplate {title = '通用框-end'})
		:newline()

	local function songArg(artist, id, byd, arg)
		arg = '.' .. arg
		artist = artist .. '.'
		local function fun(a) return a and artist .. a .. arg end
		if byd then
			return parentArgs[fun(queryMO(id, 'bydSongName'))] or parentArgs[fun(id .. '.byd')]
		else
			return parentArgs[fun(queryMO(id, 'title'))] or parentArgs[fun(id)]
		end
	end

	local function aslAppend(artist, songid, date, byd)
		local theList = {}
		local function Input(arg) return songid .. (byd and '.byd' or '') .. (arg and '.' .. arg or '') end
		local function aInput(arg) return artist .. '.' .. Input(arg) end
		local function none(arg) return '<span title="' .. aInput(arg) .. '">' .. '--' .. '</span>' end
		theList.title = ('[[' .. (Args[Input 'title'] or songTitle(songid, byd)) .. ']]') or none()
		theList.length = Args[Input 'length'] or songLength(songid, byd) or none()
		theList.bpm = Args[Input 'bpm'] or songBPM(songid, byd) or none()
		theList.pack = Args[Input 'pack'] or songPack(songid) or none()
		local releaseVer, releaseDate = CL.fullVersionNum(songVer(songid, byd), date)
		local ver = Args[Input 'ver'] or releaseVer or none()
		theList.date = Args[Input 'date'] or releaseDate
		local AprilFoolVer = Args[Input 'AprilFoolVer']
		theList.AprilFoolDate = Args[Input 'AprilFoolDate']
		local afVer
		if AprilFoolVer and theList.AprilFoolDate then
			afVer = ("'''愚人节'''<br>" .. 'v' .. AprilFoolVer .. '<br />(' .. theList.AprilFoolDate .. ")<br>'''常驻'''<br>") or ''
		end
		theList.displayVer = (afVer or '') .. 'v' .. ver .. '<br />(' .. theList.date .. ')' or none()
		theList.text = songArg(artist, songid, byd, 'text') or none 'text'
		return theList
	end

	for _, name in ipairs(a2z) do
		local item = gl2[name]
		local usingName = item.name
		local displayName = mw.html.create()
		if item.ja then
			displayName:wikitext('-{<span lang="ja">', usingName, '</span>}-')
		else
			displayName:wikitext(usingName)
		end
		displayName:wikitext(item.otherName and (' (' .. item.otherName .. ')') or '')
		if item.notAllLatin then
			displayName:wikitext(item.enName and (' (' .. item.enName .. ')') or '')
		end
		displayName = tostring(displayName)

		render
			:wikitext(('<h2 id="%s"><span title="%s">%s</span></h2>')
				:format(usingName, usingName, displayName))
			:newline()
			:wikitext(item.description)
			:newline()
		local wt = render:tag 'table'
		wt:attr {
			class = 'wikitable', border = '1', cellspacing = '1', cellpadding = '5', style = 'text-align:center;width: 100%'
		}:tag 'tr'
			:tag 'th':attr {style = 'width: 30.5%;'}:wikitext '曲目名称':done()
			:tag 'th':attr {style = 'width: 6%;'}:wikitext '时长':done()
			:tag 'th':attr {style = 'width: 10%;'}:wikitext 'BPM':done()
			:tag 'th':attr {style = 'width: 18.5%;'}:wikitext '曲包':done()
			:tag 'th':attr {style = 'width: 15%;'}:wikitext '发布版本':done()
			:tag 'th':attr {style = 'width: 20%;'}:wikitext '备注':done()

		local artistSongList = {}
		local listSort = {}
		if item.normal then
			for _, songid in ipairs(item.normal) do
				local date = songDate(songid)
				local theList = aslAppend(usingName, songid, date)
				local aslId = (theList.AprilFoolDate or theList.date) .. songid
				artistSongList[aslId] = theList
				table.insert(listSort, aslId)
			end
		end
		if item.beyond then
			for _, songid in ipairs(item.beyond) do
				local date = songDate(songid, 1)
				local theList = aslAppend(usingName, songid, date, 1)
				local aslId = (theList.AprilFoolDate or theList.date) .. songid .. 'byd'
				artistSongList[aslId] = theList
				table.insert(listSort, aslId)
			end
		end
		table.sort(listSort)
		for _, id in ipairs(listSort) do
			local theList = artistSongList[id]
			wt:tag 'tr'
				:tag 'td':wikitext(theList.title):done()
				:tag 'td':wikitext(theList.length):done()
				:tag 'td':wikitext(theList.bpm):done()
				:tag 'td':wikitext(theList.pack):done()
				:tag 'td':wikitext(theList.displayVer):done()
				:tag 'td':wikitext(theList.text):done()
		end
	end
	return tostring(render)
end

return p