יחידה:EmbedMedia
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:EmbedMedia/תיעוד
local p = {}
function p.embed(frame)
local url = frame.args.url or frame.args[1]
local width = frame.args.width or "100%"
local height = frame.args.height or "360"
local autoplay = frame.args.autoplay == "true" and "autoplay" or ""
local loop = frame.args.loop == "true" and "loop" or ""
local muted = frame.args.muted == "true" and "muted" or ""
if not url or url == "" then
return '<span style="color:red;">שגיאה: לא סופק קישור למדיה</span>'
end
-- YouTube
local yt_id = url:match("v=([%w%-_]+)") or url:match("youtu%.be/([%w%-_]+)")
if yt_id then
local embed_url = "https://www.youtube.com/embed/"..yt_id
return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
end
-- Vimeo
local vimeo_id = url:match("vimeo.com/(%d+)")
if vimeo_id then
local embed_url = "https://player.vimeo.com/video/"..vimeo_id
return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
end
-- MP4
if url:match("%.mp4$") then
return string.format('<video width="%s" height="%s" controls %s %s %s><source src="%s" type="video/mp4">דפדפן זה אינו תומך בהטמעת וידאו.</video>', width, height, autoplay, loop, muted, url)
end
-- MP3
if url:match("%.mp3$") then
return string.format('<audio controls %s %s %s><source src="%s" type="audio/mpeg">דפדפן זה אינו תומך בהטמעת שמע.</audio>', autoplay, loop, muted, url)
end
-- SoundCloud (צריך iframe)
if url:match("soundcloud.com") then
return string.format('<iframe width="%s" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=%s"></iframe>', width, url)
end
return '<span style="color:red;">שגיאה: סוג מדיה לא נתמך</span>'
end
return p