更新 music168.lua

This commit is contained in:
2025-11-12 16:06:05 +08:00
parent ca4e086a66
commit c0f275cc9d

View File

@@ -1,372 +1,373 @@
-----------------------------------------------------------------系统启动阶段------------------------------------------------------------------------------------------------- -----------------------------------------------------------------系统启动阶段-------------------------------------------------------------------------------------------------
--*获取程序所在目录 --*获取程序所在目录
local mypath = "/"..fs.getDir(shell.getRunningProgram()) local mypath = "/"..fs.getDir(shell.getRunningProgram())
if not fs.exists(mypath.."/lib/basalt.lua") then shell.run("wget https://git.liulikeji.cn/GitHub/Basalt/releases/download/v1.6.3/basalt.lua lib/basalt.lua") end if not fs.exists(mypath.."/lib/basalt.lua") then shell.run("wget https://git.liulikeji.cn/GitHub/Basalt/releases/download/v1.6.3/basalt.lua lib/basalt.lua") end
if not fs.exists(mypath.."/speakerlib.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/ComputerCraft-Music168-Player/releases/download/v1.1.0/speakerlib.lua") end if not fs.exists(mypath.."/speakerlib.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/ComputerCraft-Music168-Player/raw/branch/1.1.0/speakerlib.lua") end
if not fs.exists(mypath.."/MusicLyrics.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/ComputerCraft-Music168-Player/raw/branch/1.1.0/MusicLyrics.lua") end
--*GUI库导入
basalt = require(mypath.."/lib/basalt") --*GUI库导入
--*初始化GUI框架 basalt = require(mypath.."/lib/basalt")
local mainf = basalt.createFrame() --*初始化GUI框架
main = { local mainf = basalt.createFrame()
mainf:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):setBackground(colors.red), main = {
} mainf:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):setBackground(colors.red),
_G.Playprint = false }
_G.Playopen =false _G.Playprint = false
--*GUI框架配置表 _G.Playopen =false
local sub = { --*GUI框架配置表
["UI"] = { local sub = {
main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.red), ["UI"] = {
main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(), main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.red),
main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(), main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(),
main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.red):hide(), main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(),
main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(), main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.red):hide(),
}, main[1]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h -2"):setBackground(colors.white):hide(),
["menu"] ={ },
main[1]:addFrame():setPosition(1, "parent.h"):setSize("parent.w", 1):setBackground(colors.lightGray), ["menu"] ={
}, main[1]:addFrame():setPosition(1, "parent.h"):setSize("parent.w", 1):setBackground(colors.lightGray),
["BF"] = { },
mainf:addFrame():setPosition(1, "parent.h + 1"):setSize("parent.w", "parent.h"):setBackground(colors.red), ["BF"] = {
main[1]:addFrame():setPosition(1, "parent.h - 1"):setSize("parent.w", 1):setBackground(colors.lightGray):hide(), mainf:addFrame():setPosition(1, "parent.h + 1"):setSize("parent.w", "parent.h"):setBackground(colors.red),
}, main[1]:addFrame():setPosition(1, "parent.h - 1"):setSize("parent.w", 1):setBackground(colors.lightGray):hide(),
["play_table"] = { },
mainf:addFrame():setPosition(2, "parent.h + 1"):setSize("parent.w-2", 13):setBackground(colors.orange), ["play_table"] = {
} mainf:addFrame():setPosition(2, "parent.h + 1"):setSize("parent.w-2", 13):setBackground(colors.orange),
} }
--创建动画 }
play_Gui_UP = mainf:addAnimation():setObject(sub["BF"][1]):move(1,1,0.3) --创建动画
play_Gui_DO = mainf:addAnimation():setObject(sub["BF"][1]):move(1,mainf:getHeight()+1,1) play_Gui_UP = mainf:addAnimation():setObject(sub["BF"][1]):move(1,1,0.3)
play_table_Gui_UP = mainf:addAnimation():setObject(sub["play_table"][1]):move(2,mainf:getHeight()-12,0.3) play_Gui_DO = mainf:addAnimation():setObject(sub["BF"][1]):move(1,mainf:getHeight()+1,1)
play_table_Gui_DO = mainf:addAnimation():setObject(sub["play_table"][1]):move(2,mainf:getHeight()+1,1) play_table_Gui_UP = mainf:addAnimation():setObject(sub["play_table"][1]):move(2,mainf:getHeight()-12,0.3)
--play_Gui_UP:play() play_table_Gui_DO = mainf:addAnimation():setObject(sub["play_table"][1]):move(2,mainf:getHeight()+1,1)
--main[1]:hide() --play_Gui_UP:play()
--main[1]:addAnimation():setObject(sub["BF"][1]):move(1,"parent.h+1",1.5):play() --main[1]:hide()
--创建播放界面 --main[1]:addAnimation():setObject(sub["BF"][1]):move(1,"parent.h+1",1.5):play()
play_name = "NO Music" --创建播放界面
play_id = "NO Music" play_name = "NO Music"
play_Gui = { play_id = "NO Music"
sub["BF"][1]:addButton():setPosition(1,1):setSize(3, 1):setText("V"):onClick(function() play_Gui_DO:play() play_GUI_state=false main[1]:enable() end):setBackground(colors.red):setForeground(colors.white), play_Gui = {
sub["BF"][1]:addLabel():setText("NO Music"):setPosition(sub["BF"][1]:getWidth()/2 - #play_name/2,1):setBackground(colors.red):setForeground(colors.white), sub["BF"][1]:addButton():setPosition(1,1):setSize(3, 1):setText("V"):onClick(function() play_Gui_DO:play() play_GUI_state=false main[1]:enable() end):setBackground(colors.red):setForeground(colors.white),
sub["BF"][1]:addLabel():setText("NO Music"):setPosition(sub["BF"][1]:getWidth()/2 - #play_id/2,2):setBackground(colors.red):setForeground(colors.white), sub["BF"][1]:addLabel():setText("NO Music"):setPosition(sub["BF"][1]:getWidth()/2 - #play_name/2,1):setBackground(colors.red):setForeground(colors.white),
sub["BF"][1]:addProgram():setPosition(2,2):setSize("parent.w-2", "parent.h-4"), sub["BF"][1]:addLabel():setText("NO Music"):setPosition(sub["BF"][1]:getWidth()/2 - #play_id/2,2):setBackground(colors.red):setForeground(colors.white),
1,--sub["BF"][1]:addButton():setPosition(3,"parent.h-5"):setSize(1, 1):setText("\3"):onClick(function() end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addProgram():setPosition(2,2):setSize("parent.w-2", "parent.h-4"),
1,--sub["BF"][1]:addButton():setPosition(8,"parent.h-5"):setSize(1, 1):setText("\25"):onClick(function() end):setForeground(colors.white):setBackground(colors.red), 1,--sub["BF"][1]:addButton():setPosition(3,"parent.h-5"):setSize(1, 1):setText("\3"):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
1,--sub["BF"][1]:addButton():setPosition("parent.w/2","parent.h-5"):setSize(2, 1):setText("+-"):onClick(function() end):setForeground(colors.white):setBackground(colors.red), 1,--sub["BF"][1]:addButton():setPosition(8,"parent.h-5"):setSize(1, 1):setText("\25"):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
1,--sub["BF"][1]:addButton():setPosition("parent.w-3","parent.h-5"):setSize(1, 1):setText("@"):onClick(function() end):setForeground(colors.white):setBackground(colors.red), 1,--sub["BF"][1]:addButton():setPosition("parent.w/2","parent.h-5"):setSize(2, 1):setText("+-"):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
1,--sub["BF"][1]:addButton():setPosition("parent.w-8","parent.h-5"):setSize(1, 1):setText("E"):onClick(function() end):setForeground(colors.white):setBackground(colors.red), 1,--sub["BF"][1]:addButton():setPosition("parent.w-3","parent.h-5"):setSize(1, 1):setText("@"):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addProgressbar():setPosition(3, "parent.h - 2"):setSize("parent.w - 4", 1):setProgressBar(colors.red, "=", colors.white):setBackground(colors.red):setBackgroundSymbol("-"):setForeground(colors.white), 1,--sub["BF"][1]:addButton():setPosition("parent.w-8","parent.h-5"):setSize(1, 1):setText("E"):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addLabel():setText("00:00"):setPosition("3", "parent.h - 1"):setSize(5, 1):setForeground(colors.white), sub["BF"][1]:addProgressbar():setPosition(3, "parent.h - 2"):setSize("parent.w - 4", 1):setProgressBar(colors.red, "=", colors.white):setBackground(colors.red):setBackgroundSymbol("-"):setForeground(colors.white),
sub["BF"][1]:addLabel():setText("00:00"):setPosition("parent.w - 6", "parent.h - 1"):setSize(5, 1):setForeground(colors.white), sub["BF"][1]:addLabel():setText("00:00"):setPosition("3", "parent.h - 1"):setSize(5, 1):setForeground(colors.white),
sub["BF"][1]:addButton():setPosition(3, "parent.h - 0"):setSize(3, 1):setText("=O="):onClick(function() end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addLabel():setText("00:00"):setPosition("parent.w - 6", "parent.h - 1"):setSize(5, 1):setForeground(colors.white),
sub["BF"][1]:addButton():setPosition("parent.w /2 - 4","parent.h - 0"):setSize(2, 1):setText("|\17"):onClick(function() play_set_1() end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addButton():setPosition(3, "parent.h - 0"):setSize(3, 1):setText("=O="):onClick(function() end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addButton():setPosition("parent.w / 2 ", "parent.h - 0"):setSize(2, 1):setText("I>"):onClick(function() if play_data_table["play"] then _G.Playstop = true play_data_table["play"]=false else play_data_table["play"]=true end end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addButton():setPosition("parent.w /2 - 4","parent.h - 0"):setSize(2, 1):setText("|\17"):onClick(function() play_set_1() end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addButton():setPosition("parent.w / 2 +4", "parent.h - 0"):setSize(2, 1):setText("\16|"):onClick(function() play_set_0() end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addButton():setPosition("parent.w / 2 ", "parent.h - 0"):setSize(2, 1):setText("I>"):onClick(function() if play_data_table["play"] then _G.Playstop = true play_data_table["play"]=false else play_data_table["play"]=true end end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addButton():setPosition("parent.w - 4", "parent.h - 0"):setSize(3, 1):setText("=T="):onClick(function() play_table_Gui_UP:play() main[1]:disable() sub["BF"][1]:disable() end):setForeground(colors.white):setBackground(colors.red), sub["BF"][1]:addButton():setPosition("parent.w / 2 +4", "parent.h - 0"):setSize(2, 1):setText("\16|"):onClick(function() play_set_0() end):setForeground(colors.white):setBackground(colors.red),
sub["BF"][1]:addSlider():setPosition(3, "parent.h - 2"):setSize("parent.w - 4", 1):setMaxValue(100):setBackground(colors.red):setForeground(colors.white),--:setBackgroundSymbol("\x8c"):setSymbol(" "), sub["BF"][1]:addButton():setPosition("parent.w - 4", "parent.h - 0"):setSize(3, 1):setText("=T="):onClick(function() play_table_Gui_UP:play() main[1]:disable() sub["BF"][1]:disable() end):setForeground(colors.white):setBackground(colors.red),
} sub["BF"][1]:addSlider():setPosition(3, "parent.h - 2"):setSize("parent.w - 4", 1):setMaxValue(100):setBackground(colors.red):setForeground(colors.white),--:setBackgroundSymbol("\x8c"):setSymbol(" "),
--创建播放UI }
play_column_Gui = { --创建播放UI
sub["BF"][2]:addLabel():setText(""):setPosition(1,1):setSize("parent.w-7",1):setBackground(colors.lightGray):setForeground(colors.white), play_column_Gui = {
sub["BF"][2]:addButton():setPosition("parent.w -4 ", 1):setSize(2, 1):setText("I>"):onClick(function() if play_data_table["play"] then _G.Playstop = true play_data_table["play"]=false else play_data_table["play"]=true end end):setForeground(colors.white):setBackground(colors.lightGray), sub["BF"][2]:addLabel():setText(""):setPosition(1,1):setSize("parent.w-7",1):setBackground(colors.lightGray):setForeground(colors.white),
sub["BF"][2]:addButton():setPosition("parent.w-1", 1):setSize(1, 1):setText("T"):onClick(function() play_table_Gui_UP:play() main[1]:disable() end):setForeground(colors.white):setBackground(colors.lightGray), sub["BF"][2]:addButton():setPosition("parent.w -4 ", 1):setSize(2, 1):setText("I>"):onClick(function() if play_data_table["play"] then _G.Playstop = true play_data_table["play"]=false else play_data_table["play"]=true end end):setForeground(colors.white):setBackground(colors.lightGray),
sub["BF"][2]:addButton():setPosition(1, 1):setSize("parent.w -5", 1):setText(""):onClick(function() play_Gui_UP:play() play_GUI_state=true main[1]:disable() end):setBackground(colors.lights), sub["BF"][2]:addButton():setPosition("parent.w-1", 1):setSize(1, 1):setText("T"):onClick(function() play_table_Gui_UP:play() main[1]:disable() end):setForeground(colors.white):setBackground(colors.lightGray),
} sub["BF"][2]:addButton():setPosition(1, 1):setSize("parent.w -5", 1):setText(""):onClick(function() play_Gui_UP:play() play_GUI_state=true main[1]:disable() end):setBackground(colors.lights),
play_table_Gui = { }
sub["play_table"][1]:addButton():setPosition("parent.w-3",1):setSize(3, 1):setText("V"):onClick(function() if not play_GUI_state then main[1]:enable() end sub["BF"][1]:enable() play_table_Gui_DO:play() end):setBackground(colors.no):setForeground(colors.white), play_table_Gui = {
sub["play_table"][1]:addLabel():setText("PlyaTable"):setPosition(1,1):setForeground(colors.white), sub["play_table"][1]:addButton():setPosition("parent.w-3",1):setSize(3, 1):setText("V"):onClick(function() if not play_GUI_state then main[1]:enable() end sub["BF"][1]:enable() play_table_Gui_DO:play() end):setBackground(colors.no):setForeground(colors.white),
sub["play_table"][1]:addList():setPosition(2,3):setSize("parent.w-2", "parent.h-2"):setScrollable(true), sub["play_table"][1]:addLabel():setText("PlyaTable"):setPosition(1,1):setForeground(colors.white),
} sub["play_table"][1]:addList():setPosition(2,3):setSize("parent.w-2", "parent.h-2"):setScrollable(true),
--创建菜单栏 }
menuBut = { --创建菜单栏
sub["menu"][1]:addButton():setPosition(3,1):setSize(3, 1):setText("{Q}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[1]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][1]:show() end):setForeground(colors.white):setBackground(colors.red), menuBut = {
sub["menu"][1]:addButton():setPosition(8,1):setSize(3, 1):setText("{T}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[2]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][2]:show() end):setForeground(colors.white):setBackground(colors.lightGray), sub["menu"][1]:addButton():setPosition(3,1):setSize(3, 1):setText("{Q}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[1]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][1]:show() end):setForeground(colors.white):setBackground(colors.red),
sub["menu"][1]:addButton():setPosition(12,1):setSize(4, 1):setText("{PH}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[3]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][3]:show() end):setForeground(colors.white):setBackground(colors.lightGray), sub["menu"][1]:addButton():setPosition(8,1):setSize(3, 1):setText("{T}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[2]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][2]:show() end):setForeground(colors.white):setBackground(colors.lightGray),
sub["menu"][1]:addButton():setPosition(17,1):setSize(3, 1):setText("{G}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[4]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][4]:show() end):setForeground(colors.white):setBackground(colors.lightGray), sub["menu"][1]:addButton():setPosition(12,1):setSize(4, 1):setText("{PH}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[3]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][3]:show() end):setForeground(colors.white):setBackground(colors.lightGray),
sub["menu"][1]:addButton():setPosition(22,1):setSize(3, 1):setText("{Z}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[5]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][5]:show() end):setForeground(colors.white):setBackground(colors.lightGray), sub["menu"][1]:addButton():setPosition(17,1):setSize(3, 1):setText("{G}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[4]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][4]:show() end):setForeground(colors.white):setBackground(colors.lightGray),
} sub["menu"][1]:addButton():setPosition(22,1):setSize(3, 1):setText("{Z}"):onClick(function() for index, value in ipairs(menuBut) do value:setBackground(colors.lightGray) end menuBut[5]:setBackground(colors.red) for index, value in ipairs(sub["UI"]) do value:hide() end sub["UI"][5]:show() end):setForeground(colors.white):setBackground(colors.lightGray),
-----------------------------------------------------------------DATA--------------------------------------------------------------------------------------------------------- }
play_data_table = { ["music"] = {} , ["play"] = false ,["play_table"] = {}, ["play_table_index"] = 0, ["mode"] = "" , } -----------------------------------------------------------------DATA---------------------------------------------------------------------------------------------------------
_G.Playopen = false play_data_table = { ["music"] = {} , ["play"] = false ,["play_table"] = {}, ["play_table_index"] = 0, ["mode"] = "" , }
_G.getPlay = 0 _G.Playopen = false
_G.getPlaymax = 0 _G.getPlay = 0
_G.setPlay = nil _G.getPlaymax = 0
-----------------------------------------------------------------模块--------------------------------------------------------------------------------------------------------- _G.setPlay = nil
-----------------------------------------------------------------模块---------------------------------------------------------------------------------------------------------
--音乐+
function play_set_1() --音乐+
_G.music168_playopen = false os.queueEvent("music168_play_stop") function play_set_1()
_G.getPlay = 0 _G.music168_playopen = false os.queueEvent("music168_play_stop")
_G.Playopen = false _G.getPlay = 0
_G.Playstop = false _G.Playopen = false
table_index = play_table_Gui[3]:getItemIndex() _G.Playstop = false
if table_index <= 1 then table_index = play_table_Gui[3]:getItemIndex()
play_table_Gui[3]:selectItem(play_table_Gui[3]:getItemCount()) if table_index <= 1 then
else play_table_Gui[3]:selectItem(play_table_Gui[3]:getItemCount())
play_table_Gui[3]:selectItem(table_index-1) else
end play_table_Gui[3]:selectItem(table_index-1)
end end
--音乐- end
function play_set_0() --音乐-
_G.music168_playopen = false os.queueEvent("music168_play_stop") function play_set_0()
_G.getPlay = 0 _G.music168_playopen = false os.queueEvent("music168_play_stop")
_G.Playopen = false _G.getPlay = 0
_G.Playstop = false _G.Playopen = false
table_index = play_table_Gui[3]:getItemIndex() _G.Playstop = false
if table_index >= play_table_Gui[3]:getItemCount() then table_index = play_table_Gui[3]:getItemIndex()
play_table_Gui[3]:selectItem(1) if table_index >= play_table_Gui[3]:getItemCount() then
else play_table_Gui[3]:selectItem(1)
play_table_Gui[3]:selectItem(table_index+1) else
end play_table_Gui[3]:selectItem(table_index+1)
end end
--获取URL end
function GetmusicUrl(music_id) --获取URL
while true do function GetmusicUrl(music_id)
local http = http.post(server_url.."api/song/url",textutils.serialiseJSON({["id"]=music_id})) while true do
if http then local http = http.post(server_url.."api/song/url",textutils.serialiseJSON({["id"]=music_id}))
json_str = http.readAll() if http then
local table = textutils.unserialiseJSON(json_str) json_str = http.readAll()
if table["data"][1]["url"] then local table = textutils.unserialiseJSON(json_str)
return(table["data"][1]["url"]) if table["data"][1]["url"] then
end return(table["data"][1]["url"])
end end
end end
end end
--dfpwm转码 end
--播放 --dfpwm转码
function playmusic(music_name,music_id,play_table,index) --播放
_G.getPlay = 0 function playmusic(music_name,music_id,play_table,index)
_G.getPlaymax = 0 _G.getPlay = 0
_G.Playopen = false _G.getPlaymax = 0
_G.music168_playopen = false os.queueEvent("music168_play_stop") _G.Playopen = false
_G.music168_playopen = false os.queueEvent("music168_play_stop")
play_Gui[2]:setText(music_name):setPosition(sub["BF"][1]:getWidth()/2 +1 - #music_name/2,1)
play_Gui[3]:setText(music_id):setPosition(sub["BF"][1]:getWidth()/2 +1 - #tostring(music_id)/2,2) play_Gui[2]:setText(music_name):setPosition(sub["BF"][1]:getWidth()/2 +1 - #music_name/2,1)
play_column_Gui[1]:setText(music_name.." | "..tostring(music_id)) play_Gui[3]:setText(music_id):setPosition(sub["BF"][1]:getWidth()/2 +1 - #tostring(music_id)/2,2)
play_data_table["music"] = { ["music_id"] = music_id, ["music_name"] = music_name } play_column_Gui[1]:setText(music_name.." | "..tostring(music_id))
play_data_table["play_table"] = play_table play_data_table["music"] = { ["music_id"] = music_id, ["music_name"] = music_name }
play_data_table["play_table_index"] = index play_data_table["play_table"] = play_table
play_data_table["play"] = true play_data_table["play_table_index"] = index
play_table_Gui[3]:clear() play_data_table["play"] = true
for index, value in ipairs(play_table) do play_table_Gui[3]:clear()
play_table_Gui[3]:addItem(value["name"].." | "..tostring(value["id"])) for index, value in ipairs(play_table) do
end play_table_Gui[3]:addItem(value["name"].." | "..tostring(value["id"]))
end
play_table_Gui[3]:selectItem(index)
_G.music168_music_id = music_id play_table_Gui[3]:selectItem(index)
_G.music168_music_id = music_id
_G.music168_playopen = true
--basalt.debug("true") _G.music168_playopen = true
--play_thread_id = AddThread(function () --basalt.debug("true")
-- --play_thread_id = AddThread(function ()
--end) --
end --end)
end
printUtf8 = load(http.get("https://alist.liulikeji.cn/d/HFS/utf8ptrint.lua").readAll())()
--搜索 printUtf8 = load(http.get("https://alist.liulikeji.cn/d/HFS/utf8ptrint.lua").readAll())()
server_url = "http://music168.liulikeji.cn:15843/" --搜索
function Search(input_str,GUI_in,api) server_url = "http://music168.liulikeji.cn:15843/"
Search_table = {} function Search(input_str,GUI_in,api)
while true do Search_table = {}
kg_a=false while true do
if api=="search" then kg_a=false
http1 = http.post(server_url.."api/search",textutils.serialiseJSON({["value"]=input_str})) if api=="search" then
json_str = http1.readAll() http1 = http.post(server_url.."api/search",textutils.serialiseJSON({["value"]=input_str}))
table_get = textutils.unserialiseJSON(json_str) json_str = http1.readAll()
if table_get["result"]["songCount"] ~= 0 then kg_a=true end table_get = textutils.unserialiseJSON(json_str)
elseif api=="playlist" then if table_get["result"]["songCount"] ~= 0 then kg_a=true end
http1 = http.post(server_url.."api/playlist/detail",textutils.serialiseJSON({["id"]=input_str})) elseif api=="playlist" then
json_str = http1.readAll() http1 = http.post(server_url.."api/playlist/detail",textutils.serialiseJSON({["id"]=input_str}))
table_get = textutils.unserialiseJSON(json_str) json_str = http1.readAll()
if table_get["code"] ~= 404 then kg_a=true end table_get = textutils.unserialiseJSON(json_str)
end if table_get["code"] ~= 404 then kg_a=true end
if http1 then end
if kg_a then if http1 then
if api=="search" then if kg_a then
for index, value in ipairs(table_get["result"]["songs"]) do if api=="search" then
out_table = {["id"] = value["id"],["name"]=value["name"],["artists_id"]=value["artists"][1]["id"],["artists_name"]=value["artists"][1]["name"]} for index, value in ipairs(table_get["result"]["songs"]) do
Search_table[index]=out_table out_table = {["id"] = value["id"],["name"]=value["name"],["artists_id"]=value["artists"][1]["id"],["artists_name"]=value["artists"][1]["name"]}
end Search_table[index]=out_table
elseif api=="playlist" then end
for index, value in ipairs(table_get["playlist"]["tracks"]) do elseif api=="playlist" then
out_table = {["id"] = value["id"],["name"]=value["name"],["artists_id"]=value["ar"][1]["id"],["artists_name"]=value["ar"][1]["name"]} for index, value in ipairs(table_get["playlist"]["tracks"]) do
Search_table[index]=out_table out_table = {["id"] = value["id"],["name"]=value["name"],["artists_id"]=value["ar"][1]["id"],["artists_name"]=value["ar"][1]["name"]}
end Search_table[index]=out_table
end end
a=2 end
if play_lib_F then play_lib_F:remove() end a=2
play_lib_F = GUI_in[3]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):setBackground(colors.white):setScrollable() if play_lib_F then play_lib_F:remove() end
for index, value in ipairs(Search_table) do play_lib_F = GUI_in[3]:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):setBackground(colors.white):setScrollable()
id = value["id"] for index, value in ipairs(Search_table) do
local frame = play_lib_F:addFrame():setPosition(2, a):setSize("parent.w-2", 4):setBackground(colors.lightBlue):onClick(function() if play_data_table["play"] then shell.run(mypath.."/speakerlib.lua stop") if _G.Playopen then end _G.music168_playopen = false os.queueEvent("music168_play_stop") play_data_table["play"]=false end play_Gui_UP:play() play_GUI_state = true main[1]:disable() _G.music168_playopen = false os.queueEvent("music168_play_stop") playmusic(value["name"],value["id"],Search_table,index) end) id = value["id"]
local textf = frame:addFrame():setPosition(1, 1):setSize("parent.w", 3) local frame = play_lib_F:addFrame():setPosition(2, a):setSize("parent.w-2", 4):setBackground(colors.lightBlue):onClick(function() if play_data_table["play"] then shell.run(mypath.."/speakerlib.lua stop") if _G.Playopen then end _G.music168_playopen = false os.queueEvent("music168_play_stop") play_data_table["play"]=false end play_Gui_UP:play() play_GUI_state = true main[1]:disable() _G.music168_playopen = false os.queueEvent("music168_play_stop") playmusic(value["name"],value["id"],Search_table,index) end)
textf:addProgram():setPosition(1, 1):setSize("parent.w", 4):execute(function () local textf = frame:addFrame():setPosition(1, 1):setSize("parent.w", 3)
term.setBackgroundColor(colors.lightGray) textf:addProgram():setPosition(1, 1):setSize("parent.w", 4):execute(function ()
term.clear() term.setBackgroundColor(colors.lightGray)
printUtf8(value["name"],colors.white,colors.lightGray) term.clear()
end):injectEvent("char", false, "w"):disable() printUtf8(value["name"],colors.white,colors.lightGray)
--frame:addLabel():setText(value["name"]):setPosition(1, 1) end):injectEvent("char", false, "w"):disable()
frame:addLabel():setText("name:"..value["name"].." id:"..value["id"].." artists:"..value["artists_name"]):setPosition(1, 4) --frame:addLabel():setText(value["name"]):setPosition(1, 1)
--frame:addLabel():setText("artists: "..value["artists_name"]):setPosition(1, 3) frame:addLabel():setText("name:"..value["name"].." id:"..value["id"].." artists:"..value["artists_name"]):setPosition(1, 4)
a=a+5 --frame:addLabel():setText("artists: "..value["artists_name"]):setPosition(1, 3)
end a=a+5
end
break;
else break;
frame = GUI_in[3]:addFrame():setPosition(2, 2):setSize("parent.w-2", 3):setBackground(colors.lightBlue) else
frame:addLabel():setText("[songCount] == 0"):setPosition(1, 1) frame = GUI_in[3]:addFrame():setPosition(2, 2):setSize("parent.w-2", 3):setBackground(colors.lightBlue)
break; frame:addLabel():setText("[songCount] == 0"):setPosition(1, 1)
end break;
end end
end
end
end end
end
play_Gui[4]:onError(function(self, event, err)
play_Gui[4]:onError(function(self, event, err)
end)
end)
play_Gui[4]:onDone(function()
play_Gui[4]:onDone(function()
end)
end)
-----------------------------------------------------------------渲染界面阶段-------------------------------------------------------------------------------------------------
GUI = { -----------------------------------------------------------------渲染界面阶段-------------------------------------------------------------------------------------------------
{ GUI = {
sub["UI"][1]:addInput():setPosition(2,1):setSize("parent.w-3", 1):setForeground(colors.gray):setBackground(colors.lightGray), {
sub["UI"][1]:addButton():setPosition("parent.w-1",1):setSize(1, 1):setText("Q"):onClick(function() Search(GUI[1][1]:getValue(),GUI[1],"search") end):setForeground(colors.white):setBackground(colors.lightGray), sub["UI"][1]:addInput():setPosition(2,1):setSize("parent.w-3", 1):setForeground(colors.gray):setBackground(colors.lightGray),
sub["UI"][1]:addFrame():setPosition(1, 3):setSize("parent.w", "parent.h -3"):setBackground(colors.white) sub["UI"][1]:addButton():setPosition("parent.w-1",1):setSize(1, 1):setText("Q"):onClick(function() Search(GUI[1][1]:getValue(),GUI[1],"search") end):setForeground(colors.white):setBackground(colors.lightGray),
}, sub["UI"][1]:addFrame():setPosition(1, 3):setSize("parent.w", "parent.h -3"):setBackground(colors.white)
{ },
sub["UI"][4]:addInput():setPosition(2,1):setSize("parent.w-3", 1):setForeground(colors.gray):setBackground(colors.lightGray), {
sub["UI"][4]:addButton():setPosition("parent.w-1",1):setSize(1, 1):setText("Q"):onClick(function() Search(GUI[1][1]:getValue(),GUI[2],"playlist") end):setForeground(colors.white):setBackground(colors.lightGray), sub["UI"][4]:addInput():setPosition(2,1):setSize("parent.w-3", 1):setForeground(colors.gray):setBackground(colors.lightGray),
sub["UI"][4]:addFrame():setPosition(1, 3):setSize("parent.w", "parent.h -3"):setBackground(colors.white) sub["UI"][4]:addButton():setPosition("parent.w-1",1):setSize(1, 1):setText("Q"):onClick(function() Search(GUI[1][1]:getValue(),GUI[2],"playlist") end):setForeground(colors.white):setBackground(colors.lightGray),
}, sub["UI"][4]:addFrame():setPosition(1, 3):setSize("parent.w", "parent.h -3"):setBackground(colors.white)
} },
}
function thread2()
while true do function thread2()
--basalt.debug(_G.music168_playopen = false os.queueEvent("music168_play_stop")) while true do
local screenWidth, _ = term.getSize() --basalt.debug(_G.music168_playopen = false os.queueEvent("music168_play_stop"))
local screenWidth, _ = term.getSize()
-- 处理用户拖动进度条设置播放位置
-- 处理用户拖动进度条设置播放位置
w,h = term.getSize()
if w >= 100 and h >= 30 then px = "--12px" else px = "--8px" end w,h = term.getSize()
if w >= 100 and h >= 30 then px = "--12px" else px = "--8px" end
if play_Gui[18]:getIndex() ~=1 then
local sliderValue = play_Gui[18]:getValue() or 0 if play_Gui[18]:getIndex() ~=1 then
_G.setPlay = _G.getPlaymax * (sliderValue / 100) local sliderValue = play_Gui[18]:getValue() or 0
play_Gui[18]:setIndex(1) _G.setPlay = _G.getPlaymax * (sliderValue / 100)
end play_Gui[18]:setIndex(1)
end
sleep(0.1)
sleep(0.1)
-- 更新播放进度条
if _G.getPlay ~= nil and _G.getPlaymax ~= nil and _G.getPlaymax > 0 then -- 更新播放进度条
play_Gui[10]:setProgress((_G.getPlay / _G.getPlaymax) * 100) if _G.getPlay ~= nil and _G.getPlaymax ~= nil and _G.getPlaymax > 0 then
play_Gui[10]:setProgress((_G.getPlay / _G.getPlaymax) * 100)
-- 更新当前播放时间显示
local current = _G.getPlay or 0 -- 更新当前播放时间显示
local total = _G.getPlaymax or 0 local current = _G.getPlay or 0
local currentTimeStr = string.format("%02d:%02d", math.floor(current / 60), current % 60) local total = _G.getPlaymax or 0
local totalTimeStr = string.format("%02d:%02d", math.floor(total / 60), total % 60) local currentTimeStr = string.format("%02d:%02d", math.floor(current / 60), current % 60)
local totalTimeStr = string.format("%02d:%02d", math.floor(total / 60), total % 60)
play_Gui[11]:setText(currentTimeStr) -- 当前播放时间
play_Gui[12]:setText(totalTimeStr) -- 时间 play_Gui[11]:setText(currentTimeStr) -- 当前播放时间
end play_Gui[12]:setText(totalTimeStr) -- 总时间
end
if play_data_table["play"]== true then
_G.Playstop = false if play_data_table["play"]== true then
play_Gui[15]:setText("II") _G.Playstop = false
play_column_Gui[2]:setText("II") play_Gui[15]:setText("II")
sub["BF"][2]:show() play_column_Gui[2]:setText("II")
else sub["BF"][2]:show()
play_Gui[15]:setText("I>") else
play_column_Gui[2]:setText("I>") play_Gui[15]:setText("I>")
--play_Gui[11]:setText("00:00") play_column_Gui[2]:setText("I>")
_G.Playstop = true --play_Gui[11]:setText("00:00")
end _G.Playstop = true
if play_data_table["play_table_index"] ~= 0 then end
if play_data_table["play_table_index"] ~= play_table_Gui[3]:getItemIndex() then if play_data_table["play_table_index"] ~= 0 then
index = play_table_Gui[3]:getItemIndex() if play_data_table["play_table_index"] ~= play_table_Gui[3]:getItemIndex() then
if play_data_table["play"] then index = play_table_Gui[3]:getItemIndex()
if play_data_table["play"] then
shell.run(mypath.."/speakerlib.lua stop")
if _G.Playopen then shell.run(mypath.."/speakerlib.lua stop")
if _G.Playopen then
end
play_data_table["play"]=false end
end play_data_table["play"]=false
_G.music168_playopen = false os.queueEvent("music168_play_stop") end
sleep(0.1) _G.music168_playopen = false os.queueEvent("music168_play_stop")
playmusic(play_data_table["play_table"][index]["name"],play_data_table["play_table"][index]["id"],play_data_table["play_table"],index) sleep(0.1)
playmusic(play_data_table["play_table"][index]["name"],play_data_table["play_table"][index]["id"],play_data_table["play_table"],index)
end
end end
end end
end end
end
function paste()
while true do function paste()
local event, text = os.pullEvent("paste") while true do
GUI[1][1]:setValue(text) local event, text = os.pullEvent("paste")
GUI[2][1]:setValue(text) GUI[1][1]:setValue(text)
end GUI[2][1]:setValue(text)
end end
end
function speakerp()
function speaker_thread() function speakerp()
local startTime = os.clock() function speaker_thread()
local startTime = os.clock()
if _G.music168_music_id then
--basalt.debug(music168_music_id) if _G.music168_music_id then
--basalt.debug(music168_music_id)
_G.Playopen = true
play_Gui[4]:stop() _G.Playopen = true
play_Gui[4]:stop()
play_Gui[4]:execute(function ()
shell.run("MusicLyrics.lua http://music168.liulikeji.cn:15843/api/song/lyric?id=".._G.music168_music_id.." "..px) play_Gui[4]:execute(function ()
end) shell.run("MusicLyrics.lua http://music168.liulikeji.cn:15843/api/song/lyric?id=".._G.music168_music_id.." "..px)
play_Gui[4]:injectEvent("char","w") end)
sleep(0.1) play_Gui[4]:injectEvent("char","w")
sleep(0.1)
--dfpwmURL = http.post("http://gmapi.liulikeji.cn:15842/dfpwm",textutils.serialiseJSON({ ["url"] = GetmusicUrl(_G.music168_music_id) } ))
shell.run(mypath.."/speakerlib play "..GetmusicUrl(_G.music168_music_id)) --dfpwmURL = http.post("http://gmapi.liulikeji.cn:15842/dfpwm",textutils.serialiseJSON({ ["url"] = GetmusicUrl(_G.music168_music_id) } ))
-- 检查是否播放完成自动跳转下一首 shell.run(mypath.."/speakerlib play "..GetmusicUrl(_G.music168_music_id))
if _G.music168_playopen then -- 检查是否播放完成自动跳转下一首
play_set_0() if _G.music168_playopen then
play_Gui[4]:stop() play_set_0()
play_Gui[4]:stop()
end
end end
end end
end
function while_thread()
os.pullEvent("music168_play_stop") function while_thread()
_G.getPlay = 0 os.pullEvent("music168_play_stop")
_G.getPlaymax = 0 _G.getPlay = 0
play_Gui[4]:stop() _G.getPlaymax = 0
end play_Gui[4]:stop()
end
while true do
if _G.music168_playopen then while true do
parallel.waitForAny(speaker_thread, while_thread) if _G.music168_playopen then
sleep(0.1) parallel.waitForAny(speaker_thread, while_thread)
end sleep(0.1)
sleep(0.01) end
end sleep(0.01)
end end
end
function gc()
while true do function gc()
play_Gui[4]:injectEvent(os.pullEvent()) while true do
end play_Gui[4]:injectEvent(os.pullEvent())
end
end
_G.music168_playopen = false os.queueEvent("music168_play_stop") end
-----------------------------------------------------------------启动循环渲染器----------------------------------------------------------------------------------------------- _G.music168_playopen = false os.queueEvent("music168_play_stop")
parallel.waitForAll(basalt.autoUpdate, thread2, paste, speakerp,gc) -----------------------------------------------------------------启动循环渲染器-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------以下结束----------------------------------------------------------------------------------------------------- parallel.waitForAll(basalt.autoUpdate, thread2, paste, speakerp,gc)
-----------------------------------------------------------------以下结束-----------------------------------------------------------------------------------------------------