欢迎来到代码驿站!

当前位置:首页 >

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

时间:2021-04-15 11:15:32|栏目:|点击:

参考此文: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

上一篇:局域网的基本组成

栏    目:

下一篇:易语言打开文件件网页的方法

本文标题:Lua脚本获取喜马拉雅MP3音频地址

本文地址:http://www.codeinn.net/misctech/101380.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有