模块:SongPlayer:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第7行: | 第7行: | ||
local imageName = args.image | local imageName = args.image | ||
local c1 = args.color1 or '# | local c1 = args.color1 or '#94E1FF' | ||
local c2 = args.color2 or '# | local c2 = args.color2 or '#A3E5FF' | ||
local c3 = args.color3 or '# | local c3 = args.color3 or '#B2E9FE' | ||
local c4 = args.color4 or '# | local c4 = args.color4 or '#D5F3FE' | ||
if not title or title == '' or not imageName or imageName == '' then | if not title or title == '' or not imageName or imageName == '' then | ||
| 第50行: | 第50行: | ||
info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>') | info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>') | ||
return tostring(html) | html:tag('audio') | ||
:attr('id', 'riz-audio') | |||
:attr('src', songUrl) | |||
:attr('preload', 'none') | |||
return tostring(html) | |||
end | end | ||
return p | return p | ||
2025年11月30日 (日) 19:55的版本
此模块的文档可以在模块: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
local c1 = args.color1 or '#94E1FF'
local c2 = args.color2 or '#A3E5FF'
local c3 = args.color3 or '#B2E9FE'
local c4 = args.color4 or '#D5F3FE'
if not title or title == '' or not imageName or imageName == '' then
return ''
end
local sanitizedTitle = title:gsub(' ', '_'):gsub('[\\/:*?"<>|]', '-')
local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
local rawImagePath = frame:preprocess('{{filepath:' .. imageName .. '}}')
local imagePath = rawImagePath:gsub('^https?:', '')
local songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'
-- 构建主容器
local html = mw.html.create('div')
:attr('id', 'riz-player')
:addClass('riz-player-mini')
:css({
['--rp-c1'] = c1,
['--rp-c2'] = c2,
['--rp-c3'] = c3,
['--rp-c4'] = c4,
['display'] = 'none'
})
local cover = html:tag('div'):addClass('rp-cover')
cover:tag('img'):attr('src', imagePath):attr('alt', 'cover')
cover:tag('div'):addClass('rp-btn-toggle'):wikitext('<div class="rp-icon-play"></div><div class="rp-icon-pause"></div>')
local info = html:tag('div'):addClass('rp-info')
info:tag('div'):addClass('rp-title'):wikitext(title)
info:tag('div'):addClass('rp-artist'):wikitext(artist or '')
local progressWrap = info:tag('div'):addClass('rp-progress-wrap')
local progressBar = progressWrap:tag('div'):addClass('rp-progress-bar')
progressBar:tag('div'):addClass('rp-progress-current')
progressBar:tag('div'):addClass('rp-progress-handle')
info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>')
html:tag('audio')
:attr('id', 'riz-audio')
:attr('src', songUrl)
:attr('preload', 'none')
return tostring(html)
end
return p