Module:Songs: Difference between revisions

From Umamusume Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(43 intermediate revisions by 2 users not shown)
Line 3: Line 3:


function p.albums(frame)
function p.albums(frame)
local songName = frame.args[1]
local songName = mw.text.decode(frame.args[1])
if not songName then return end
if not songName then return end
local escaped = string.gsub(songName, "'", "\\\'")
local escaped = string.gsub(songName, "'", "\\'")
local query = {
local query = {
join = "Album_Songs.album=Albums.title",
join = "Album_Songs.album=Albums.title",
where = "Album_Songs.song_page='" .. escaped .. "'",
where = "Album_Songs.song_page='" .. escaped .. "'",
groupBy = "Albums.title"
orderBy = "Albums.release_date ASC"
}
}
local fields = {'Albums._pageTitle=album_page'}
local fields = {
local events = cargo.query('Albums, Album_Songs',
'Albums._pageTitle=album_page',
'Album_Songs.singers=singers',
'Album_Songs.type=type'
}
local albums = cargo.query('Albums, Album_Songs',
table.concat(fields, ','), query)
table.concat(fields, ','), query)


local text = ''
local text = ''
for _, ev in ipairs(events) do
for _, ev in ipairs(albums) do
text = text .. frame:expandTemplate{
if ev.type ~= 'offvocal' and ev.type ~= 'shortver' then
title='Song Albums/Entry',
text = text .. frame:expandTemplate {
args=ev
title = 'Song Albums/Entry',
} .. '\n'
args = ev
} .. '\n'
end
end
end
return text
return text
Line 26: Line 32:


function p.events(frame)
function p.events(frame)
local songName = frame.args[1]
local songName = mw.text.decode(frame.args[1])
if not songName then return end
if not songName then return end
local escaped = string.gsub(songName, "'", "\\\'")
local escaped = string.gsub(songName, "'", "\\'")
local query = {
local query = {
join = "Setlist_Event._pageID=Setlist_Songs._pageID",
where = "song_page='" .. escaped .. "'",
where = "song_page='" .. escaped .. "'",
orderBy = "event_order ASC, leg_order ASC, day ASC",
}
}
local fields = {'event_page', 'leg_name', 'day', 'cast'}
local fields = { 'event_page', 'leg_name', 'day', 'cast' }
local events = cargo.query('Setlist_Songs',
local events = cargo.query('Setlist_Event, Setlist_Songs',
table.concat(fields, ','), query)
table.concat(fields, ','), query)
if #events == 0 then
return "None."
end


local text = ''
local text = ''
for _, ev in ipairs(events) do
for _, ev in ipairs(events) do
text = text .. frame:expandTemplate{
text = text .. frame:expandTemplate {
title='Song Events/Entry',
title = 'Song Events/Entry',
args=ev
args = ev
} .. '\n'
} .. '\n'
end
end
return text
end
function p.characterSongs(frame)
local horseName = mw.text.decode(frame.args[1])
if not horseName then return end
local escaped = string.gsub(horseName, "'", "\\'")
local query = {
limit = '1000',
where = 'Album_Songs.singers HOLDS "' .. escaped .. '"',
orderBy = "Album_Songs.song_page ASC, Album_Songs.song_title ASC, Album_Songs.album ASC"
}
local fields = { 'song_page', 'song_title', 'album', 'type', 'singers' }
local results = cargo.query('Album_Songs', table.concat(fields, ','), query)
local groups = {}
local songTitles = {}
local songTitlesAdded = {}
local songPageNames = {}
for _, result in ipairs(results) do
local singers = mw.text.split(result.singers, ",")
local type = nil
if result.type == "solover" then
type = "'''" .. horseName .. " ver.'''"
elseif result.type == "remix" then
type = "Group (Remix)"
elseif not result.type then
if #singers == 1 then
type = "'''Solo'''"
elseif #singers == 2 then
type = "Duo"
elseif #singers == 3 then
type = "Trio"
else
type = "Group"
end
end
if type ~= nil then
if not groups[result.song_title] then groups[result.song_title] = {} end
songPageNames[result.song_title] = result.song_page
if not songTitlesAdded[result.song_title] then
table.insert(songTitles, result.song_title)
songTitlesAdded[result.song_title] = true
end
table.insert(groups[result.song_title], { album = result.album, type = type })
end
end
local text = '{| class="wikitable sortable mw-collapsible mw-collapsed"\n! Song !! Album !! Type\n'
for _, song in ipairs(songTitles) do
local rows = groups[song]
local rowspan = #rows
local head = table.remove(rows, 1)
text = text ..
string.format('|-\n| rowspan=%d|[[%s|%s]] || [[%s]] || %s\n', rowspan, songPageNames[song], song, head.album,
head.type)
for _, row in ipairs(rows) do
text = text ..
string.format('|-\n| [[%s]] || %s\n', row.album, row.type)
end
end
text = text .. '|}'
return text
return text
end
end


