Module:Video: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:
  result = result .. i .. ':' .. line
  result = result .. i .. ':' .. line
end
end
return result
return (#lines)
-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.png', 'yes'}}
-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.png', 'yes'}}

Revision as of 00:30, 13 February 2024

usage

unknown file

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

1

found video

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

File:7

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


local p = {}

function p.file( frame )
	-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.webm', 'yes'}}
	-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.ogg', 'yes'}}
	
	local lines = p.split(frame.args[1], '-')
	local result = ''
	for i, line in ipairs(lines) do
	   result = result .. i .. ':' .. line
	end
	return (#lines)
	
	-- fileexists = frame:expandTemplate{title = 'exist', args = {'file:'..frame.args[1]..'.png', 'yes'}}
	-- if frame.args[1] == 'if'  then
	-- 	return 'if'
	-- elseif frame.args[1] == 'elseif'  then
	-- 	return 'elseif'
	-- else
	-- 	return 'else'
	-- end
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