Coder Social home page Coder Social logo

musicapi's Introduction

music-api

注意事项

  • 项目仍在开发阶段,即使是小版本之间也会出现不兼容,如用在生产环境,请写死版本号使用

安装

yarn add @suen/music-api

引入

  • node
    import musicApi from '@suen/music-api'
  • android、ios
    • 引入js
    • 通过Fly注册并调用,详见Fly文档
    • 已在window下注册,webview内可直接使用window.musicApi
  • react native
    • 安装依赖
      // 请使用yarn 经测试 使用npm可能会在装依赖时卡死
      yarn add react-native-crypto react-native-randombytes
      react-native link react-native-randombytes
      yarn add -D rn-nodeify@latest
      ./node_modules/.bin/rn-nodeify --hack --install --yarn // 执行到这一步时 请确定已安装 @suen/music-api
    • 通过以下代码引入
      import './shim.js' // shim.js会生成在根目录下
      import musicApi from '@suen/music-api/dist/app.react-native'
  • electron-render
    // 主进程 引入nodeAdapter,避免被打包进渲染进程 如无这个需求 可直接在渲染进程中引入
    import nodeAdapter from 'flyio/src/adapter/node'
    global.nodeAdapter = nodeAdapter
    
    // 渲染进程
    import musicApiContructor from '@suen/music-api/dist/app.electron'
    const musicApi = musicApiContructor(require('electron').remote.getGlobal('nodeAdapter'))
  • api server
    // express
    import app from '@suen/music-api/src/express-app'
    app.listen(8080)
    
    // lean cloud
    import app from '@suen/music-api/src/lean-cloud-server'
    app.listen(process.env.LEANCLOUD_APP_PORT)

使用

  • 函数调用
    musicApi.searchSong('周杰伦')
      .then(data => {
          console.log(data)
      })
    musicApi.qq.searchSong({
      keyword: '周杰伦'
    })
      .then(data => {
          console.log(data)
      })
  • api server调用

Api

  • Common

    • 歌曲搜索

      function searchSong( keyword:关键字, offset:偏移页数 ) {
          return {
              status:Boolean, // 请求是否成功
              data:{
                  netease: Object,
                  qq: Object
              }
          }
      }
    • 歌曲url

      function getSongUrl( vendor:歌曲来源, id:歌曲id ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  url:'歌曲地址'
              }
          }
      }
    • 歌曲歌词

      function getLyric( vendor:歌曲来源, id:歌曲id ) {
          return {
              status: Boolean, // 请求是否成功
              data: Array, // 歌词数组
          }
      }
    • 歌曲评论

      由于网易云、QQ音乐的评论逻辑不一样hotCommentscomments没有进行强封装

      function getComment( vendor:歌曲来源, id:歌曲id, page:页数, limit:页大小 ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  hotComments: Array, // 热评
                  comments: Array, // 所有评论
                  total: Number, //评论总数
              }
          }
      }
    • 歌曲详情

      function getSongDetail( vendor:歌曲来源, id:歌曲id ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  album: {
                      id: Number | String,
                      name: String,
                      cover: String
                  },
                  artists: Array,
                  name: String,
                  id: Number,
                  cp: Boolean
              }
          }
      }
    • 批量获取歌曲详情

      注意事项:

      • QQ音乐一次只能获取50条数据,不会去重
      • 网易云音乐未发现单次数量限制,会去重
      • 去重的意思是 重复的歌曲id,只会返回一次歌曲信息
      function getBatchSongDetail( vendor:歌曲来源, ids:歌曲id数组 ) {
          return {
              status: Boolean, // 请求是否成功
              data: [{
                  album: {
                      id: Number | String,
                      name: String,
                      cover: String
                  },
                  artists: Array,
                  name: String,
                  id: Number,
                  cp: Boolean
              }]
          }
      }
    • 歌手单曲

      注意事项:

      • 网易云没有分页,传页参数无效
      • 默认第一页,50条数据
      function getArtistSongs( vendor:歌曲来源, id:歌手id, offset:偏移页数, limit:页大小 ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  detail: {
                      id: Number | String,
                      name: String,
                      avatar: String,
                      desc: String
                  },
                  songs: [{
                     album: {
                         id: Number | String,
                         name: String,
                         cover: String
                     },
                     artists: Array,
                     name: String,
                     id: Number,
                     cp: Boolean
                 }]
              }
          }
      }
    • 歌单信息

      注意事项:

      • QQ音乐没有分页,传页参数无效;网易云可传limit
      • 默认第一页,65535条数据
      function getPlaylistDetail( vendor:歌曲来源, id:歌手id, offset:偏移页数, limit:页大小 ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  detail: {
                      id: Number | String,
                      name: String,
                      cover: String,
                      desc: String
                  },
                  songs: [{
                     album: {
                         id: Number | String,
                         name: String,
                         cover: String
                     },
                     artists: Array,
                     name: String,
                     id: Number,
                     cp: Boolean
                 }]
              }
          }
      }
    • 专辑信息

      function getAlbumDetail( vendor:歌曲来源, id:专辑id ) {
          return {
              status: Boolean, // 请求是否成功
              data: {
                  name: String,
                  cover: String,
                  artist: {
                      id: Number,
                      name: String,
                  },
                  desc: String,
                  publishTime: Number,
                  songs: [{
                     album: {
                         id: Number | String,
                         name: String,
                         cover: String
                     },
                     artists: Array,
                     name: String,
                     id: Number,
                     cp: Boolean
                 }]
              }
          }
      }
  • Difference

    • 网易云
      • 获取排行榜

        注意事项:排行榜id可传0-23

        function getTopList( id:排行榜id ) {
            return {
                status: Boolean, // 请求是否成功
                data: {
                    name: '名称',
                    description: '简介',
                    cover: '封面',
                    playCount: '播放次数',
                    list: [{
                       album: {
                           id: Number | String,
                           name: String,
                           cover: String
                       },
                       artists: Array,
                       name: String,
                       id: Number,
                       cp: Boolean
                   }]
                }
            }
        }
    • QQ音乐
      • 获取歌手列表

        注意事项:一页限制80条

        function getArtists( offset : '偏移页数', { area = -100, sex = -100, genre = -100, index = -100 } ) {
            return {
                status: Boolean, // 请求是否成功
                data: {
                    area: '地区分类',
                    genre: '音乐分类',
                    index: '热门 + 首字母',
                    sex: '性别',
                    singerlist: [{
                       country: '地区分类',
                       singer_id: '歌手id',
                       singer_mid: '歌手mid',
                       singer_name: '歌手名',
                       singer_pic: '照片'
                    }],
                    tags: [{
                       area: [],
                       genre: [],
                       index: [],
                       sex: [],
                    }],
                    total: '总数量'
                }
            }
        }

