יחידה:EmbedMedia
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:EmbedMedia/תיעוד
-- Module: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 "315"
local autoplay = frame.args.autoplay == "true" and 1 or 0
local loop = frame.args.loop == "true" and 1 or 0
local muted = frame.args.muted == "true" and 1 or 0
if not url or url == "" then
return '<span style="color:red;">שגיאה: לא סופק קישור למדיה</span>'
end
local iframe_template = '<div style="position:relative;padding-bottom:56.25%%;height:0;overflow:hidden;"><iframe src="%s" width="100%%" height="100%%" style="position:absolute;top:0;left:0;width:100%%;height:100%%;" frameborder="0" allowfullscreen></iframe></div>'
-- YouTube
local yt_id = url:match("v=([%w%-_]+)") or url:match("youtu%.be/([%w%-_]+)")
if yt_id then
local yt_url = string.format("https://www.youtube.com/embed/%s?autoplay=%d&loop=%d&mute=%d", yt_id, autoplay, loop, muted)
return string.format(iframe_template, yt_url)
end
-- Vimeo
local vimeo_id = url:match("vimeo.com/(%d+)")
if vimeo_id then
local vimeo_url = string.format("https://player.vimeo.com/video/%s?autoplay=%d&loop=%d&muted=%d", vimeo_id, autoplay, loop, muted)
return string.format(iframe_template, vimeo_url)
end
-- Dailymotion
local dm_id = url:match("dailymotion.com/video/([%w]+)")
if dm_id then
local dm_url = string.format("https://www.dailymotion.com/embed/video/%s?autoplay=%d&loop=%d&mute=%d", dm_id, autoplay, loop, muted)
return string.format(iframe_template, dm_url)
end
-- TikTok
if string.match(url, "tiktok.com") then
return string.format(iframe_template, url)
end
-- SoundCloud
if string.match(url, "soundcloud.com") then
return string.format('<iframe width="100%%" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=%s&auto_play=%d"></iframe>', url, autoplay)
end
-- Google Drive Video
local drive_id = url:match("/file/d/([%w%-_]+)")
if drive_id then
local drive_embed = "https://drive.google.com/file/d/"..drive_id.."/preview"
return string.format(iframe_template, drive_embed)
end
-- Slideshare
if string.match(url, "slideshare.net") then
return string.format('<iframe src="%s" width="100%%" height="500" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #ccc; border-width:1px; margin-bottom:5px; max-width:100%%;" allowfullscreen></iframe>', url)
end
-- MP4
if string.match(url, "%.mp4$") then
return string.format('<video width="%s" height="%s" controls autoplay="%d" loop="%d" muted="%d"><source src="%s" type="video/mp4">דפדפן זה אינו תומך בהטמעת וידאו.</video>', width, height, autoplay, loop, muted, url)
end
-- MP3
if string.match(url, "%.mp3$") then
return string.format('<audio controls autoplay="%d" loop="%d" muted="%d"><source src="%s" type="audio/mpeg">דפדפן זה אינו תומך בהטמעת שמע.</audio>', autoplay, loop, muted, url)
end
-- ברירת מחדל: iframe רגיל
return string.format(iframe_template, url)
end
return p