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

(编辑:jimmy 日期: 2024/10/5 浏览:2)

参考此文:https://www.jb51.net/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

一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。