Fandom

Vocaloid Wiki

Module:Reformat

7,993pages on
this wiki
Add New Page
Talk18
-- <nowiki>
 
local export = {}
local replace = mw.ustring.gsub
local trim = mw.text.trim
local find = mw.ustring.find
local match = mw.ustring.match
local split = mw.text.split
 
-- {{subst:#invoke:reformat|derivatives
-- {{subst:#invoke:reformat|derivatives_tabber
-- {{subst:#invoke:reformat|song_box_new
-- {{subst:#invoke:reformat|producer_song_box
-- {{subst:#invoke:reformat|producer_infobox
 
function export.derivatives(frame)
	local text = trim([[
 
{{Derivatives |<nnd_id> |<nnd_comment> |<yt_id> |<yt_comment> |<bb_id> |<bb_comment>
|<nnd_id2> |<nnd2_comment> |<yt_id2> |<yt2_comment>
|<pp_id> |<pp_comment> |<piapro_id> |<piapro_comment> |<sc_id> |<sc_comment> |<sc_id2> |<sc2_comment> |<5s_id> |<5s_comment> |<mz_id> |<mz_comment> |<vm_id> |<vm_comment> |<tm_id> |<tm_comment>
|<etc> |<etc_comment> |<etc2> |<etc2_comment>
|<singer> |<author> |<category>
|<title> |<romaji (english)>
|<description>
|<width> |<height>
|<icon> |<thumb> |<color> }}
 
]])
 
	local keep =  { 'nnd_id', 'yt_id', 'yt_comment', 'author', 'category', 'title', 'description', 'color' }
 
	local optional = { 'nnd_comment', 'bb_id', 'bb_comment', 'nnd_id2', 'nnd2_comment', 'yt_id2', 'yt2_comment', 'pp_id', 'pp_comment', 'piapro_id', 'piapro_comment', 'sc_id', 'sc_comment', 'sc_id2', 'sc2_comment', '5s_id', '5s_comment', 'mz_id', 'mz_comment', 'vm_id', 'vm_comment', 'tm_id', 'tm_comment', 'etc', 'etc_comment', 'etc2', 'etc2_comment', 'singer', 'romaji %(english%)', 'width', 'height', 'icon', 'thumb' }
 
	local p = frame.args
 
	for param, value in pairs(p) do
		if param == 'title' then
			value = replace(value, 'dance cover', 'Dance Cover')
			value = replace(value, 'cover', 'Cover')
			value = replace(value, 'demo', 'Demo')
			value = replace(value, ' x ', ' × ')
		end
		if param == 'author' then
			-- value = replace(value, ' %([A-Z][a-z][A-Za-z, ]+', mw.ustring.lower) -- 「(Cover)」→「(cover)」 but not 「(UST)」→「(uST)」
				-- converts 「Rin tuning」 to 「rin tuning」 like it's told to, but this isn't what we want so whatever
			value = replace(value, ' x ', ' × ')
		end
		if param == 'category' then
			value = replace(value, 'Cover', 'cover')
			value = replace(value, 'Version', 'version')
			value = replace(value, '[Uu]taite', 'Human')
			value = replace(value, '[Uu][Tt][Aa][Uu]', 'UTAU')
			value = replace(value, '[Vv][Oo][Cc][Aa][Ll][Oo][Ii][Dd]', 'VOCALOID')
			-- value = replace(value, ';', ',')
		end
		if param == 'color' then
			value = replace(value, ' *; *color: *', '; color:')
			value = replace(value, ';$', '')
		end
		if param == 'romaji (english)' then
			param = 'romaji %(english%)'
		end
 
		if value ~= '' then
			text = replace(text, '|<'..param..'>', '|'..param..' = '..value)
		end
	end
 
	for i, param in ipairs(keep) do
		text = replace(text, '|<'..param..'> ?', '|'..param..' = ')
	end
	for i, param in ipairs(optional) do
		text = replace(text, '|<'..param..'> ?', '')
	end
 
	text = replace(text, ' +', ' ')
	text = replace(text, '\n+', '\n')
	text = replace(text, ' \n', '\n')
	text = replace(text, '=\n', '= \n')
 
	text = replace(text, 'romaji %%%(english%%%) = ', 'romaji (english) = ')
 
	text = replace(text, '|nnd_id = |yt_id = |yt_comment = \n', '')
	text = replace(text, '|nnd_id = |', '|')
	text = replace(text, 'Derivatives |singer', 'Derivatives\n|singer')
	text = replace(text, 'Derivatives |author', 'Derivatives\n|author')
 
	return text
end
 
function export.derivatives_tabber(frame)
	local text = trim([[
 
{{Derivatives tabber
  |<vocaloid>
  |<VOCALOID>
 
  |<utau>
  |<UTAU>
 
  |<other>
  |<OTHER>
 
  |<human>
  |<HUMAN>
 
  |<dance>
  |<DANCE>
 
  |<arrangement>
  |<ARRANGEMENT>
 
  |<fanmadepv>
  |<FANMADEPV>
 
  |<spinoff>
  |<SPINOFF>
 
  |<more>
  |<MORE>
}}
 
]])
 
	local list_lower =  { 'vocaloid', 'utau', 'other', 'human', 'dance', 'arrangement', 'fanmadepv', 'spinoff', 'more' }
	local list_upper =  { 'VOCALOID', 'UTAU', 'OTHER', 'HUMAN', 'DANCE', 'ARRANGEMENT', 'FANMADEPV', 'SPINOFF', 'MORE' }
	local list, other = {}, {}
 
	local p = frame.args
 
	if p['VOCALOID'] or p['UTAU'] or p['OTHER'] or p['HUMAN'] or p['DANCE'] or p['ARRANGEMENT'] or p['FANMADEPV'] or p['SPINOFF'] or p['MORE'] then
		list = list_upper
		other = list_lower
	else
		list = list_lower
		other = list_upper
	end
 
	for param, value in pairs(p) do
		if value ~= '' then
			text = replace(text, '<'..param..'>', param..' =\n'..value)
		end
	end
 
	for i, param in ipairs(list) do
		text = replace(text, '<'..param..'>', param..' =')
	end
	for i, param in ipairs(other) do
		text = replace(text, '\n  |<'..param..'>', '')
	end
 
	text = replace(text, '\n*{{[Cc]lr}}\n*', '\n\n')
 
	return text
end
 
function export.song_box_new(frame)
	local text = trim([[
 
{{Song box 2
  |color     = <color>
  |image     = <image>
  |title     = <title>
  |date      = <date>
  |views     = <views>
  |singers   = <singers>
  |producers = <producers>
  |links     = <links>
}}
 
]])
 
	local list =  { 'color', 'image', 'title', 'date', 'views', 'singers', 'producers', 'links' }
 
	local p = frame.args
 
	for param, value in pairs(p) do
		if param == 'title' or param == 'singers' or param == 'producers' or param == 'links' then
			value = replace(value, '\n%* *', '\n* ')
			value = replace(value, ' ?<[Bb][Rr] ?%/?> ?', '\n* ')
		end
		if param == 'views' then
			value = replace(value, '&', 'and')
		end
		if param == 'color' then
			value = replace(value, ' *; *color: *', '; color:')
			value = replace(value, ';$', '')
		end
		if param == 'links' then
			local honke, tensai = {}, {}
			value = replace(value, '}} {{', '}}@@{{')
			value = replace(value, '\n%*  *', '@@')
			value = split(value, '@@')
			for i, l in ipairs(value) do
				if find(l, 'reprint') then
					table.insert(tensai, l)
				else
					table.insert(honke, l)
				end
			end
			honke = table.concat(honke, ' ')
			tensai = table.concat(tensai, ' ')
			if honke == '' then honke = nil end
			if tensai == '' then tensai = nil end
			if not honke then
				value = tensai
			else
				value = honke .. (tensai and '\n* ' .. tensai or '')
			end
		end
 
		if value ~= '' then
			text = replace(text, '<'..param..'>', value)
		end
	end
 
	for i, param in ipairs(list) do
		text = replace(text, '<'..param..'>', '')
	end
 
	return text
end
 
function export.producer_song_box(frame)
	local text = trim([[
 
{{Infobox song
|<nnd_id> |<nnd_comment> |<yt_id> |<yt_comment> |<bb_id> |<bb_comment>
|<nnd_id2> |<nnd2_comment> |<yt_id2> |<yt2_comment>
|<pp_id> |<pp_comment> |<piapro_id> |<piapro_comment> |<sc_id> |<sc_comment> |<5s_id> |<5s_comment>
|<mz_id> |<mz_comment> |<vm_id> |<5s_comment> |<tm_id> |<tm_comment>
|<etc> |<etc_name> |<etc_comment> |<xtra_url> |<xtra_name> |<xtra_comment>
|<composer> |<lyricist>
|<overallPVwork> |<illustrator> |<videoeditor>
|<vocaloid>
|<description>
|<icon> |<thumb>
|<uploaddate> |<title1> |<title2> }}
 
]])
 
	local keep =  { 'title1', 'nnd_id', 'yt_id', 'yt_comment', 'uploaddate', 'vocaloid', 'composer', 'lyricist', 'description' }
	local keep_2 = { 'overallPVwork', 'illustrator', 'videoeditor' }
 
	local optional = { 'title2', 'icon', 'thumb', 'xtra_url', 'etc', 'xtra_name', 'etc_name', 'xtra_comment', 'etc_comment', 'bb_id', 'sc_id', '5s_id', 'mz_id', 'nnd_comment', 'nnd_id2', 'nnd2_comment', 'yt_id2', 'yt2_comment', 'bb_comment', 'piapro_id', 'pp_id', 'piapro_comment', 'pp_comment', 'sc_comment', '5s_comment', 'mz_comment', 'vm_id', 'vm_comment', 'tm_id', 'tm_comment' }
 
	local p = frame.args
 
	for param, value in pairs(p) do
		if param == 'overallpvwork' then
			param = 'overallPVwork'
		end
 
		if value ~= '' then
			text = replace(text, '|<'..param..'>', '|'..param..' = '..value)
		end
	end
 
	for i, param in ipairs(keep) do
		text = replace(text, '|<'..param..'> ?', '|'..param..' = ')
	end
	for i, param in ipairs(optional) do
		text = replace(text, '|<'..param..'> ?', '')
	end
 
	if p['overallPVwork'] ~= '' or p['illustrator'] ~= '' or p['videoeditor'] ~= '' then
		text = replace(text, '|<overallPVwork> ?', '')
		text = replace(text, '|<illustrator> ?', '')
		text = replace(text, '|<videoeditor> ?', '')
	else
		for i, param in ipairs(keep_2) do
			text = replace(text, '|<'..param..'> ?', '|'..param..' = ')
		end
	end
 
	text = replace(text, ' +', ' ')
	text = replace(text, '\n+', '\n')
	text = replace(text, ' \n', '\n')
	text = replace(text, '=\n', '= \n')
 
	text = replace(text, '|nnd_id = |yt_id = |yt_comment = \n?', '')
	text = replace(text, '|nnd_id = |', '|')
 
	return text
end
 
 
function export.producer_infobox(frame)
	local text = trim([[
 
{{Infobox Producer
|width        = <width>
|image        = <image>
|caption      = <caption>
|producer     = <producer>
|debut        = <debut>
|currently    = <currently>
|genre        = <genre>
|labels       = <labels>
|associations = <associations>
|official     = <official>
|url          = <url>
|playlist     = <playlist>
|content      =
<content>
}}
 
]])
 
	local keep =  { 'image', 'producer', 'debut', 'currently', 'genre', 'labels', 'associations', 'official', 'url', 'playlist', 'content' }
 
	local optional = { 'width', 'caption' }
 
	local p = frame.args
 
	for param, value in pairs(p) do
		if param == 1 then
			param = 'content' -- who even allowed |1= to happen
			value = trim(value)
		end
		if param == 'content' then
			value = replace(value, '^# *', '# ')
			value = replace(value, '\n# *', '\n# ')
		end
		if value ~= '' then
			text = replace(text, '<'..param..'>', value)
		end
	end
 
	for i, param in ipairs(keep) do
		text = replace(text, '<'..param..'>', '')
	end
 
	for i, param in ipairs(optional) do
		text = replace(text, '|'..param..' *=%s*<'..param..'>\n', '')
	end
 
	return text
end
 
function export.master(frame)
	local template = frame.args['template name']
 
	template = replace(template, '_', ' ')
	template = mw.ustring.lower(template)
 
	if template == 'derivatives' then
		return export.derivatives(frame)
 
	elseif template == 'derivatives tabber' then
		return export.derivatives_tabber(frame)
 
	elseif template == 'song box 2' then
		return export.song_box_new(frame)
 
	elseif template == 'song box' then
		return require('module:song box conversion').show(frame)
 
	elseif template == 'infobox song' then
		return export.producer_song_box(frame)
 
	elseif template == 'infobox producer' then
		return export.producer_infobox(frame)
 
	end
end
 
 
return export

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki