dsh-cloudmusic-player 0.7.20 → 0.7.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,8 +3,25 @@
3
3
  All notable changes to this project are documented here.
4
4
  格式按 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号按 [SemVer](https://semver.org/lang/zh-CN/)。
5
5
 
6
+ ## [0.7.22] - 2026-11-27
7
+
8
+ ### Fixed
9
+
10
+ - 修复「客户端暂停后再放 B 站视频、插件识别不到歌」。根因:client-first 模式原来会按「哪条通道正在播」动态选路,Chromium(Edge/Chrome)只向系统上报一个 SMTC 会话,B 站视频一放就顶掉音乐会话,web 通道的 SMTC 回退于是把视频当媒体/误判无歌。改为:client-first 下**客户端进程在线就锁定 native 通道**,完全不碰 web/浏览器 SMTC;只有客户端进程不在时才让网页版接管。客户端在线时行为与适配网页版之前完全一致。网页优先请显式切 web-first / web-only。
11
+ - 顺带修 detectClientRunning:宿主 env.SystemRoot 异常时 tasklist 绝对路径拼错导致 ENOENT,改为多候选路径逐个试 + 裸名兜底。health 增加「客户端进程 在线/离线」诊断字段。
12
+
13
+ ## [0.7.21] - 2026-11-27
14
+
15
+ ### Fixed
16
+
17
+ - 修复 0.7.20 引入的回归:网易云「暂停」时 SMTC 会话的 artist 常被清空,被「artist 空即非音乐」判据误当成视频挡掉,导致暂停后识别不到歌。改为:artist 空但歌名与 sticky 记忆一致时用记忆里的歌手补回、照常识别;只有无歌手且歌名不匹配(真正的视频/网页媒体)才挡下。SmtcBrowser 与 web-backend 两层同步。
18
+
6
19
  ## [0.7.20] - 2026-11-27
7
20
 
21
+ ### Fixed
22
+
23
+ - 客户端打开但未播放时,SMTC 里可能出现无歌手、无站点后缀的 B 站/网页视频会话(如「笨蛋教学,高维理解:压枪的第一性原理」),旧判据只靠站点标记漏判,把视频标题当成正在播放的歌显示。改为「artist 为空即非音乐」:smtc-browser 与 web-backend 两层统一按此判据挡下,走 sticky 兜底(有记住的歌显示歌,否则如实报无音乐会话),不再把视频当歌。
24
+
8
25
  ### 维护
9
26
 
10
27
  - 文档、包元数据与同步脚本中的仓库地址改为占位符,移除个人信息;本地 git 署名改为中性 contributors。无功能变更。
package/index.js CHANGED
@@ -639,7 +639,7 @@ export function apply(ctx, config) {
639
639
  const h = await player.deepHealth()
640
640
  return {
641
641
  text: [
642
- `当前通道 ${h.channel || player.active}${h.loggedIn !== undefined ? ` · 网页登录 ${h.loggedIn ? '已登录' : '未登录'}` : ''}`,
642
+ `当前通道 ${h.channel || player.active}${h.loggedIn !== undefined ? ` · 网页登录 ${h.loggedIn ? '已登录' : '未登录'}` : ''}${h.clientOnline !== undefined ? ` · 客户端进程 ${h.clientOnline ? '在线' : '离线'}` : ''}`,
643
643
  `平台 ${h.platform} · 后端 ${h.backend} · PowerShell ${h.ps || '?'} · WinRT ${h.winrt ? 'ok' : '不可用'} · 窗口 ${h.window ? 'ok' : '不可用'}`,
644
644
  `进程 ${(h.pids || []).join(', ') || '(无)'} · 目标会话 ${h.target || '(SMTC 未匹配,走原生车道)'}`,
645
645
  `媒体会话:${(h.media || []).map((m) => `${m.aumid}${m.title ? `(${m.title})` : ''}`).join(' / ') || '(无)'}`,
package/lib/channel.mjs CHANGED
@@ -29,27 +29,32 @@ export async function detectClientRunning(cfg = {}) {
29
29
  const names = new Set(['cloudmusic', 'neteasecloudmusic', 'netease cloud music'])
30
30
  const pn = String(cfg.processName || '').toLowerCase().replace(/\.exe$/, '')
31
31
  if (pn) names.add(pn)
32
- try {
33
- // 用绝对路径:DSH 宿主进程的 PATH 未必含 System32,裸 'tasklist' 会 ENOENT
34
- // 落进 catch。独立脚本能跑只因 shell 补了 PATH——这正是「诊断脚本对、运行时错」的根源。
35
- const tasklist = `${process.env.SystemRoot || 'C:\\Windows'}\\System32\\tasklist.exe`
36
- const { stdout } = await execFileAsync(tasklist, ['/FO', 'CSV', '/NH'], {
37
- timeout: 3000,
38
- windowsHide: true,
39
- maxBuffer: 4 * 1024 * 1024,
40
- })
41
- const lower = stdout.toLowerCase()
42
- for (const n of names) {
43
- if (lower.includes(`${n}.exe`)) return true
32
+ // 用绝对路径:DSH 宿主进程的 PATH 未必含 System32,裸 'tasklist' 会 ENOENT
33
+ // 落进 catch。宿主 env.SystemRoot 也可能是空/异常值,所以列出多个候选逐个试,
34
+ // 硬编码 C:\\Windows 兜底,确保运行时一定能拿到 tasklist。
35
+ const roots = [process.env.SystemRoot, 'C:\\Windows', 'C:\\WINDOWS'].filter(Boolean)
36
+ const candidates = []
37
+ for (const root of roots) {
38
+ const pr = String(root).replace(/\\+$/, '')
39
+ const cp = pr + '\\System32\\tasklist.exe'
40
+ if (!candidates.includes(cp)) candidates.push(cp)
41
+ }
42
+ candidates.push('tasklist.exe')
43
+ for (const tasklist of candidates) {
44
+ try {
45
+ const { stdout } = await execFileAsync(tasklist, ['/FO', 'CSV', '/NH'], {
46
+ timeout: 3000,
47
+ windowsHide: true,
48
+ maxBuffer: 4 * 1024 * 1024,
49
+ })
50
+ const lower = stdout.toLowerCase()
51
+ for (const n of names) {
52
+ if (lower.includes(n + '.exe')) return true
53
+ }
54
+ return false
55
+ } catch {
56
+ // 这个候选失败,试下一个。
44
57
  }
45
- return false
46
- } catch {
47
- // tasklist 在宿主运行时里可能因 cwd/PATH 差异失败(独立脚本却正常)。
48
- // 以前这里 return true(判客户端在线),会让 client-first 兜底误选 native,
49
- // 于是「网页版正在放歌」被显示成已暂停·无标题。现在 pick() 已有 channelPlaying
50
- // 前置判据——客户端真在播会优先选 native,所以探测失败时判「不在」更安全:
51
- // 网页在播能切过去,都没播则走 web 便于插件起播。
52
- return false
53
58
  }
54
59
  }
55
60
 
@@ -134,9 +139,12 @@ export class ChannelRouter {
134
139
  break
135
140
  case 'client-first':
136
141
  default:
137
- if (await this.channelPlaying('native')) chosen = 'native'
138
- else if (await this.channelPlaying('web')) chosen = 'web'
139
- else chosen = (await this.clientOnline()) ? 'native' : 'web'
142
+ // 客户端进程在线就锁 native,完全不碰 web 通道。
143
+ // Chromium 只上报一个 SMTC 会话:客户端暂停后再放 B 站视频,视频会话会
144
+ // 顶掉音乐会话,web 通道的 SMTC 回退就会把视频当媒体/误判无歌。
145
+ // 客户端在线时行为与 k65 之前完全一致(验收标准第 1 条);只有客户端
146
+ // 进程不在时才让 web 通道接管。要浏览器优先请显式切 web-first/web-only。
147
+ chosen = (await this.clientOnline()) ? 'native' : 'web'
140
148
  break
141
149
  }
142
150
  if (chosen !== this.active) {
@@ -203,6 +211,7 @@ export class ChannelRouter {
203
211
  return {
204
212
  ...h,
205
213
  channel: 'web',
214
+ clientOnline: await this.clientOnline(),
206
215
  channels: {
207
216
  native: { backend: this.native.backend.id, platform: this.native.backend.platform, degraded: this.native.degraded || '' },
208
217
  web: { backend: this.web.id, platform: 'web', reachable: h.ok !== false },
@@ -213,6 +222,7 @@ export class ChannelRouter {
213
222
  return {
214
223
  ...h,
215
224
  channel: 'native',
225
+ clientOnline: await this.clientOnline(),
216
226
  channels: {
217
227
  native: { backend: this.native.backend.id, platform: this.native.backend.platform, degraded: this.native.degraded || '' },
218
228
  web: { backend: this.web.id, platform: 'web', reachable: await this.webAvailable() },
@@ -179,10 +179,21 @@ export class SmtcBrowser {
179
179
  this._stateInflight = (async () => {
180
180
  try {
181
181
  let r = await this._run('state')
182
- // Node 层兜底挡视频标题:probe 的 score 判据可能漏判某些站点(如 Gimy 劇迷)。
183
- // 视频标题无歌手(artist 空),不是音乐——当成「无音乐会话」走 sticky 兜底。
184
- if (r && r.ok && r.title && isVideoTitle(r.title) && !String(r.artist || '').trim()) {
185
- r = { ok: false, error: 'video-session', detail: 'video title' }
182
+ // Node 层兜底挡视频/网页媒体:音乐会话一定有歌手,artist 空就不是音乐。
183
+ // 之前只靠站点标记(bilibili/youtube/gimy...)判视频,漏掉了「笨蛋教学…
184
+ // 压枪的第一性原理」这类无站点后缀、artist 也空的 B 站视频——它被当成歌显示。
185
+ // 判据改为:没有歌手(artist 空)即非音乐,走 sticky 兜底(有记住的歌就显示歌,
186
+ // 没有则如实报无音乐会话),绝不把视频/网页媒体当歌。
187
+ if (r && r.ok && r.title && !String(r.artist || '').trim()) {
188
+ // 例外:网易云「暂停」时 SMTC 会把 artist 清空,但 title 还是刚才那首歌。
189
+ // 若歌名与 sticky 记住的一致,用记忆里的歌手补回,照常识别,别当视频挡掉。
190
+ const last = this._stickyMusic()
191
+ const sameSong = last && String(last.title || '').trim().toLowerCase() === String(r.title).trim().toLowerCase()
192
+ if (sameSong) {
193
+ r = { ...r, artist: last.artist || '', album: last.album || last.albumTitle || '' }
194
+ } else {
195
+ r = { ok: false, error: 'video-session', detail: isVideoTitle(r.title) ? 'video title' : 'no artist' }
196
+ }
186
197
  }
187
198
  if (r && r.ok && r.title && String(r.artist || '').trim()) {
188
199
  // 只把「有歌手」的真实音乐记为最近一次——视频标题(无歌手)不会污染兜底。
@@ -865,8 +865,9 @@ export class WebBackend {
865
865
  const cdpReal = !!(s && s.hasAudio && s.status === 'Playing')
866
866
  if (!cdpReal && this._smtcEnabled()) {
867
867
  const sm = await this.smtc.readState().catch(() => null)
868
- if (sm && sm.ok && sm.title && !sm.artist && this._isVideoTitle(sm.title)) {
869
- // probe 已尽力排除视频标题;这里挡住任何穿透到 Node 层的视频会话(artist 空 + 站点标记)。
868
+ if (sm && sm.ok && sm.title && !String(sm.artist || '').trim()) {
869
+ // 音乐会话一定有歌手;artist 空就是视频/网页媒体,绝不当歌显示。
870
+ // smtc-browser 层已按此判据挡下,这里是双保险。
870
871
  } else if (sm && sm.ok && sm.title) {
871
872
  this.dataSource = 'smtc'
872
873
  this.smtcState = sm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cloudmusic-player",
3
- "version": "0.7.20",
3
+ "version": "0.7.22",
4
4
  "description": "DSH 悬浮播放器:联动本地网易云音乐客户端或网页版,调音量 / 切歌 / 喜欢红心 / 跳进度 / 滚动歌词 / 一键日推",
5
5
  "keywords": [
6
6
  "dsh",
@@ -48,6 +48,16 @@ test('channelMode 四种模式选择正确', async () => {
48
48
  assert.equal(await router('web-first', true, false).pick(), 'native')
49
49
  })
50
50
 
51
+ test('client-first 客户端在线时锁定 native,不读 web/浏览器 SMTC', async () => {
52
+ const r = router('client-first', true, true)
53
+ // 若实现又去探测哪条通道在播(web 通道会读浏览器 SMTC,被 B 站视频抢占),
54
+ // 这里直接抛错让测试失败。客户端在线就必须锁 native。
55
+ r.channelPlaying = async () => { throw new Error('client-first 不该调用 channelPlaying') }
56
+ assert.equal(await r.pick(), 'native')
57
+ assert.equal((await r.state()).via, 'native')
58
+ assert.equal((await r.action('next')).via, 'native')
59
+ })
60
+
51
61
  test('未知模式回退 client-first', async () => {
52
62
  assert.equal(await router('???', true, true).pick(), 'native')
53
63
  assert.equal(await router('???', false, true).pick(), 'web')
@@ -107,7 +107,7 @@ test('readState TTL 缓存:连续两次读只 spawn 一次,pos 按经过时
107
107
  test('readState 并发合并:同一瞬间多次读共享一次 probe', async () => {
108
108
  let spawnCount = 0
109
109
  const s = new SmtcBrowser({
110
- spawnFactory: () => { spawnCount++; return fakeChild([JSON.stringify({ ok: true, title: 'X', status: 'Paused' })]) },
110
+ spawnFactory: () => { spawnCount++; return fakeChild([JSON.stringify({ ok: true, title: 'X', artist: '歌手X', status: 'Paused' })]) },
111
111
  })
112
112
  const [a, b, c] = await Promise.all([s.readState(), s.readState(), s.readState()])
113
113
  assert.equal(spawnCount, 1, '并发三次读只 spawn 一次')
@@ -205,6 +205,22 @@ test('视频抢占 SMTC 后用最近一次真实音乐(暂停态)兜底,
205
205
  assert.equal(video.title, '会呼吸的痛', '视频会话不能覆盖兜底记忆')
206
206
  })
207
207
 
208
+ test('网易云暂停时 SMTC 清空 artist,但歌名与记住的一致 → 补回歌手照常识别', async () => {
209
+ let probeResult = { ok: true, title: '会呼吸的痛', artist: '梁静茹', status: 'Playing', pos: 10, end: 272, aumid: 'msedge.exe' }
210
+ const s = new SmtcBrowser({ spawnFactory: () => fakeChild([JSON.stringify(probeResult)]) })
211
+ const first = await s.readState()
212
+ assert.equal(first.artist, '梁静茹')
213
+
214
+ // 暂停后 SMTC 会话 artist 变空,但 title 仍是这首歌
215
+ s.invalidate()
216
+ probeResult = { ok: true, title: '会呼吸的痛', artist: '', status: 'Paused', pos: 20, end: 272, aumid: 'msedge.exe' }
217
+ const paused = await s.readState()
218
+ assert.equal(paused.ok, true, '暂停的歌应照常识别,不能被当成视频挡掉')
219
+ assert.equal(paused.title, '会呼吸的痛')
220
+ assert.equal(paused.artist, '梁静茹', '应用 sticky 记忆补回被清空的歌手')
221
+ assert.equal(paused.status, 'Paused')
222
+ })
223
+
208
224
  test('控制作业回读到视频标题时用 sticky 歌名覆盖,保持显示网易云歌', async () => {
209
225
  let controlResult = { ok: true, action: 'pause', title: 'xxx_bilibili', artist: '', status: 'Paused', pos: 5, end: 100 }
210
226
  const s = new SmtcBrowser({