我是靠谱客的博主 明亮唇膏,最近开发中收集的这篇文章主要介绍Lua脚本获取喜马拉雅MP3音频地址,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

参考此文:http://www.uoften.com/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音频地址的全部内容,希望文章能够帮你解决Lua脚本获取喜马拉雅MP3音频地址所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(152)

评论列表共有 0 条评论

立即
投稿
返回
顶部