模块:SongPlayer:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第10行: | 第10行: | ||
return '' | return '' | ||
end | end | ||
frame:addModules('ext.APlayer') | |||
local sanitizedTitle = title | local sanitizedTitle = title | ||
2025年11月29日 (六) 21:41的版本
此模块的文档可以在模块: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
frame:addModules('ext.APlayer')
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