Module:Video

From Heroes 3 wiki
Revision as of 00:40, 13 February 2024 by Imahero (talk | contribs)
Jump to navigation Jump to search

usage

unknown file

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

file:unknown file.png

found video

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

File:File:RoE 1.0 CD-Heroes3-DATA-HEROES3 VID-EVIL1A-smk-EVIL1A.webm

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:File:RoE 1.0 CD-Heroes3-DATA-HEROES3 VID-EVIL1A.png


local p = {}

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