Vocaloid Wiki
Register
Advertisement

Documentation for this module may be created at Module:Song box conversion/doc

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

local function convbr(text)
	text = replace(text, ' ?<[Bb][Rr] ?%/?> ?', '\n* ') --[[Module:Reciprocal link test]]
	return text
end

function export.show(frame)
	local p = frame.args
	local text = '{{Song box 2'

	local image = p['image'] or ''
	local title = p['songtitle'] or ''
	local date = p['uploaddate'] or ''
	local views = p['viewcount'] or ''
	local color = p['color'] or ''
	local singers = p['singer'] or ''
	local producers = p['producer'] or ''

	local NN = { 'nn', p['nnd_id'] or '', p['nnd_comment'] or '' }
	local YT = { 'yt', p['yt_id'] or '', p['yt_comment'] or '' }
	local NNx = { 'nn', p['nnd_id2'] or '', p['nnd2_comment'] or '' }
	local YTx = { 'yt', p['yt_id2'] or '', p['yt2_comment'] or '' }
	local BB = { 'bb', p['bb_id'] or '', p['bb_comment'] or '' }
	local PP = { 'pp', p['pp_id'] or '', p['pp_comment'] or '' }
	local PPx = { 'pp', p['piapro_id'] or '', p['piapro_comment'] or '' }
	local SC = { 'sc', p['sc_id'] or '', p['sc_comment'] or '' }
	local FS = { '5s', p['5s_id'] or '', p['5s_comment'] or '' } -- note fs, not 5s
	local MZ = { 'mz', p['mz_id'] or '', p['mz_comment'] or '' }
	local VM = { 'vm', p['vm_id'] or '', p['vm_comment'] or '' }
	local TM = { 'tm', p['tm_id'] or '', p['tm_comment'] or '' }
	local ETC = p['etc'] or '' -- probably a tricky one to handle

	-- color = replace(color, ' *; *color: *', '; ')
	color = replace(color, ' *; *color: *', '; color:')
	color = replace(color, ';$', '')
	title, singers, producers = convbr(title), convbr(singers), convbr(producers)

--[[
	local TEMP = { title, singers, producers }
	for param, text in pairs(TEMP) do
		if find(text, '<') then return('<span class="error">◆◆Please check input for ' .. param .. '◆◆</span><br><pre>' .. mw.text.nowiki(text) .. '</pre>') end
	end
]]

	local LINKS = { NN, YT, NNx, YTx, BB, PP, PPx, SC, FS, MZ, VM, TM }
	local honke = {}
	local tensai = {}
	for i, datas in pairs(LINKS) do
		if datas[2] ~= '' then -- if video link
			if datas[3] ~= '' then -- if comment
				if find(datas[3], 'sub') or find(datas[3], 'reprint') then -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!TODO: what about "authorized reprint"
					table.insert(tensai, '{{l|' .. datas[1] .. '|' .. datas[2] .. '|' .. datas[3] .. '}}')
				else
					table.insert(honke, '{{l|' .. datas[1] .. '|' .. datas[2] .. '|' .. datas[3]  .. '}}')
				end
			else
				table.insert(honke, '{{l|' .. datas[1] .. '|' .. datas[2] .. '}}')
			end
		end
	end
	honke = table.concat(honke, ' ') .. ETC
	tensai = table.concat(tensai, ' ')
	if honke == '' then honke = nil end
	if tensai == '' then tensai = nil end
	if tensai and not honke then
		honke = tensai
		tensai = nil
	end

	if find(views, '%(') then
		views = replace(views, ', and', '◆')
		views = replace(views, ', &', '◆')
		views = replace(views, 'and', '◆')
		views = replace(views, ', ', '◆')
		views = replace(views, '; ', '◆')
		views = replace(views, '&', '◆')
		views = replace(views, '/', '◆')
		views = replace(views, '+', '')
		views = replace(views, 'NND', 'nn')
		views = replace(views, '([0-9,]+) *%((..)%)', '{{v|%2|%1}}')
		views = mw.ustring.lower(views)
		views = replace(views, ' *◆ *', '◆')
	else
		if honke then
			views = '{{v|' .. match(honke, '{{l|(..)') .. '|' .. replace(views, '+', '') .. '}}'
		end
	end
	views = split(views, '◆')
	if #views == 2 then
		views = views[1] .. ' and ' .. views[2]
	else
		views = mw.text.listToText(views, ', ', ', and ')
	end

	text = text .. '\n  |color     = ' .. color
	text = text .. '\n  |image     = ' .. image
	text = text .. '\n  |title     = ' .. title
	text = text .. '\n  |date      = ' .. date
	text = text .. '\n  |views     = ' .. views
	text = text .. '\n  |singers   = ' .. singers
	text = text .. '\n  |producers = ' .. producers
	text = text .. '\n  |links     = ' .. (honke and honke or '')
	text = text .. (tensai and '\n* ' .. tensai or '')
	text = text .. '\n}}'

	return text
end

return export
Advertisement