return p
return p

Latest revision as of 00:59, 4 October 2024

Documentation for this module may be created at Module:Songs/doc

local p = {}
local cargo = mw.ext.cargo

function p.albums(frame)
	local songName = mw.text.decode(frame.args[1])
	if not songName then return end
	local escaped = string.gsub(songName, "'", "\\'")
	local query = {
		join = "Album_Songs.album=Albums.title",
		where = "Album_Songs.song_page='" .. escaped .. "'",
		orderBy = "Albums.release_date ASC"
	}
	local fields = {
		'Albums._pageTitle=album_page',
		'Album_Songs.singers=singers',
		'Album_Songs.type=type'
	}
	local albums = cargo.query('Albums, Album_Songs',
		table.concat(fields, ','), query)

	local text = ''
	for _, ev in ipairs(albums) do
		if ev.type ~= 'offvocal' and ev.type ~= 'shortver' then
			text = text .. frame:expandTemplate {
				title = 'Song Albums/Entry',
				args = ev
			} .. '\n'
		end
	end
	return text
end

function p.events(frame)
	local songName = mw.text.decode(frame.args[1])
	if not songName then return end
	local escaped = string.gsub(songName, "'", "\\'")
	local query = {
		join = "Setlist_Event._pageID=Setlist_Songs._pageID",
		where = "song_page='" .. escaped .. "'",
		orderBy = "event_order ASC, leg_order ASC, day ASC",
	}
	local fields = { 'event_page', 'leg_name', 'day', 'cast' }
	local events = cargo.query('Setlist_Event, Setlist_Songs',
		table.concat(fields, ','), query)
	
	if #events == 0 then
		return "None."
	end

	local text = ''
	for _, ev in ipairs(events) do
		text = text .. frame:expandTemplate {
			title = 'Song Events/Entry',
			args = ev
		} .. '\n'
	end
	return text
end

function p.characterSongs(frame)
	local horseName = mw.text.decode(frame.args[1])
	if not horseName then return end
	local escaped = string.gsub(horseName, "'", "\\'")
	local query = {
		limit = '1000',
		where = 'Album_Songs.singers HOLDS "' .. escaped .. '"',
		orderBy = "Album_Songs.song_page ASC, Album_Songs.song_title ASC, Album_Songs.album ASC"
	}
	local fields = { 'song_page', 'song_title', 'album', 'type', 'singers' }
	local results = cargo.query('Album_Songs', table.concat(fields, ','), query)

	local groups = {}
	local songTitles = {}
	local songTitlesAdded = {}
	local songPageNames = {}
	for _, result in ipairs(results) do
		local singers = mw.text.split(result.singers, ",")

		local type = nil
		if result.type == "solover" then
			type = "'''" .. horseName .. " ver.'''"
		elseif result.type == "remix" then
			type = "Group (Remix)"
		elseif not result.type then
			if #singers == 1 then
				type = "'''Solo'''"
			elseif #singers == 2 then
				type = "Duo"
			elseif #singers == 3 then
				type = "Trio"
			else
				type = "Group"
			end
		end

		if type ~= nil then
			if not groups[result.song_title] then groups[result.song_title] = {} end
			songPageNames[result.song_title] = result.song_page
			if not songTitlesAdded[result.song_title] then
				table.insert(songTitles, result.song_title)
				songTitlesAdded[result.song_title] = true
			end
			table.insert(groups[result.song_title], { album = result.album, type = type })
		end
	end

	local text = '{| class="wikitable sortable mw-collapsible mw-collapsed"\n! Song !! Album !! Type\n'
	for _, song in ipairs(songTitles) do
		local rows = groups[song]
		local rowspan = #rows
		local head = table.remove(rows, 1)
		text = text ..
			string.format('|-\n| rowspan=%d|[[%s|%s]] || [[%s]] || %s\n', rowspan, songPageNames[song], song, head.album,
				head.type)
		for _, row in ipairs(rows) do
			text = text ..
				string.format('|-\n| [[%s]] || %s\n', row.album, row.type)
		end
	end
	text = text .. '|}'

	return text
end

return p