dsh-cloudmusic-player 0.5.0 → 0.7.20
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 +328 -0
- package/README.md +17 -10
- package/client.js +84 -9
- package/cordis.patch.yml +6 -0
- package/index.js +114 -11
- package/lib/backend.mjs +3 -2
- package/lib/channel.mjs +229 -0
- package/lib/elog.mjs +53 -1
- package/lib/helper.ps1 +55 -15
- package/lib/like.mjs +287 -0
- package/lib/player.mjs +199 -3
- package/lib/smtc-browser.mjs +304 -0
- package/lib/smtc-probe.ps1 +190 -0
- package/lib/web-backend.mjs +1444 -0
- package/lib/winrt-audio.mjs +185 -0
- package/lib/winrt-audio.ps1 +163 -0
- package/locale/en.json +6 -1
- package/locale/zh.json +6 -1
- package/package.json +6 -6
- package/scripts/sync-github.ps1 +2 -2
- package/test/channel.test.mjs +79 -0
- package/test/elog.test.mjs +155 -2
- package/test/like.test.mjs +632 -0
- package/test/smtc-browser.test.mjs +240 -0
- package/test/web-backend.test.mjs +645 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* winrt-audio.mjs — Node 侧行协议封装,驱动 lib/winrt-audio.ps1 常驻 WinRT 后台音频引擎。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:日推要在「个人 Edge 无 CDP + ego 关着 + 不弹任何页面」的前提下精确
|
|
5
|
+
* 播指定歌。网页 <audio> 要 CDP、SMTC 只能控制不能指定曲目、WMP COM 解不了 m4a 也不
|
|
6
|
+
* 注册媒体会话——只有 WinRT MediaPlayer 满足全部约束(无窗口、不弹页、不依赖 CDP)。
|
|
7
|
+
*
|
|
8
|
+
* 协议:stdin 一行一个 JSON 请求 {seq,cmd,...},stdout 一行一个 JSON 响应 {seq,...}。
|
|
9
|
+
* 第一行是 ready 握手 {seq:0,ok:true,ready:true}。沿用 player.mjs 的 seq 配对模式。
|
|
10
|
+
* 不依赖任何 npm 包;PowerShell 走 System32 绝对路径(宿主 PATH 裸名会 ENOENT)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawn } from 'node:child_process'
|
|
14
|
+
import { createInterface } from 'node:readline'
|
|
15
|
+
import { join, dirname } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const PS1 = join(HERE, 'winrt-audio.ps1')
|
|
20
|
+
|
|
21
|
+
/** System32 里 PowerShell 5.1 的固定路径;优先 env.SystemRoot,兜底 C:\Windows。 */
|
|
22
|
+
export function resolvePowershell() {
|
|
23
|
+
const root = process.env.SystemRoot || 'C:\\Windows'
|
|
24
|
+
return join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const READY_TIMEOUT_MS = 8000
|
|
28
|
+
const DEFAULT_TIMEOUT_MS = 6000
|
|
29
|
+
|
|
30
|
+
export class WinrtAudio {
|
|
31
|
+
constructor(opts = {}) {
|
|
32
|
+
this.log = typeof opts.log === 'function' ? opts.log : () => {}
|
|
33
|
+
this.getConfig = typeof opts.getConfig === 'function' ? opts.getConfig : () => ({})
|
|
34
|
+
this.psPath = opts.psPath || resolvePowershell()
|
|
35
|
+
this.ps1Path = opts.ps1Path || PS1
|
|
36
|
+
this.requestTimeoutMs = Number(opts.requestTimeoutMs) || DEFAULT_TIMEOUT_MS
|
|
37
|
+
|
|
38
|
+
this.child = null
|
|
39
|
+
this.rl = null
|
|
40
|
+
this.starting = null
|
|
41
|
+
this.stopped = false
|
|
42
|
+
this.ready = false
|
|
43
|
+
this.lastError = ''
|
|
44
|
+
this.seq = 0
|
|
45
|
+
/** @type {Map<number,{resolve:Function,reject:Function,timer:any}>} */
|
|
46
|
+
this.pending = new Map()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 起常驻引擎(幂等)。返回 ready 信息。 */
|
|
50
|
+
async start() {
|
|
51
|
+
if (this.stopped) throw new Error('winrt audio stopped')
|
|
52
|
+
if (this.ready && this.child && !this.child.killed) return this._readyInfo()
|
|
53
|
+
if (this.starting) return this.starting
|
|
54
|
+
this.starting = this.#spawnOnce().finally(() => { this.starting = null })
|
|
55
|
+
return this.starting
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async #spawnOnce() {
|
|
59
|
+
const child = spawn(this.psPath, [
|
|
60
|
+
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass',
|
|
61
|
+
'-File', this.ps1Path,
|
|
62
|
+
], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
63
|
+
this.child = child
|
|
64
|
+
this.ready = false
|
|
65
|
+
this.stderrTail = ''
|
|
66
|
+
|
|
67
|
+
child.stderr.setEncoding('utf8')
|
|
68
|
+
child.stderr.on('data', (chunk) => {
|
|
69
|
+
this.stderrTail = (this.stderrTail + chunk).slice(-4096)
|
|
70
|
+
})
|
|
71
|
+
child.stdin.on('error', (err) => {
|
|
72
|
+
this.lastError = `stdin: ${err && err.message ? err.message : err}`
|
|
73
|
+
})
|
|
74
|
+
child.on('exit', (code) => {
|
|
75
|
+
this.ready = false
|
|
76
|
+
this.child = null
|
|
77
|
+
// 所有在途请求立刻失败,别挂到超时
|
|
78
|
+
for (const [, p] of this.pending) {
|
|
79
|
+
clearTimeout(p.timer)
|
|
80
|
+
p.reject(new Error(`winrt audio exited (code=${code}) ${this.stderrTail.slice(-200)}`))
|
|
81
|
+
}
|
|
82
|
+
this.pending.clear()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const ready = await new Promise((resolve, reject) => {
|
|
86
|
+
let settled = false
|
|
87
|
+
const timer = setTimeout(() => {
|
|
88
|
+
if (settled) return
|
|
89
|
+
settled = true
|
|
90
|
+
try { child.kill() } catch { /* ignore */ }
|
|
91
|
+
reject(new Error(`winrt audio not ready in ${READY_TIMEOUT_MS}ms ${this.stderrTail.slice(-300)}`))
|
|
92
|
+
}, READY_TIMEOUT_MS)
|
|
93
|
+
|
|
94
|
+
this.rl = createInterface({ input: child.stdout })
|
|
95
|
+
this.rl.on('line', (line) => {
|
|
96
|
+
const text = String(line).trim()
|
|
97
|
+
if (!text) return
|
|
98
|
+
let msg
|
|
99
|
+
try { msg = JSON.parse(text) } catch {
|
|
100
|
+
this.log(`winrt-audio non-json: ${text.slice(0, 160)}`)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
if (msg && msg.seq === 0 && msg.ready === true) {
|
|
104
|
+
if (settled) return
|
|
105
|
+
settled = true
|
|
106
|
+
clearTimeout(timer)
|
|
107
|
+
if (msg.ok === false) { reject(new Error(msg.detail || msg.error || 'winrt unavailable')); return }
|
|
108
|
+
this.ready = true
|
|
109
|
+
this.lastError = ''
|
|
110
|
+
resolve(this._readyInfo())
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
this.#dispatch(msg)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
return ready
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#dispatch(msg) {
|
|
120
|
+
if (!msg || typeof msg.seq !== 'number') return
|
|
121
|
+
const p = this.pending.get(msg.seq)
|
|
122
|
+
if (!p) return
|
|
123
|
+
this.pending.delete(msg.seq)
|
|
124
|
+
clearTimeout(p.timer)
|
|
125
|
+
p.resolve(msg)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_readyInfo() {
|
|
129
|
+
return { ok: true, ready: true, backend: 'winrt-mediaplayer', engine: this.ps1Path }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 发一条命令,等配对响应。 */
|
|
133
|
+
async request(cmd, payload = {}, timeoutMs) {
|
|
134
|
+
try { await this.start() } catch (err) {
|
|
135
|
+
return { ok: false, error: 'winrt-unavailable', detail: String(err?.message || err) }
|
|
136
|
+
}
|
|
137
|
+
const seq = ++this.seq
|
|
138
|
+
const msg = { seq, cmd, ...payload }
|
|
139
|
+
const timeout = Number(timeoutMs) || this.requestTimeoutMs
|
|
140
|
+
const res = await new Promise((resolve) => {
|
|
141
|
+
const timer = setTimeout(() => {
|
|
142
|
+
this.pending.delete(seq)
|
|
143
|
+
resolve({ ok: false, error: 'winrt-timeout', detail: `${cmd} timed out in ${timeout}ms` })
|
|
144
|
+
}, timeout)
|
|
145
|
+
this.pending.set(seq, { resolve, reject: (err) => resolve({ ok: false, error: 'winrt-error', detail: String(err?.message || err) }), timer })
|
|
146
|
+
try {
|
|
147
|
+
this.child.stdin.write(JSON.stringify(msg) + '\n')
|
|
148
|
+
} catch (err) {
|
|
149
|
+
clearTimeout(timer)
|
|
150
|
+
this.pending.delete(seq)
|
|
151
|
+
resolve({ ok: false, error: 'winrt-write-failed', detail: String(err?.message || err) })
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
if (res && res.ok === true) this.lastError = ''
|
|
155
|
+
else if (res && res.detail) this.lastError = String(res.detail)
|
|
156
|
+
return res
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 播一首(URL 来自明文 song/url API)。 */
|
|
160
|
+
play({ url, songId, title, artist, positionMs, level, muted } = {}) {
|
|
161
|
+
return this.request('play', { url, songId, title, artist, positionMs, level, muted })
|
|
162
|
+
}
|
|
163
|
+
pause() { return this.request('pause') }
|
|
164
|
+
resume() { return this.request('resume') }
|
|
165
|
+
toggle() { return this.request('toggle') }
|
|
166
|
+
seek(positionMs) { return this.request('seek', { positionMs }) }
|
|
167
|
+
volume(level, muted) { return this.request('volume', { level, muted }) }
|
|
168
|
+
state() { return this.request('state') }
|
|
169
|
+
stop() { return this.request('stop') }
|
|
170
|
+
|
|
171
|
+
async close() {
|
|
172
|
+
this.stopped = true
|
|
173
|
+
if (this.child && !this.child.killed) {
|
|
174
|
+
try { this.child.stdin.write(JSON.stringify({ seq: ++this.seq, cmd: 'quit' }) + '\n') } catch { /* ignore */ }
|
|
175
|
+
try { this.child.kill() } catch { /* ignore */ }
|
|
176
|
+
}
|
|
177
|
+
this.child = null
|
|
178
|
+
this.rl = null
|
|
179
|
+
this.ready = false
|
|
180
|
+
for (const [, p] of this.pending) { clearTimeout(p.timer); try { p.resolve({ ok: false, error: 'winrt-closed' }) } catch { /* ignore */ } }
|
|
181
|
+
this.pending.clear()
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export default WinrtAudio
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
param()
|
|
2
|
+
|
|
3
|
+
# winrt-audio.ps1 - resident background audio engine for cloudmusic-player web channel.
|
|
4
|
+
# Reads one JSON command per line from stdin, writes one JSON response per line to stdout.
|
|
5
|
+
# Uses WinRT MediaPlayer (no window, no browser page, no CDP, not registered in SMTC).
|
|
6
|
+
# IMPORTANT: this file must stay pure ASCII. PowerShell 5.1 decodes script text with the
|
|
7
|
+
# system ANSI codepage (GBK on zh-CN); non-ASCII comments become mojibake / ParserError.
|
|
8
|
+
|
|
9
|
+
$ErrorActionPreference = 'Stop'
|
|
10
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
11
|
+
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
12
|
+
|
|
13
|
+
function Out-Json([hashtable]$obj) {
|
|
14
|
+
[Console]::Out.WriteLine(($obj | ConvertTo-Json -Compress -Depth 8))
|
|
15
|
+
[Console]::Out.Flush()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
Add-Type -AssemblyName System.Runtime.WindowsRuntime -ErrorAction Stop
|
|
20
|
+
[Windows.Media.Playback.MediaPlayer,Windows.Media.Playback,ContentType=WindowsRuntime] | Out-Null
|
|
21
|
+
[Windows.Media.Core.MediaSource,Windows.Media.Core,ContentType=WindowsRuntime] | Out-Null
|
|
22
|
+
} catch {
|
|
23
|
+
Out-Json @{ seq=0; ok=$false; ready=$false; error='winrt-unavailable'; detail=($_.Exception.Message) }
|
|
24
|
+
exit 0
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$mp = $null
|
|
28
|
+
$curSongId = ''
|
|
29
|
+
$curTitle = ''
|
|
30
|
+
$curArtist = ''
|
|
31
|
+
$curUrl = ''
|
|
32
|
+
|
|
33
|
+
function Get-Session {
|
|
34
|
+
if ($null -eq $mp) { return $null }
|
|
35
|
+
try { return $mp.PlaybackSession } catch { return $null }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function Get-StateObj([int]$seq) {
|
|
39
|
+
$st = Get-Session
|
|
40
|
+
if ($null -eq $st) {
|
|
41
|
+
return @{ seq=$seq; ok=$true; active=$false; status='Paused'; pos=[double]0; end=[double]0; songId=$curSongId; title=$curTitle; artist=$curArtist; volume=[double]1; muted=$false }
|
|
42
|
+
}
|
|
43
|
+
$state = [string]$st.PlaybackState
|
|
44
|
+
$pos = [double]0
|
|
45
|
+
$end = [double]0
|
|
46
|
+
try { $pos = [double]$st.Position.TotalSeconds } catch {}
|
|
47
|
+
try { $end = [double]$st.NaturalDuration.TotalSeconds } catch {}
|
|
48
|
+
$vol = [double]1
|
|
49
|
+
$mut = $false
|
|
50
|
+
try { $vol = [double]$mp.Volume } catch {}
|
|
51
|
+
try { $mut = [bool]$mp.IsMuted } catch {}
|
|
52
|
+
return @{ seq=$seq; ok=$true; active=$true; status=$state; pos=$pos; end=$end; songId=$curSongId; title=$curTitle; artist=$curArtist; url=$curUrl; volume=$vol; muted=$mut }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Out-Json @{ seq=0; ok=$true; ready=$true; engine='winrt-mediaplayer' }
|
|
56
|
+
|
|
57
|
+
while ($true) {
|
|
58
|
+
$line = [Console]::In.ReadLine()
|
|
59
|
+
if ($null -eq $line) { break }
|
|
60
|
+
if ([string]::IsNullOrWhiteSpace($line)) { continue }
|
|
61
|
+
$req = $null
|
|
62
|
+
try { $req = $line | ConvertFrom-Json } catch {
|
|
63
|
+
Out-Json @{ seq=0; ok=$false; error='bad-json'; detail=$_.Exception.Message }
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
$seq = 0
|
|
67
|
+
try { $seq = [int]$req.seq } catch {}
|
|
68
|
+
$cmd = [string]$req.cmd
|
|
69
|
+
try {
|
|
70
|
+
switch ($cmd) {
|
|
71
|
+
'play' {
|
|
72
|
+
$url = [string]$req.url
|
|
73
|
+
if ([string]::IsNullOrEmpty($url)) { Out-Json @{ seq=$seq; ok=$false; error='no-url' }; break }
|
|
74
|
+
if ($null -eq $mp) {
|
|
75
|
+
$mp = New-Object Windows.Media.Playback.MediaPlayer
|
|
76
|
+
$mp.IsLoopingEnabled = $false
|
|
77
|
+
}
|
|
78
|
+
# Source must be a MediaSource, not a raw System.Uri.
|
|
79
|
+
$src = [Windows.Media.Core.MediaSource]::CreateFromUri([System.Uri]$url)
|
|
80
|
+
$mp.Source = $src
|
|
81
|
+
$curUrl = $url
|
|
82
|
+
$curSongId = [string]$req.songId
|
|
83
|
+
$curTitle = [string]$req.title
|
|
84
|
+
$curArtist = [string]$req.artist
|
|
85
|
+
if ($null -ne $req.level) { try { $mp.Volume = [double]$req.level } catch {} }
|
|
86
|
+
if ($null -ne $req.muted) { try { $mp.IsMuted = [bool]$req.muted } catch {} }
|
|
87
|
+
$st = Get-Session
|
|
88
|
+
if ($null -ne $st) {
|
|
89
|
+
if ($null -ne $req.positionMs -and [double]$req.positionMs -gt 0) {
|
|
90
|
+
try { $st.Position = [TimeSpan]::FromMilliseconds([double]$req.positionMs) } catch {}
|
|
91
|
+
}
|
|
92
|
+
try { $st.PlaybackRate = 1.0 } catch {}
|
|
93
|
+
}
|
|
94
|
+
$mp.Play()
|
|
95
|
+
$r = Get-StateObj $seq
|
|
96
|
+
$r.cmd = 'play'
|
|
97
|
+
Out-Json $r
|
|
98
|
+
}
|
|
99
|
+
'pause' {
|
|
100
|
+
if ($null -ne $mp) { try { $mp.Pause() } catch {} }
|
|
101
|
+
$r = Get-StateObj $seq; $r.cmd = 'pause'; Out-Json $r
|
|
102
|
+
}
|
|
103
|
+
'resume' {
|
|
104
|
+
if ($null -ne $mp) {
|
|
105
|
+
$st = Get-Session
|
|
106
|
+
if ($null -ne $st) { try { $st.PlaybackRate = 1.0 } catch {} }
|
|
107
|
+
try { $mp.Play() } catch {}
|
|
108
|
+
}
|
|
109
|
+
$r = Get-StateObj $seq; $r.cmd = 'resume'; Out-Json $r
|
|
110
|
+
}
|
|
111
|
+
'toggle' {
|
|
112
|
+
if ($null -ne $mp) {
|
|
113
|
+
$st = Get-Session
|
|
114
|
+
$state = if ($null -ne $st) { [string]$st.PlaybackState } else { 'Paused' }
|
|
115
|
+
if ($state -eq 'Playing') {
|
|
116
|
+
try { $mp.Pause() } catch {}
|
|
117
|
+
} else {
|
|
118
|
+
if ($null -ne $st) { try { $st.PlaybackRate = 1.0 } catch {} }
|
|
119
|
+
try { $mp.Play() } catch {}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
$r = Get-StateObj $seq; $r.cmd = 'toggle'; Out-Json $r
|
|
123
|
+
}
|
|
124
|
+
'seek' {
|
|
125
|
+
$ms = [double]0
|
|
126
|
+
try { $ms = [double]$req.positionMs } catch {}
|
|
127
|
+
if ($ms -lt 0) { $ms = 0 }
|
|
128
|
+
$st = Get-Session
|
|
129
|
+
if ($null -ne $st) { try { $st.Position = [TimeSpan]::FromMilliseconds($ms) } catch {} }
|
|
130
|
+
$r = Get-StateObj $seq; $r.cmd = 'seek'; Out-Json $r
|
|
131
|
+
}
|
|
132
|
+
'volume' {
|
|
133
|
+
if ($null -ne $mp) {
|
|
134
|
+
if ($null -ne $req.level) { try { $mp.Volume = [double]$req.level } catch {} }
|
|
135
|
+
if ($null -ne $req.muted) { try { $mp.IsMuted = [bool]$req.muted } catch {} }
|
|
136
|
+
}
|
|
137
|
+
$r = Get-StateObj $seq; $r.cmd = 'volume'; Out-Json $r
|
|
138
|
+
}
|
|
139
|
+
'state' {
|
|
140
|
+
$r = Get-StateObj $seq; $r.cmd = 'state'; Out-Json $r
|
|
141
|
+
}
|
|
142
|
+
'stop' {
|
|
143
|
+
if ($null -ne $mp) {
|
|
144
|
+
try { $mp.Pause() } catch {}
|
|
145
|
+
try { $mp.Dispose() } catch {}
|
|
146
|
+
$mp = $null
|
|
147
|
+
}
|
|
148
|
+
$curSongId = ''; $curTitle = ''; $curArtist = ''; $curUrl = ''
|
|
149
|
+
Out-Json @{ seq=$seq; ok=$true; active=$false; status='Paused'; pos=[double]0; end=[double]0; songId=''; title=''; artist=''; cmd='stop' }
|
|
150
|
+
}
|
|
151
|
+
'quit' {
|
|
152
|
+
if ($null -ne $mp) { try { $mp.Dispose() } catch {}; $mp = $null }
|
|
153
|
+
Out-Json @{ seq=$seq; ok=$true; cmd='quit' }
|
|
154
|
+
break
|
|
155
|
+
}
|
|
156
|
+
default {
|
|
157
|
+
Out-Json @{ seq=$seq; ok=$false; error='bad-cmd'; detail=("unknown cmd: " + $cmd) }
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
Out-Json @{ seq=$seq; ok=$false; error='cmd-failed'; detail=($_.Exception.Message) }
|
|
162
|
+
}
|
|
163
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "NetEase Music Player",
|
|
4
|
-
"description": "A small floating player inside DSH, wired to your local NetEase Cloud Music client: prev / play-pause / next, drag the volume, scrolling lyrics."
|
|
4
|
+
"description": "A small floating player inside DSH, wired to your local NetEase Cloud Music client: prev / play-pause / next, a like heart, drag the volume, scrolling lyrics."
|
|
5
5
|
},
|
|
6
6
|
"player": {
|
|
7
7
|
"play": "Play",
|
|
8
8
|
"pause": "Pause",
|
|
9
9
|
"next": "Next",
|
|
10
10
|
"prev": "Previous",
|
|
11
|
+
"like": "Like",
|
|
12
|
+
"unlike": "Unlike",
|
|
13
|
+
"albumLabel": "Album",
|
|
14
|
+
"sourceLabel": "Source",
|
|
15
|
+
"sourceUnknown": "Unknown",
|
|
11
16
|
"volume": "Volume",
|
|
12
17
|
"lyrics": "Lyrics",
|
|
13
18
|
"close": "Collapse",
|
package/locale/zh.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "网易云播放器",
|
|
4
|
-
"description": "在 DSH 里挂一个悬浮小播放器,联动本机网易云音乐客户端:上一首 / 播放暂停 /
|
|
4
|
+
"description": "在 DSH 里挂一个悬浮小播放器,联动本机网易云音乐客户端:上一首 / 播放暂停 / 下一首、喜欢红心、拖音量、滚动歌词。"
|
|
5
5
|
},
|
|
6
6
|
"player": {
|
|
7
7
|
"play": "播放",
|
|
8
8
|
"pause": "暂停",
|
|
9
9
|
"next": "下一首",
|
|
10
10
|
"prev": "上一首",
|
|
11
|
+
"like": "喜欢",
|
|
12
|
+
"unlike": "取消喜欢",
|
|
13
|
+
"albumLabel": "专辑",
|
|
14
|
+
"sourceLabel": "来源",
|
|
15
|
+
"sourceUnknown": "未知",
|
|
11
16
|
"volume": "音量",
|
|
12
17
|
"lyrics": "歌词",
|
|
13
18
|
"close": "收起",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cloudmusic-player",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH
|
|
3
|
+
"version": "0.7.20",
|
|
4
|
+
"description": "DSH 悬浮播放器:联动本地网易云音乐客户端或网页版,调音量 / 切歌 / 喜欢红心 / 跳进度 / 滚动歌词 / 一键日推",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
7
7
|
"dsh-plugin",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"author": "dsh-cloudmusic-player contributors",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player.git"
|
|
20
20
|
},
|
|
21
|
-
"homepage": "https://github.com/
|
|
21
|
+
"homepage": "https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player#readme",
|
|
22
22
|
"bugs": {
|
|
23
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player/issues"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"main": "index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"docs"
|
|
48
48
|
],
|
|
49
49
|
"scripts": {
|
|
50
|
-
"test": "node --test test/elog.test.mjs test/lyrics.test.mjs test/transport.test.mjs test/daily.test.mjs",
|
|
50
|
+
"test": "node --test test/elog.test.mjs test/lyrics.test.mjs test/transport.test.mjs test/daily.test.mjs test/like.test.mjs test/channel.test.mjs test/web-backend.test.mjs test/smtc-browser.test.mjs",
|
|
51
51
|
"enable-desktop": "node scripts/enable-desktop.mjs",
|
|
52
52
|
"sync": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/sync-github.ps1"
|
|
53
53
|
},
|
package/scripts/sync-github.ps1
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<#
|
|
2
2
|
.SYNOPSIS
|
|
3
3
|
把本地改动同步到 GitHub:补 remote → add → commit → push。
|
|
4
4
|
|
|
@@ -51,7 +51,7 @@ try {
|
|
|
51
51
|
Fail @'
|
|
52
52
|
这里不是 git 仓库(.git 丢了?)。
|
|
53
53
|
换机器/换目录后的恢复办法:
|
|
54
|
-
git clone https://github.com/
|
|
54
|
+
git clone https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player.git <新目录>
|
|
55
55
|
然后把你的改动覆盖进去,再跑一次 npm run sync。
|
|
56
56
|
(注意:clone 时本地 node_modules 会被跳过,需要时跑一次 npm install。)
|
|
57
57
|
'@
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// channel.mjs 单元测试
|
|
2
|
+
import { test } from 'node:test'
|
|
3
|
+
import assert from 'node:assert/strict'
|
|
4
|
+
import { ChannelRouter, detectClientRunning } from '../lib/channel.mjs'
|
|
5
|
+
|
|
6
|
+
function fakeNative() {
|
|
7
|
+
return {
|
|
8
|
+
backend: { id: 'windows-powershell', platform: 'win32' },
|
|
9
|
+
degraded: '', windowLeak: false, ready: true, restartLimit: 3,
|
|
10
|
+
state: async () => ({ ok: true, via: 'native' }),
|
|
11
|
+
action: async (a) => ({ ok: true, via: 'native', action: a }),
|
|
12
|
+
volume: async () => ({ ok: true, via: 'native' }),
|
|
13
|
+
readyInfo: () => ({ backend: 'windows-powershell', capabilities: {}, platform: 'win32' }),
|
|
14
|
+
deepHealth: async () => ({ ok: true, platform: 'win32' }),
|
|
15
|
+
on() {}, start() {}, stop() {}, restart: async () => ({ ok: true }),
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function fakeWeb(loggedIn = true) {
|
|
19
|
+
return {
|
|
20
|
+
id: 'web-cdp', capabilities: { playback: true }, lastError: '',
|
|
21
|
+
_isLoggedIn: async () => loggedIn,
|
|
22
|
+
ensure: async () => ({ ok: true }),
|
|
23
|
+
state: async () => ({ ok: true, via: 'web' }),
|
|
24
|
+
action: async (a) => ({ ok: true, via: 'web', action: a }),
|
|
25
|
+
volume: async () => ({ ok: true, via: 'web' }),
|
|
26
|
+
deepHealth: async () => ({ ok: true, platform: 'web' }),
|
|
27
|
+
stop() {},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function router(mode, online, webOk) {
|
|
31
|
+
const r = new ChannelRouter({
|
|
32
|
+
native: fakeNative(), web: fakeWeb(webOk),
|
|
33
|
+
getConfig: () => ({ channelMode: mode, processName: 'cloudmusic' }),
|
|
34
|
+
log: () => {},
|
|
35
|
+
})
|
|
36
|
+
r.clientOnline = async () => online
|
|
37
|
+
r.webAvailable = async () => webOk
|
|
38
|
+
return r
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
test('channelMode 四种模式选择正确', async () => {
|
|
42
|
+
assert.equal(await router('client-only', true, true).pick(), 'native')
|
|
43
|
+
assert.equal(await router('client-only', false, true).pick(), 'native')
|
|
44
|
+
assert.equal(await router('web-only', true, true).pick(), 'web')
|
|
45
|
+
assert.equal(await router('client-first', true, true).pick(), 'native')
|
|
46
|
+
assert.equal(await router('client-first', false, true).pick(), 'web')
|
|
47
|
+
assert.equal(await router('web-first', true, true).pick(), 'web')
|
|
48
|
+
assert.equal(await router('web-first', true, false).pick(), 'native')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('未知模式回退 client-first', async () => {
|
|
52
|
+
assert.equal(await router('???', true, true).pick(), 'native')
|
|
53
|
+
assert.equal(await router('???', false, true).pick(), 'web')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('state/action/volume 走当前通道且形状一致', async () => {
|
|
57
|
+
const r = router('client-first', false, true)
|
|
58
|
+
assert.equal((await r.state()).via, 'web')
|
|
59
|
+
assert.equal((await r.action('next')).via, 'web')
|
|
60
|
+
assert.equal((await r.volume({ level: 0.5 })).via, 'web')
|
|
61
|
+
r._clientCache = { at: 0, value: null }
|
|
62
|
+
r.clientOnline = async () => true
|
|
63
|
+
assert.equal((await r.state()).via, 'native')
|
|
64
|
+
assert.equal((await r.action('next')).via, 'native')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('backend/degraded/readyInfo 反映当前通道', async () => {
|
|
68
|
+
const r = router('web-only', true, true)
|
|
69
|
+
await r.pick()
|
|
70
|
+
assert.equal(r.backend.id, 'web-cdp')
|
|
71
|
+
assert.equal(r.readyInfo().backend, 'web-cdp')
|
|
72
|
+
assert.equal(r.readyInfo().capabilities.playback, true)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('detectClientRunning 非 win32 返回 false', async () => {
|
|
76
|
+
if (process.platform !== 'win32') {
|
|
77
|
+
assert.equal(await detectClientRunning({}), false)
|
|
78
|
+
}
|
|
79
|
+
})
|