API Reference v2.0

接口文档

Lokua Music 提供统一的 RESTful API,聚合多个音乐平台数据。所有接口支持 CORS 跨域,可直接在前端项目中调用。

概览

基础地址

http://localhost:20081

数据格式

JSON (Content-Type: application/json)

跨域支持

全接口开启 CORS,无需代理

统一接口

POST /api/music

请求体 (JSON):

{
  "input":  "周杰伦",       // 搜索关键词 / 歌曲ID / 歌曲URL
  "filter": "name",         // name | id | url
  "type":   "netease",      // 平台标识(filter=url 时可省略)
  "page":   1               // 页码,默认 1(可选)
}
参数 类型 必填 说明
input string 搜索关键词(filter=name)、歌曲ID(filter=id)、或歌曲链接(filter=url)
filter string name 按名称搜索   id 按ID查询   url 按链接自动识别
type string 条件 平台标识(见下方列表)。filter=url 时可省略,系统自动识别
page number 分页页码,默认 1。仅 filter=name 时生效

支持平台

netease 网易云音乐
qq QQ音乐
kugou 酷狗音乐
kuwo 酷我音乐
migu 咪咕音乐
5singyc 5sing 原创
5singfc 5sing 翻唱
lizhi 荔枝FM
qingting 蜻蜓FM
ximalaya 喜马拉雅
kg 全民K歌

GET 快捷接口

主流平台提供独立的 GET 端点,参数通过 Query String 传递,无需指定 type。

GET /api/netease?input=十年&filter=name&page=1 网易云音乐
GET /api/qq?input=告白气球&filter=name QQ音乐
GET /api/kugou?input=光辉岁月&filter=name 酷狗音乐
GET /api/kuwo?input=晴天&filter=name 酷我音乐
参数 类型 默认值 说明
input string - 搜索关键词或歌曲 ID(必填)
filter string name name 或 id
page number 1 分页页码

响应格式

200 OK
{
  "code": 200,
  "error": "",
  "data": [
    {
      "type":   "netease",      // 来源平台
      "songid": "347230",       // 歌曲 ID
      "title":  "十年",          // 歌曲名称
      "author": "陈奕迅",        // 歌手
      "url":    "http://...mp3", // 播放地址
      "pic":    "http://...jpg", // 封面图片
      "lrc":    "[00:00]...",   // LRC 歌词
      "link":   "http://..."    // 来源页面链接
    }
  ]
}
字段 类型 说明
typestring来源平台标识,如 netease、qq、kugou 等
songidstring/number歌曲在原平台的唯一 ID
titlestring歌曲名称
authorstring歌手名称(多歌手用逗号分隔)
urlstring音频文件播放地址(MP3/M4A)
picstring封面图片 URL
lrcstringLRC 格式歌词文本(部分平台可能为空)
linkstring歌曲在原平台的页面链接

错误码

code 含义 常见原因
200 成功 正常返回数据
403 参数错误 / 付费内容 缺少必填参数、不支持的平台、版权限制
404 未找到 无匹配结果或 ID 不存在
500 服务器错误 上游接口异常或内部错误
503 服务不可用 平台已关停(如千千音乐、一听)
错误响应示例
{
  "code": 404,
  "data": "",
  "error": "(╥﹏╥) 没有找到相关信息"
}

调用示例

cURL

# 按名称搜索 - 网易云
curl -X POST http://localhost:20081/api/music \
  -H "Content-Type: application/json" \
  -d '{"input":"周杰伦","filter":"name","type":"netease"}'

# GET 快捷方式 - 酷狗
curl "http://localhost:20081/api/kugou?input=光辉岁月&filter=name"

# 按链接自动识别平台
curl -X POST http://localhost:20081/api/music \
  -H "Content-Type: application/json" \
  -d '{"input":"https://music.163.com/song?id=347230","filter":"url"}'

JavaScript (fetch)

const res = await fetch('http://localhost:20081/api/music', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    input:  '周杰伦',
    filter: 'name',
    type:   'kugou'
  })
});
const { data, code, error } = await res.json();

// GET 方式
const res2 = await fetch('http://localhost:20081/api/netease?input=十年&filter=name');
const result = await res2.json();

Python (requests)

import requests

resp = requests.post('http://localhost:20081/api/music', json={
    'input':  '陈奕迅',
    'filter': 'name',
    'type':   'kuwo'
})
songs = resp.json()['data']

for song in songs:
    print(song['title'], '-', song['author'], '-', song['url'])

健康检查

GET /health
{
  "status":  "ok",
  "version": "2.0.0-node"
}