Модуль: Videogallery old: различия между версиями 🔗
Sphynkx (обсуждение | вклад) (Created page with "-- Module for replacing of combination of EmbedVideo-ext + my Ev-template with more faster lua-implementation -- Test page: http://emwikitest.sphynkx.org.ua/Sandbox/Videogalle...") |
Sphynkx (обсуждение | вклад) Нет описания правки |
||
Строка 9: | Строка 9: | ||
if string.match(u,'youtube') then | if string.match(u,'youtube') then | ||
id = string.gsub(u,'.*youtube.com%/watch%?v%=(.*)','%1') | id = string.gsub(u,'.*youtube.com%/watch%?v%=(.*)','%1') | ||
return '<html><iframe src="https://www.youtube.com/embed/'..id..'" width="300" height="250" frameborder="1" allowfullscreen="true" style="white-space: nowrap; display: -webkit-flex; -webkit-flex-direction: row; display: flex; flex-direction: row;" align="baseline" seamless></iframe></html>[[ | return '<html><iframe src="https://www.youtube.com/embed/'..id..'" width="300" height="250" frameborder="1" allowfullscreen="true" style="white-space: nowrap; display: -webkit-flex; -webkit-flex-direction: row; display: flex; flex-direction: row;" align="baseline" seamless></iframe></html>[[File:Youtube.png|24px|left|link=]]' | ||
elseif string.match(u,'emtube') then | elseif string.match(u,'emtube') then | ||
id = string.gsub(u,'.*emtube.-/watch%?v%=(.*)','%1') | id = string.gsub(u,'.*emtube.-/watch%?v%=(.*)','%1') | ||
return '<html><iframe src="https://emtube.sphynkx.org.ua/embed?vid='..id..'&width=300&height=250&autoplay=no" frameborder="1" allowfullscreen scrolling="yes" width="300" height="250" seamless></iframe></html><br>[[ | return '<html><iframe src="https://emtube.sphynkx.org.ua/embed?vid='..id..'&width=300&height=250&autoplay=no" frameborder="1" allowfullscreen scrolling="yes" width="300" height="250" seamless></iframe></html><br>[[File:emtube.png|24px|left|link=]]' | ||
elseif string.match(u,'rutube') then | elseif string.match(u,'rutube') then | ||
id = string.gsub(u,'.*rutube.ru%/video/(.*)/','%1') | id = string.gsub(u,'.*rutube.ru%/video/(.*)/','%1') | ||
return '<html><iframe src="//rutube.ru/play/embed/'..id..'" width="300" height="250" frameborder="1" allowfullscreen="true"></iframe></html><br>[[ | return '<html><iframe src="//rutube.ru/play/embed/'..id..'" width="300" height="250" frameborder="1" allowfullscreen="true"></iframe></html><br>[[File:rutube.png|24px|left|link=]]' | ||
else return '<div style="display: block; border: 1px solid red; width:300px; max-width:300px; height:250px; max-height:250px; "> </div>[[ | else return '<div style="display: block; border: 1px solid red; width:300px; max-width:300px; height:250px; max-height:250px; "> </div>[[File:Unknown.png|24px|left|link=]]' | ||
end | end | ||
end | end |
Версия от 23:52, 10 июня 2020
-- Module for replacing of combination of EmbedVideo-ext + my Ev-template with more faster lua-implementation -- Test page: http://emwikitest.sphynkx.org.ua/Sandbox/Videogallery -- v.1: Supported services are YouTube, RuTube, EMTube, OK -- v.2: Added optional collapsibility.
local p = {} -- p stands for package
function get_embed(u)
if string.match(u,'youtube') then id = string.gsub(u,'.*youtube.com%/watch%?v%=(.*)','%1')
return '
'
elseif string.match(u,'emtube') then id = string.gsub(u,'.*emtube.-/watch%?v%=(.*)','%1')
return '
'
elseif string.match(u,'rutube') then id = string.gsub(u,'.*rutube.ru%/video/(.*)/','%1')
return '
' else return '
'
end
end
--format final code with iframe
function format_embed(d, u, t, c)
e=get_embed(u)
return ''..e..d..'
'..' ['..u..' '..t..']
'..c
end
function p.videos( frame )
local vidlist = frame.args['VIDEOS']
local vidlist_rows = frame.args['VIDEO_ROWS']
local vidlist_border = frame.args['VIDEO_BORDER']
local collapsed = frame.args['COLLAPSED']=='1' and ' mw-collapsed' or
local collapseHead = frame.args['COLLAPSIBLE']=='1' and frame:preprocess('') or
local collapseBody = frame.args['COLLAPSIBLE']=='1' and frame:preprocess('') or
local collapseEnd = frame.args['COLLAPSIBLE']=='1' and frame:preprocess('') or
-- escape STAR sign inside the text, that is not a list identifier vidlist=string.gsub(vidlist,'([^\n])%*', '%1*') vidcnt=1 vidtable = {} for i in string.gmatch(vidlist, '%*[^\*]*') do
i=string.gsub(i,'%*(.-)%[(.-) (.-)%](.*)', format_embed)
tr_start = math.fmod( vidcnt, vidlist_rows ) == 1 and '' or "" tr_end = math.fmod( vidcnt, vidlist_rows ) == 0 and '' or "" table.insert(vidtable, tr_start..''..i..''..tr_end)
vidcnt=vidcnt+1 end
-- here i reused as identifier of nonempty videogallery (for setting of category) i = (vidcnt>1) and "" or ""
return collapseHead .. table.getn(vidtable) .. ' videos' .. collapseBody .. '
' .. frame:preprocess(table.concat(vidtable)) .. ''.. i .. collapseEnd
end
return p