From b93a555ff5e1420d76c3bee484541d7b5de5e8c1 Mon Sep 17 00:00:00 2001 From: color_garden Date: Sun, 3 May 2026 02:18:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加可选服务器 --- play.lua | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/play.lua b/play.lua index 44a89bc..73c3a20 100644 --- a/play.lua +++ b/play.lua @@ -1,4 +1,3 @@ - local mypath = "/"..fs.getDir(shell.getRunningProgram()) if not fs.exists(mypath.."/speakerlib.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/computer_craft_video_play/raw/branch/main/speakerlib.lua "..mypath.."/speakerlib.lua") end if not fs.exists(mypath.."/cc_big_http.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/cc_big_http/raw/branch/main/cc_big_http.lua "..mypath.."/cc_big_http.lua") end @@ -10,6 +9,7 @@ local age = {...} local videoUrl = age[1] local debug local server_url = "https://newgmapi.liulikeji.cn" +local custom_server_flag = false -- 标志位:判断是否在命令行指定了服务器 local pix_fmt = "pal8" local gpu_Size_Auto = false --自动分辨率设置 local gpu_Size = 64 --默认屏幕分辨率 @@ -22,7 +22,7 @@ Options: -h/-high Use high color mode (rgba24) instead of palette (pal8) -size Set GPU size to NxN (1-64) -gpu Specify GPU peripheral ID to use - -server Set API server URL (default: http://127.0.0.1:5000) + -server Set API server URL (default: https://newgmapi.liulikeji.cn) ]] for i,v in ipairs(age) do @@ -35,6 +35,7 @@ for i,v in ipairs(age) do elseif v == "-server" and age[i+1] then server_url = age[i+1] + custom_server_flag = true -- 记录已通过参数设置 elseif v == "-help" then print(play_help) error("Help requested") @@ -138,6 +139,33 @@ if not videoUrl then return end + +-- 交互式服务器选择菜单 +if not custom_server_flag then + print("\n=== API Server Selection ===") + print("[1] http://101.133.167.126:9000") + print("[2] https://newgmapi.liulikeji.cn (Default)") + print("Or manually input a custom server IP/URL.") + write("Select [1/2/URL] (Press Enter for default): ") + + local choice = read() + if choice == "1" then + server_url = "http://101.133.167.126:9000" + elseif choice == "2" or choice == "" then + server_url = "https://newgmapi.liulikeji.cn" + else + -- 自动补全 http:// 前缀 + if not string.match(choice, "^http[s]?://") then + server_url = "http://" .. choice + else + server_url = choice + end + end + print("\nUsing server: " .. server_url) + sleep(0.5) +end + + _G.audio_ready = false local task_id local status_url @@ -193,11 +221,6 @@ local all_logs = {} -- 存储所有日志(完整版本,包含时间戳) local speakerrun = true local last_log_count = 0 -- 记录上次已打印的日志数量 --- 用于记录已打印的日志数量,避免重复打印 -local all_logs = {} -- 存储所有日志(完整版本,包含时间戳) -local speakerrun = true -local last_log_count = 0 -- 记录上次已打印的日志数量 - -- 去除日志前的时间戳用于显示 local function removeTimestamp(logText) -- 匹配 [YYYY-MM-DD HH:MM:SS] 格式并去除 @@ -849,4 +872,4 @@ else perf_log_file.write(textutils.serialiseJSON(perf_log)) print("perf_log has been saved to "..mypath.."/perf_log.json") end -end +end \ No newline at end of file -- 2.49.1