Skip to content

[Bug] Subsonic stream.view 使用自定义音源时缺少歌曲元数据导致解析失败 #260

Description

@andy0532

问题描述

通过 Subsonic 协议的 /rest/stream.view 播放歌曲时,部分音源(如 kg/酷狗)的歌曲会解析到不可用的 CDN 链接(如 music.haitangw.cc 返回 401),而同一首歌在 LX Music Web 播放器内可以正常播放。

根因

src/server/subsonic.tshandleStream 方法(第 1653 行)构造的 musicInfo 只包含了最小化字段:

const musicInfo: any = { source, songmid, id, meta: { songId: songmid } }
const result = await callUserApiGetMusicUrl(source as any, musicInfo as any, quality, username)

而自定义音源(如全豆要[聚合音源])需要完整歌曲元数据(如 hashalbumIdqualitys)才能正确解析到原始 CDN。歌单中存储的完整音乐对象包含这些字段:

{
  "id": "kg_452855453",
  "source": "kg",
  "meta": {
    "songId": 452855453,
    "qualitys": [
      { "type": "128k",  "hash": "A48A1AFF..." },
      { "type": "flac",  "hash": "30EF0584..." }
    ]
  },
  "hash": "A48A1AFF..."
}

类中已有 findMusicById 方法(第 461 行)可以获取完整音乐对象,且已被 getCoverArtgetLyricsBySongId 等其他方法使用,唯独 handleStream 没有调用它。

修复方案

将第 1653 行改为优先从歌单获取完整音乐对象:

// 优先使用完整音乐对象(含 hash、albumId 等),确保自定义源正确解析
const found = await this.findMusicById(username, id)
let musicInfo: any
if (found) {
    musicInfo = { ...found.music, id, songmid }
} else {
    musicInfo = { source, songmid, id, meta: { songId: songmid } }
}

影响范围

  • 所有依赖自定义音源(如全豆要聚合源)且歌单中存在该歌曲的 Subsonic 客户端
  • wy(网易云)和 tx(QQ音乐)源不受影响,它们的 SDK 本身能处理最小参数
  • kg(酷狗)、kw(酷我)等需要 hash 字段的源会失败

环境

  • lxserver Docker 版本
  • Subsonic 客户端:音流 App、Symfonium 等

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions