酷狗音乐api - 回复一下疑问

疑问1 - 为什么我歌词解出来是乱码?

如果你请求的歌词是KRC格式的那一定是乱码,lrc格式请用Base64解码,而krc是要官方的解密方式才可行,如果想使用KRC的话可以参考我的已下JS代码

/**
 * krc解码
 * @param {string | Uint8Array | Buffer} val
 * @returns {string}
 */
const decodeLyrics = (val) => {
  let bytes = null;
  if (val instanceof Uint8Array) bytes = val;
  if (Buffer.isBuffer(val)) bytes = new Uint8Array(val);
  if (typeof val === 'string') bytes = new Uint8Array(Buffer.from(val, 'base64'));
  if (bytes === null) return '';
  const enKey = [64, 71, 97, 119, 94, 50, 116, 71, 81, 54, 49, 45, 206, 210, 110, 105];
  const krcBytes = bytes.slice(4);
  const len = krcBytes.byteLength;
  for (let index = 0; index < len; index += 1) {
    krcBytes[index] = krcBytes[index] ^ enKey[index % enKey.length];
  }
  try {
    const inflate = pako.inflate(krcBytes);
    return Buffer.from(inflate).toString('utf8');
  } catch {
    return '';
  }
};

疑问2 - 如何解析音乐

这里需要通过搜索拿到歌曲的哈希值,然后请求接口,这里我给大家放图演示

http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=%E9%9D%92%E8%8A%B1%E7%93%B7

 

通过搜索接口可以获取歌曲的高品质hash和普通哈希

然后通过接口解析 ,这里我随便找了一个,因为要付费

https://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash=badb427aee8ed2cdd9be8bacce44c9ea

 

我圈中的就是文件了 ,注意使用浏览器请求会导致结果无法访问

程序内不会!

好了就这样白白 

猜你喜欢

转载自blog.csdn.net/2301_78245299/article/details/141453210