模块:SongPlayer:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第17行: | 第17行: | ||
local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH') | local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH') | ||
local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}') | local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}') | ||
local songUrl = ' | local songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3' | ||
local data_div = mw.html.create('div') | local data_div = mw.html.create('div') | ||
2025年11月29日 (六) 19:54的版本
此模块的文档可以在模块: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