信息发布→ 登录 注册 退出

Lua脚本获取喜马拉雅MP3音频地址

发布时间:2026-01-11

点击量:

参考此文:https://www./softjc/314839.html

在Linux下可以直接运行

#!/usr/bin/lua5.1
--需要luacurl http://luacurl.luaforge.net/
--luajson https://github.com/mbalmer/luajson
require("luacurl")
require('json')


function get_html(url, c)
  local result = { }
  if c == nil then
    c = curl.new()
  end
  c:setopt(curl.OPT_URL, url)
  c:setopt(curl.OPT_WRITEDATA, result)
  c:setopt(curl.OPT_WRITEFUNCTION, function(tab, buffer)   --call back函数,必须有
    table.insert(tab, buffer)           --tab参数即为result,参考http://luacurl.luaforge.net/

    return #buffer
  end)
  local ok = c:perform()
  return ok, table.concat(result)       --此table非上一个table,作用域不同
end


function downMp3(id)
  
  local url="http://www.ximalaya.com/tracks/"..id..".json"
  local mp3 = "http://fdfs.xmcdn.com/"
  local ok,html = get_html(url)
  if ok then
    local result = json.decode(html)
    print(mp3..result.play_path_64)
  else
    print("error")
  end
end
if arg[1] and tonumber(arg[1]) then
  downMp3(arg[1])
else
  print("请输入编号")
end

标签:# http  # result  # html  # softjc  # bin  # json  # require  # mbalmer  # url  # get_html  # function  # github  # Lua脚本  # luacurl  # luajson  # net  # luaforge  # 此文  # 即为  # 可以直接  # 请输入  # 音频地址  # MP3  # 喜马拉雅  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!