模块:SongPlayer
来自Rizline中文维基
更多操作
此模块的文档可以在模块:SongPlayer/doc创建
local p = {}
function p.player(frame)
local args = frame:getParent().args
local title = args.title
local artist = args.artist
local imageName = args.image
if not title or title == '' or not imageName or imageName == '' then
return ''
end
local sanitizedTitle = title
sanitizedTitle = sanitizedTitle:gsub(' ', '_')
sanitizedTitle = sanitizedTitle:gsub('[\\/:*?"<>|]', '-')
local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}')
local songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'
local data_div = mw.html.create('div')
:attr('id', 'song-player-data')
:attr('style', 'display:none;')
:attr('data-name', title)
:attr('data-artist', artist or 'Unknown Artist')
:attr('data-url', songUrl)
:attr('data-cover', imagePath)
:done()
local html = {
'<div id="song-player-fixed"></div>',
tostring(data_div)
}
return table.concat(html, '\n')
end
return p