musicapi's People

Contributors

hugetiny avatar johnsmith0602 avatar sabertazimi avatar sunzongzheng avatar wednesday avatar yueliu100 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

musicapi's Issues

vue中使用musicApi的函数报跨域错误怎么搞?

vue中使用musicApi报跨域错误:
Access to fetch at 'https://music.163.com/weapi/cloudsearch/get/web' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
有人遇到吗?网上找好久也找不到解决办法

请问下Leancloud参数params是通过怎样的格式传递的呢?

leancloud部署后参考您的源码,猜了一些参数
我的params送入的是这样的格式[{"id":4}]
image

但是传递到qq/index.js中的getTopList(id)方法,通过
console.log(id);
打印出的id此时的值为:
{ id: 4 }
该值会导致qq/index.js中的getTopList方法出错,只能修改您的代码,把该方法中的id修改为id.id才能正常返回
nodejs小白一个
请问下,我传递的参数params的样式是不是有问题

musicApi.searchSong 能不能也支持 musicApi.qq.searchSong 的 searchSongOptions 参数格式?

我在使用 musicApi.searchSong 的时候也有指定 limit 的需求,结果发现现在的参数格式 (keyword, offset) 似乎是不支持的,searchSong(options: searchSongOptions) 这种格式是我想要的。
另外,musicApi.searchSong 和 musicApi.qq.searchSong 的参数格式完全不同,我在使用之初也是挺困惑的。
能不能在保留现有参数的前提下,给 musicApi.searchSong 也支持以 searchSongOptions 对象为参数呢?

How can use this api in android

Hi.
I am new in using APIs, I want to use this API to search and stream musics in an android application using java or kotlin. Can i use this API using retrofit or some thing similar? If it's possible, which steps i need to do this?

thanks.

[需求]查询歌曲结果携带指向各平台的歌曲页面的 url

这个是我在使用中碰到的具体需求,我希望用户搜索歌曲后有机会跳到歌曲在对应平台的外链,我期待的数据结构大概是这样的:

{
  songs: [{
    name: '芳华绝代',
    url: 'https://y.qq.com/n/yqq/song/001IFoUn3oeFys.html',
    album: {
      cover: '...',
      url: 'https://y.qq.com/n/yqq/album/000xQ2Zy44PJ0g.html'
    }
  }]
}

我刚才看了下 QQ 音乐目前接口的返回数据,其中带的 mid 是能用来拼接 url 的。不知道 api 可以考虑添加上这两处 url 参数吗?我可以来提 PR~

移除虾米的源

因为虾米2月5日就要下线了,代码库能不能把 xiami 的源给去掉,这样 getData 的时候可以少等待一个请求?
如果可以的话,我可以提一个把 xiami 相关代码都删掉的 PR。

package.json里面的scripts有点乱

  "scripts": {
    "start": "node dist/lean-server.js",
    "dev": "nodemon --inspect-brk controllers/app.js --exec babel-node",
    "test": "mocha -t 30000 --require @babel/register 'test/*.test.js' --exit",
    "test:qq": "mocha -t 30000 --require @babel/register 'test/qq.test.js' --exit",
    "dev-server": "nodemon --inspect src/server.js --exec babel-node",
    "build": "npm run build:node && npm run build:web",
    "build:node": "babel src -d dist",
    "build:web": "webpack"
  },

src下面没有server.js 要自己创建
还有一些多余的选项

虾米音乐获取歌手的信息有瑕疵

我使用关键词'一生所爱'调用 searchSong,会发现返回的结果中, xiami 对应的一首歌,api 返回的 artists 是 ['原声带'],而从网页上能看到歌曲页面显示的歌手信息是正确的 ['卢冠廷'、'莫文蔚']。我进一步跳到虾米这张专辑的页面,发现它的歌手信息就是'原声带'。

猜测代码的逻辑是取的专辑页面的歌手名。想问在不增加额外请求的前提下,有可能直接取到更正确的歌曲页面的歌手信息吗?

升级到新版本会有这个问题

RangeError: Maximum call stack size exceeded (uncaughtException throw 1 times on pid:xx) at toString (<anonymous>) at Object.type (/node_modules/flyio/dist/npm/fly.js:90:42) at Object.clone (/node_modules/flyio/dist/npm/fly.js:144:25) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33) at Object.clone (/node_modules/flyio/dist/npm/fly.js:159:33)
之前的1.10版本没有。
用egg.js,nodejs v10.12.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.