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
package/test/elog.test.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
parseElogHeader,
|
|
23
23
|
eventTimeOf,
|
|
24
24
|
extractTrack,
|
|
25
|
+
extractSource,
|
|
25
26
|
classifyLine,
|
|
26
27
|
ElogWatcher,
|
|
27
28
|
defaultElogPath,
|
|
@@ -71,8 +72,11 @@ function line(rest, agoMs = 0, tag = '【playing】') {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/** 造「曲目详情」那条(playOneTrackInPlayingList / checkPlayPrivilege 同形) */
|
|
74
|
-
function trackLine({ id, name, artist, duration }, agoMs, kind = 'playOneTrackInPlayingList') {
|
|
75
|
-
const
|
|
75
|
+
function trackLine({ id, name, artist, duration, scene, href, text }, agoMs, kind = 'playOneTrackInPlayingList') {
|
|
76
|
+
const src = scene || href || text
|
|
77
|
+
? `"scene":"${scene || ''}","href":"${href || ''}","text":"${text || ''}",`
|
|
78
|
+
: ''
|
|
79
|
+
const json = `{"id":"${id}","displayOrder":1,${src}"localTrack":{},"track":{"id":"${id}","duration":${duration},"name":"${name}","artists":[{"id":"1","name":"${artist}"}],"album":{"id":"2","name":"专辑名"}}}`
|
|
76
80
|
return line(`,"${kind}",${json}`, agoMs)
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -86,6 +90,13 @@ function metaLine({ id, name, artist, duration }, agoMs, kind = 'nativePlay') {
|
|
|
86
90
|
return line(`,"${kind}",${mid}${json}`, agoMs)
|
|
87
91
|
}
|
|
88
92
|
|
|
93
|
+
/** 带顶层来源(scene/href/text)的 refreshCurPlaying,形状对齐真机日志 */
|
|
94
|
+
function sourceMetaLine({ id, name, artist, duration, scene, href, text }, agoMs, kind = 'refreshCurPlaying') {
|
|
95
|
+
const json = `{"id":"${id}","displayOrder":1,"ai":"","aiRcmd":false,"scene":"${scene}","href":"${href}","text":"${text}","localTrack":{},"track":{"id":"${id}","duration":${duration},"name":"${name}","artists":[{"id":"1","name":"${artist}"}],"album":{"id":"2","name":"专辑名"}}}`
|
|
96
|
+
const mid = kind === 'refreshCurPlaying' ? '"curPlaying=",' : ''
|
|
97
|
+
return line(`,"${kind}",${mid}${json}`, agoMs)
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
const startedLine = (id, duration, agoMs) =>
|
|
90
101
|
line(`,"native播放资源load完成,开始播放",{"songId":"${id}","songDuration":"${duration}"}`, agoMs)
|
|
91
102
|
|
|
@@ -196,6 +207,35 @@ test('extractTrack 对没有 id / name 的片段返回 null', () => {
|
|
|
196
207
|
assert.equal(extractTrack(undefined), null)
|
|
197
208
|
})
|
|
198
209
|
|
|
210
|
+
test('extractSource 从 curPlaying 顶层取 scene/href/text', () => {
|
|
211
|
+
const text =
|
|
212
|
+
'{"id":"1","scene":"playlist","href":"/playlist/18334824318","text":"临时","localTrack":{},"track":{"id":"1"}}'
|
|
213
|
+
assert.deepEqual(extractSource(text), {
|
|
214
|
+
scene: 'playlist',
|
|
215
|
+
href: '/playlist/18334824318',
|
|
216
|
+
text: '临时',
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('extractSource 顶层无来源字段时返回 null(不被 track 内同名字段误伤)', () => {
|
|
221
|
+
// 核心防错点:firstString 取第一个匹配,若不在 "localTrack" 处截断,
|
|
222
|
+
// 就会把 track 内部的 scene/text 当成来源 → 显示错误。
|
|
223
|
+
const text = '{"id":"1","localTrack":{},"track":{"scene":"track内","text":"track内","name":"歌"}}'
|
|
224
|
+
assert.equal(extractSource(text), null)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('extractSource 还原 text 里的 JSON 转义', () => {
|
|
228
|
+
// 源文本里 text 值是 "我\"歌单\""(JSON 转义),捕获后应还原成 我"歌单"
|
|
229
|
+
const text = '{"scene":"playlist","text":"我\\"歌单\\"","localTrack":{}}'
|
|
230
|
+
assert.deepEqual(extractSource(text), { scene: 'playlist', href: '', text: '我"歌单"' })
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('extractSource 对空/非字符串输入返回 null', () => {
|
|
234
|
+
assert.equal(extractSource(undefined), null)
|
|
235
|
+
assert.equal(extractSource(''), null)
|
|
236
|
+
assert.equal(extractSource('{"foo":1,"localTrack":{}}'), null)
|
|
237
|
+
})
|
|
238
|
+
|
|
199
239
|
test('classifyLine 区分「开始load」与「load完成,开始播放」', () => {
|
|
200
240
|
// 「native播放资源开始load」是另一条事件(还没出声),不能当成起播
|
|
201
241
|
assert.equal(classifyLine(',"native播放资源开始load",{"songId":"1"}'), null)
|
|
@@ -606,6 +646,119 @@ test('Watcher:refreshCurPlaying 在播放中途出现时不打断进度', () =
|
|
|
606
646
|
}
|
|
607
647
|
})
|
|
608
648
|
|
|
649
|
+
test('Watcher:refreshCurPlaying 记录来源,nativePlay 不清除(last-known)', () => {
|
|
650
|
+
const file = tmpFile()
|
|
651
|
+
writeLog(file, [
|
|
652
|
+
sourceMetaLine(
|
|
653
|
+
{ id: '3', name: '正在播', artist: 'P', duration: 300_000, scene: 'playlist', href: '/playlist/18334824318', text: '临时' },
|
|
654
|
+
0,
|
|
655
|
+
),
|
|
656
|
+
])
|
|
657
|
+
const w = new ElogWatcher({ filePath: file })
|
|
658
|
+
w.start()
|
|
659
|
+
try {
|
|
660
|
+
assert.deepEqual(w.getState().source, {
|
|
661
|
+
scene: 'playlist',
|
|
662
|
+
href: '/playlist/18334824318',
|
|
663
|
+
text: '临时',
|
|
664
|
+
})
|
|
665
|
+
|
|
666
|
+
// 之后来一条不带来源的 nativePlay,来源应保持 last-known
|
|
667
|
+
appendLog(file, [
|
|
668
|
+
metaLine({ id: '3', name: '正在播', artist: 'P', duration: 300_000 }, 0, 'nativePlay'),
|
|
669
|
+
])
|
|
670
|
+
w.poll()
|
|
671
|
+
assert.equal(w.getState().source.text, '临时')
|
|
672
|
+
} finally {
|
|
673
|
+
w.stop()
|
|
674
|
+
}
|
|
675
|
+
})
|
|
676
|
+
|
|
677
|
+
test('Watcher:来源 text 为空也记录(前端显示「未知」)', () => {
|
|
678
|
+
const file = tmpFile()
|
|
679
|
+
writeLog(file, [
|
|
680
|
+
sourceMetaLine(
|
|
681
|
+
{ id: '4', name: '歌', artist: 'Q', duration: 200_000, scene: 'orpheusMessage', href: '', text: '' },
|
|
682
|
+
0,
|
|
683
|
+
),
|
|
684
|
+
])
|
|
685
|
+
const w = new ElogWatcher({ filePath: file })
|
|
686
|
+
w.start()
|
|
687
|
+
try {
|
|
688
|
+
const s = w.getState().source
|
|
689
|
+
assert.ok(s, '来源对象应存在(含空 text)')
|
|
690
|
+
assert.equal(s.text, '')
|
|
691
|
+
assert.equal(s.scene, 'orpheusMessage')
|
|
692
|
+
} finally {
|
|
693
|
+
w.stop()
|
|
694
|
+
}
|
|
695
|
+
})
|
|
696
|
+
|
|
697
|
+
test('Watcher:playOneTrackInPlayingList 顶层来源写入 source(每次切歌必发)', () => {
|
|
698
|
+
const file = tmpFile()
|
|
699
|
+
writeLog(file, [
|
|
700
|
+
trackLine(
|
|
701
|
+
{ id: '5', name: 'Letting Go', artist: '蔡健雅', duration: 259_000, scene: 'playlist', href: '', text: '穗织第一幼刀_喜欢的音乐' },
|
|
702
|
+
0,
|
|
703
|
+
),
|
|
704
|
+
])
|
|
705
|
+
const w = new ElogWatcher({ filePath: file })
|
|
706
|
+
w.start()
|
|
707
|
+
try {
|
|
708
|
+
assert.deepEqual(w.getState().source, {
|
|
709
|
+
scene: 'playlist',
|
|
710
|
+
href: '',
|
|
711
|
+
text: '穗织第一幼刀_喜欢的音乐',
|
|
712
|
+
})
|
|
713
|
+
} finally {
|
|
714
|
+
w.stop()
|
|
715
|
+
}
|
|
716
|
+
})
|
|
717
|
+
|
|
718
|
+
test('Watcher:随后无来源的 track 事件不清除上次来源(last-known)', () => {
|
|
719
|
+
const file = tmpFile()
|
|
720
|
+
writeLog(file, [
|
|
721
|
+
trackLine(
|
|
722
|
+
{ id: '5', name: 'Letting Go', artist: '蔡健雅', duration: 259_000, scene: 'playlist', href: '', text: '临时歌单' },
|
|
723
|
+
4_000,
|
|
724
|
+
),
|
|
725
|
+
])
|
|
726
|
+
const w = new ElogWatcher({ filePath: file })
|
|
727
|
+
w.start()
|
|
728
|
+
try {
|
|
729
|
+
assert.equal(w.getState().source.text, '临时歌单')
|
|
730
|
+
// 同次起播连发的那条无来源事件(checkPlayPrivilege)不该清空来源
|
|
731
|
+
appendLog(file, [
|
|
732
|
+
trackLine({ id: '5', name: 'Letting Go', artist: '蔡健雅', duration: 259_000 }, 0, 'checkPlayPrivilege'),
|
|
733
|
+
])
|
|
734
|
+
w.poll()
|
|
735
|
+
assert.equal(w.getState().source.text, '临时歌单')
|
|
736
|
+
} finally {
|
|
737
|
+
w.stop()
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
|
|
741
|
+
test('Watcher:每日推荐来源(dailyRecommend)正确抽取', () => {
|
|
742
|
+
const file = tmpFile()
|
|
743
|
+
writeLog(file, [
|
|
744
|
+
trackLine(
|
|
745
|
+
{ id: '6', name: '歌', artist: 'R', duration: 200_000, scene: 'dailyRecommend', href: '', text: '每日歌曲推荐' },
|
|
746
|
+
0,
|
|
747
|
+
),
|
|
748
|
+
])
|
|
749
|
+
const w = new ElogWatcher({ filePath: file })
|
|
750
|
+
w.start()
|
|
751
|
+
try {
|
|
752
|
+
assert.deepEqual(w.getState().source, {
|
|
753
|
+
scene: 'dailyRecommend',
|
|
754
|
+
href: '',
|
|
755
|
+
text: '每日歌曲推荐',
|
|
756
|
+
})
|
|
757
|
+
} finally {
|
|
758
|
+
w.stop()
|
|
759
|
+
}
|
|
760
|
+
})
|
|
761
|
+
|
|
609
762
|
test('Watcher:换歌时 nativePlay 先到、started 未到时仍报旧歌', () => {
|
|
610
763
|
const file = tmpFile()
|
|
611
764
|
writeLog(file, [
|