Lua脚本获取喜马拉雅MP3音频地址
- 作者: 花式柔道总冠军丶
- 来源: 51数据库
- 2021-07-28
参考此文:
在linux下可以直接运行
#!/usr/bin/lua5.1
--需要luacurl http://luacurl.luaforge.net/
--luajson http://www.51sjk.com/Upload/Articles/1/0/251/251683_20210626001549754.jpg
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.51sjk.com/Upload/Articles/1/0/251/251683_20210626001610815.jpg"..id..".json"
local mp3 = "http://www.51sjk.com/Upload/Articles/1/0/251/251683_2021062600161081501.jpg"
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
推荐阅读
