Module:Video: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
need to fix this first
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:


function p.file( frame )
function p.file( frame )
-- if frame.args[2] and frame.args[2] ~= 'none' then
-- looks for a webm file that matches the first and second arguments separated by a dash and ends in '-voice'
-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..frame.args[2]..'-voice.webm', 'yes'}}
if frame.args[2] and frame.args[2] ~= 'none' then
-- if fileexists == 'yes' then
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..frame.args[2]..'-voice.webm', 'yes'}}
-- return frame.args[1]..'-'..frame.args[2]..'-voice.webm'
if fileexists == 'yes' then
-- end
return frame.args[1]..'-'..frame.args[2]..'-voice.webm'
-- end
end
end
-- for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
-- looks for a webm file that matches:
-- if frame.args[1]:match('^' .. source) == source then
-- a matched source at the beginning of the first argument,
-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..source..'-voice.webm', 'yes'}}
-- and appends the matched source to the first argument separated by a dash,
-- if fileexists == 'yes' then
-- and ends in '-voice'
-- return frame.args[1]..'-'..source..'-voice.webm'
for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
-- end
if frame.args[1]:match('^' .. source) == source then
-- break
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..source..'-voice.webm', 'yes'}}
-- end
if fileexists == 'yes' then
-- end
return frame.args[1]..'-'..source..'-voice.webm'
end
break
end
end


-- looks for a webm file that matches the first argument by itself
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.webm', 'yes'}}
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.webm', 'yes'}}
if fileexists == 'yes' then
if fileexists == 'yes' then
Line 24: Line 30:
end
end
-- returns a gif using the first argument with its last two parts separated by dashes removed
local lines = p.split(frame.args[1], '-')
local lines = p.split(frame.args[1], '-')
local parent2 = ''
local parent2 = ''
Line 34: Line 41:
end
end
end
end
return parent2..'.gif'
return parent2..'.gif'
end
end

Latest revision as of 21:42, 12 September 2025

usage[edit | hide]

unknown file[edit | hide]

{{#invoke:video|file|unknown file}}

unknown file.gif

found video[edit | hide]

[[File:{{#invoke:video|file|RoE 1.0 CD-Heroes3-DATA-HEROES3 VID-EVIL1A-smk-EVIL1A}}|200px]]

found gif[edit | hide]

This one will fail to find anything with webm because of the added text to the end. Then it will cut off the last two sections separated by a dash and so actually find a gif that matches:

[[File:{{#invoke:video|file|RoE 1.0 CD-Heroes3-DATA-HEROES3 VID-EVIL1A-smk-EVIL1Axyz123}}|200px]]


local p = {}

function p.file( frame )
	-- looks for a webm file that matches the first and second arguments separated by a dash and ends in '-voice'
	if frame.args[2] and frame.args[2] ~= 'none' then
		fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..frame.args[2]..'-voice.webm', 'yes'}}
		if fileexists == 'yes' then
			return frame.args[1]..'-'..frame.args[2]..'-voice.webm'
		end	
	end
	
	-- looks for a webm file that matches:
		-- a matched source at the beginning of the first argument,
		-- and appends the matched source to the first argument separated by a dash,
		-- and ends in '-voice'
	for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
		if frame.args[1]:match('^' .. source) == source then
			fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..source..'-voice.webm', 'yes'}}
			if fileexists == 'yes' then
				return frame.args[1]..'-'..source..'-voice.webm'
			end
			break
		end
	end

	-- looks for a webm file that matches the first argument by itself
	fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.webm', 'yes'}}
	if fileexists == 'yes' then
		return frame.args[1]..'.webm'
	end
	
	-- returns a gif using the first argument with its last two parts separated by dashes removed
	local lines = p.split(frame.args[1], '-')
	local parent2 = ''
	for i, line in ipairs(lines) do
	   parent2 = parent2 .. line
		if i + 2 >= #lines then
			break
		else
			parent2 = parent2 .. '-'
		end
	end
	return parent2..'.gif'
end

function p.split(str, sep)
   local result = {}
   local regex = ("([^%s]+)"):format(sep)
   for each in str:gmatch(regex) do
      table.insert(result, each)
   end
   return result
end

return p