网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 Lua脚本获取喜马拉雅MP3音频地址
内容
    下面介绍了Lua脚本获取喜马拉雅MP3音频地址,本文直接给出代码实例,需要的朋友可以参考下
    在Linux下可以直接运行
    #!/usr/bin/lua5.1
    --需要luacurl
    --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,参考
    return #buffer
    end)
    local ok = c:perform()
    return ok, table.concat(result) --此table非上一个table,作用域不同
    end
    function downMp3(id)
    local url=""
    local mp3 = ""
    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
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/21 18:10:40