dsh-music-player 0.1.2 → 0.1.3
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/README.md +6 -4
- package/lib/client.js +16 -5
- package/lib/index.js +90 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# dsh-music-player
|
|
2
2
|
|
|
3
|
+
[](https://awesome-dsh-plugin.com)
|
|
4
|
+
|
|
3
5
|
DeepSeek Harness 本地音乐库播放器插件(bundle)。
|
|
4
6
|
|
|
5
|
-
在 Host 进程里扫描本地音乐目录(默认 `~/Music`,可在面板里改),以 HTTP
|
|
7
|
+
在 Host 进程里扫描本地音乐目录(默认 `~/Music`,可在面板里改),以 HTTP Range 流式(仅显示播放时间,暂无拖动跳转)给浏览器提供音频;浏览器侧给聊天输入区注入**正在播放条**(曲目信息、上一首/播放暂停/下一首/停止、顺序/单曲/乱序循环模式、音量、实时频谱),并提供一个浮动的**播放面板**(曲目列表 / 音乐目录选择与格式提示)。同时注册 `music_play` 模型工具,让 agent 可以直接按关键词播放本地音乐。
|
|
6
8
|
|
|
7
9
|
## 特性
|
|
8
10
|
|
|
9
|
-
-
|
|
11
|
+
- 本地音频流式播放(HTTP Range),刷新后断点续播
|
|
10
12
|
- 顺序播放、单曲循环、乱序播放三种模式
|
|
11
13
|
- 实时 7 段频谱可视化(解码音频包络驱动)
|
|
12
14
|
- 播放列表面板可自由拖动,位置跨刷新记忆
|
|
@@ -17,10 +19,10 @@ DeepSeek Harness 本地音乐库播放器插件(bundle)。
|
|
|
17
19
|
|
|
18
20
|

|
|
19
21
|
|
|
20
|
-

|
|
21
|
-
|
|
22
22
|

|
|
23
23
|
|
|
24
|
+

|
|
25
|
+
|
|
24
26
|
## 安装
|
|
25
27
|
|
|
26
28
|
需要已安装 `dsh` CLI。
|
package/lib/client.js
CHANGED
|
@@ -739,6 +739,7 @@ window.__ModuleLoader__.load({
|
|
|
739
739
|
const [dirs, setDirs] = useState([]);
|
|
740
740
|
const [curPath, setCurPath] = useState('');
|
|
741
741
|
const [curName, setCurName] = useState('');
|
|
742
|
+
const [curUp, setCurUp] = useState(null);
|
|
742
743
|
const [dirError, setDirError] = useState(null);
|
|
743
744
|
return React.createElement('div', { className: 'dsh-music-settings' },
|
|
744
745
|
React.createElement('div', { className: 'dsh-music-settings-row' },
|
|
@@ -786,20 +787,30 @@ window.__ModuleLoader__.load({
|
|
|
786
787
|
if (data && data.error) { setDirError(data.error); return; }
|
|
787
788
|
setCurPath(data.path || '');
|
|
788
789
|
setCurName(data.name || '');
|
|
790
|
+
setCurUp(data.up || null);
|
|
789
791
|
setDirs(data.dirs || []);
|
|
790
792
|
} catch (err) {
|
|
791
793
|
setDirError('读取目录失败:' + String((err && err.message) || err));
|
|
792
794
|
}
|
|
793
795
|
}
|
|
794
796
|
function goUp() {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
797
|
+
// Prefer the parent path computed by the host (correct separators per OS).
|
|
798
|
+
// At a drive root the host reports the "__drives__" sentinel, so "up"
|
|
799
|
+
// jumps to the drive list and lets the user switch disks.
|
|
800
|
+
if (curUp === '__drives__') { browse('__drives__'); return; }
|
|
801
|
+
if (curUp !== null && curUp !== undefined && curUp !== '') { browse(curUp); return; }
|
|
802
|
+
// fallback: derive the parent locally when the host omitted `up`.
|
|
803
|
+
// Handle both "\" and "/" so Windows paths never dead-end (the old
|
|
804
|
+
// POSIX-only parse did nothing on backslash paths like C:\Users\x).
|
|
805
|
+
if (curPath === '' || curPath === '/' || /^[A-Za-z]:[\\/]?$/.test(curPath)) return;
|
|
806
|
+
const idx = Math.max(curPath.lastIndexOf('/'), curPath.lastIndexOf('\\'));
|
|
807
|
+
if (idx <= 0) return;
|
|
808
|
+
browse(curPath.slice(0, idx));
|
|
799
809
|
}
|
|
800
810
|
function pickCurrent() {
|
|
801
811
|
const p = curPath;
|
|
802
|
-
|
|
812
|
+
// The drive-list view ("__drives__") is not a real directory.
|
|
813
|
+
if (p === '' || p === '__drives__') return;
|
|
803
814
|
setPickerOpen(false);
|
|
804
815
|
saveRoot(p);
|
|
805
816
|
}
|
package/lib/index.js
CHANGED
|
@@ -28,8 +28,9 @@ function audioType(name) {
|
|
|
28
28
|
return i > 0 ? (AUDIO_TYPES[name.slice(i + 1).toLowerCase()] || 'application/octet-stream') : 'application/octet-stream'
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
|
|
32
|
-
import { dirname } from 'node:path'
|
|
31
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync } from 'node:fs'
|
|
32
|
+
import { dirname, basename, parse as pathParse, join as pathJoin } from 'node:path'
|
|
33
|
+
import * as os from 'node:os'
|
|
33
34
|
|
|
34
35
|
export const name = 'dsh-music-player'
|
|
35
36
|
export const inject = ['webServer', 'fs', 'shell', 'tools', 'systemPrompt']
|
|
@@ -43,6 +44,14 @@ export function apply(ctx) {
|
|
|
43
44
|
|
|
44
45
|
const getHome = async () => {
|
|
45
46
|
if (home !== null) return home
|
|
47
|
+
try {
|
|
48
|
+
// os.homedir() resolves the user's home cross-platform (Windows uses
|
|
49
|
+
// C:\Users\<name>; POSIX /Users/<name> or /home/<name>). The $HOME shell
|
|
50
|
+
// variable does not exist under cmd/powershell on Windows, so fall back
|
|
51
|
+
// to the shell only when os.homedir() is unusable.
|
|
52
|
+
const osHome = (typeof os !== 'undefined' && os.homedir) ? os.homedir() : ''
|
|
53
|
+
if (osHome !== '') { home = osHome; return home }
|
|
54
|
+
} catch { /* fall through to shell */ }
|
|
46
55
|
try {
|
|
47
56
|
const result = await ctx.shell.run(ctx.shell.resolve({ command: 'printf %s "$HOME"' }))
|
|
48
57
|
const value = String((result.stdout && result.stdout.text) || '').trim()
|
|
@@ -100,21 +109,29 @@ export function apply(ctx) {
|
|
|
100
109
|
const found = []
|
|
101
110
|
const walk = async (dir, depth) => {
|
|
102
111
|
if (depth > 4 || found.length >= 500) return
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
// Tolerant listing (all entries, see listEntries): dsh-fs-local's listDir
|
|
113
|
+
// aborts on the first unreadable child, so scanning a drive root (or any
|
|
114
|
+
// dir with protected entries) would silently yield zero tracks.
|
|
115
|
+
const entries = listEntries(dir)
|
|
105
116
|
for (const entry of entries) {
|
|
106
117
|
if (found.length >= 500) return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
const abs = pathJoin(dir, entry.name)
|
|
119
|
+
try {
|
|
120
|
+
if (entry.isDir) { await walk(abs, depth + 1); continue }
|
|
121
|
+
if (!isAudioName(entry.name)) continue
|
|
122
|
+
const st = statSync(abs)
|
|
123
|
+
if (!st.isFile()) continue
|
|
124
|
+
const rel = abs.startsWith(rootStr) ? abs.slice(rootStr.length + 1) : entry.name
|
|
125
|
+
found.push({
|
|
126
|
+
name: rel, path: abs, size: st.size || 0,
|
|
127
|
+
ext: entry.name.slice(entry.name.lastIndexOf('.') + 1).toLowerCase(),
|
|
128
|
+
})
|
|
129
|
+
} catch {
|
|
130
|
+
// unreadable entry: skip it, keep walking the rest
|
|
131
|
+
}
|
|
115
132
|
}
|
|
116
133
|
}
|
|
117
|
-
await walk(
|
|
134
|
+
await walk(rootStr, 0)
|
|
118
135
|
found.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
119
136
|
return { rootPath: rootStr, found }
|
|
120
137
|
}
|
|
@@ -129,7 +146,9 @@ export function apply(ctx) {
|
|
|
129
146
|
}
|
|
130
147
|
const init = async () => {
|
|
131
148
|
const h = await getHome()
|
|
132
|
-
|
|
149
|
+
// Use path.join so the default root uses the platform separator; on Windows
|
|
150
|
+
// a bare h + '/Music' produced a mixed "C:\Users\x/Music" root.
|
|
151
|
+
let root = h === null ? null : pathJoin(h, 'Music')
|
|
133
152
|
// Restore the user's last chosen directory; validate it so a deleted or
|
|
134
153
|
// renamed directory falls back to the default instead of erroring.
|
|
135
154
|
const stored = await loadStoredRoot()
|
|
@@ -153,6 +172,29 @@ export function apply(ctx) {
|
|
|
153
172
|
}
|
|
154
173
|
const ensureStarted = () => { if (startupPromise === null) startupPromise = init(); return startupPromise }
|
|
155
174
|
|
|
175
|
+
// Tolerant directory listing for the picker and the scan. dsh-fs-local's
|
|
176
|
+
// listDir is all-or-nothing: one unreadable child (pagefile.sys, System
|
|
177
|
+
// Volume Information, ...) aborts the entire listing, which made drive roots
|
|
178
|
+
// (and any dir containing protected entries) show up empty. Enumerate with
|
|
179
|
+
// node:fs instead, skip entries that cannot be stat'd, and report every
|
|
180
|
+
// entry with an isDir flag so callers can filter (picker: dirs only;
|
|
181
|
+
// scan: dirs to recurse + audio files to collect).
|
|
182
|
+
const listEntries = (dirPath) => {
|
|
183
|
+
let dirents = []
|
|
184
|
+
try { dirents = readdirSync(dirPath, { withFileTypes: true, encoding: 'utf8' }) } catch { return [] }
|
|
185
|
+
const out = []
|
|
186
|
+
for (const ent of dirents) {
|
|
187
|
+
try {
|
|
188
|
+
const isDir = ent.isDirectory() || (ent.isSymbolicLink() && statSync(pathJoin(dirPath, ent.name)).isDirectory())
|
|
189
|
+
out.push({ name: ent.name, isDir })
|
|
190
|
+
} catch {
|
|
191
|
+
// unreadable entry (EPERM/EBUSY/...): skip it, keep listing the rest
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
out.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
195
|
+
return out
|
|
196
|
+
}
|
|
197
|
+
|
|
156
198
|
// ---- shared HTTP helpers ----
|
|
157
199
|
const writeJson = (res, value, status) => {
|
|
158
200
|
res.writeHead(status || 200, { 'content-type': 'application/json; charset=utf-8' })
|
|
@@ -203,6 +245,24 @@ export function apply(ctx) {
|
|
|
203
245
|
await ensureStarted()
|
|
204
246
|
const raw = url.searchParams.get('path') || ''
|
|
205
247
|
try {
|
|
248
|
+
// Windows has no single root that lists every drive, so expose a
|
|
249
|
+
// sentinel ("__drives__") that enumerates the available drive roots.
|
|
250
|
+
// Browsing "up" from a drive root (e.g. C:\) lands here so users can
|
|
251
|
+
// switch to another drive.
|
|
252
|
+
if (raw === '__drives__') {
|
|
253
|
+
const isWin = typeof process !== 'undefined' && process.platform === 'win32'
|
|
254
|
+
if (isWin) {
|
|
255
|
+
const roots = []
|
|
256
|
+
for (const letter of 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
|
|
257
|
+
const root = letter + ':\\'
|
|
258
|
+
try { if (existsSync(root)) roots.push({ name: root, path: root }) } catch {}
|
|
259
|
+
}
|
|
260
|
+
writeJson(res, { path: '__drives__', name: '\u672c\u673a\u78c1\u76d8', up: null, dirs: roots })
|
|
261
|
+
} else {
|
|
262
|
+
writeJson(res, { path: '/', name: '/', up: null, dirs: [] })
|
|
263
|
+
}
|
|
264
|
+
return
|
|
265
|
+
}
|
|
206
266
|
const base = raw === '' ? ((await getHome()) || '/') : raw
|
|
207
267
|
const expanded = base.startsWith('~/') ? ((await getHome()) || '') + '/' + base.slice(2) : base
|
|
208
268
|
const target = await ctx.fs.resolve(expanded)
|
|
@@ -212,13 +272,22 @@ export function apply(ctx) {
|
|
|
212
272
|
return
|
|
213
273
|
}
|
|
214
274
|
const abs = ctx.fs.processPath(target)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
275
|
+
// Parent / name computation must use the host filesystem's separators
|
|
276
|
+
// (Windows uses "\" and drive roots like C:\, POSIX uses "/"), so do it
|
|
277
|
+
// with node:path rather than guessing a separator in the browser.
|
|
278
|
+
const atRoot = pathParse(abs).dir === abs
|
|
279
|
+
// On Windows, "up" from a drive root goes to the drive-list sentinel so
|
|
280
|
+
// users can switch drives; at the POSIX root there is nowhere to go.
|
|
281
|
+
const up = atRoot
|
|
282
|
+
? (process.platform === 'win32' ? '__drives__' : null)
|
|
283
|
+
: dirname(abs)
|
|
284
|
+
// Tolerant listing (see listEntries): skip unreadable entries so
|
|
285
|
+
// drive roots like C:\ still show their normal folders instead of an
|
|
286
|
+
// empty list. Only directories are offered by the picker.
|
|
287
|
+
const dirs = listEntries(abs)
|
|
288
|
+
.filter((e) => e.isDir)
|
|
289
|
+
.map((e) => ({ name: e.name, path: pathJoin(abs, e.name) }))
|
|
290
|
+
writeJson(res, { path: abs, name: basename(abs) || abs, up, dirs })
|
|
222
291
|
} catch (err) {
|
|
223
292
|
writeJson(res, { error: String((err && err.message) || err) }, 500)
|
|
224
293
|
}
|