Module:Video: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
function p.file( frame )
function p.file( frame )
for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
if frame.args[1]:match('^' .. source) ~= nil then
whatisitreturning = frame.args[1]:match('^' .. source)
fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..source..'-voice.webm', 'yes'}}
if whatisitreturning then
if fileexists == 'yes' then
return whatisitreturning
return frame.args[1]..'-'..source..'-voice.webm'
--fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'-'..source..'-voice.webm', 'yes'}}
end
--if fileexists == 'yes' then
break
-- return frame.args[1]..'-'..source..'-voice.webm'
--end
--break
end
end
end
end

Revision as of 21:42, 19 February 2024

usage

unknown file

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

unknown file.gif

found video

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

File:RoE

found gif

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]]

File:RoE


local p = {}

function p.file( frame )
	for _, source in pairs({'RoE', 'AB', 'SoD', 'HC', 'HotA'}) do
		whatisitreturning = frame.args[1]:match('^' .. source)
		if whatisitreturning then
			return whatisitreturning
			--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

	fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.webm', 'yes'}}
	if fileexists == 'yes' then
		return frame.args[1]..'.webm'
	end
	
	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