zoukankan      html  css  js  c++  java
  • lua获取喜马拉雅音频地址

    参考此文http://blog.csdn.net/zjg555543/article/details/39177971

    在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
  • 相关阅读:
    用工具爬虎牙星秀VS用代码
    mysql简单的操作
    MySQL5.1的安装过程
    MySQL的安装
    SQL server 2008 的安装
    数据库基础知识
    HTTP协议
    TCP协议
    web系统基础
    软件测试缺陷的定义、产生原因、缺陷报告格式、缺陷报告
  • 原文地址:https://www.cnblogs.com/xdao/p/lua_ximalaya.html
Copyright © 2011-2022 走看看