服务器之家

服务器之家 > 正文

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

时间:2020-04-21 11:18     来源/作者:脚本之家

在Linux下可以直接运行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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
标签:

相关文章

热门资讯

沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意 2019-07-07
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
超A是什么意思 你好a表达的是什么
超A是什么意思 你好a表达的是什么 2019-06-06
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
返回顶部