@chenhao6682108/dsh-skill-musicbee 0.1.2 → 0.1.4

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 CHANGED
@@ -64,9 +64,11 @@ it feeds (`playlists_dir`, `library_root`, `python` → `MUSICBEE_PY`).
64
64
  Then copy `references/party-2026-11-20-final.json`, change only the path fields and `library_root`,
65
65
  and keep the rule fields (`req`, `ending`, `body`, `share`, `long_sec`, `no_repeat_style`,
66
66
  `ballroom_gap_max`) as they are. `party_build.py -h` lists every accepted field, and each failure
67
- message names the exact next command to run. `party_build.py` also **refuses to write a playlist**
68
- until `mb-doctor.cmd -Accept` has recorded the confirmed paths in `~/.musicbee-skill/paths.json`,
69
- and it rejects a config whose `playlists_dir` / `library_root` disagree with that record.
67
+ message names the exact next command to run. `playlists_dir` and `prefix_mbp` are **optional in the
68
+ config**: `party_build.py` reads MusicBee's own `Playlists` folder from `<ENV_LibPath>` and picks a
69
+ same-library `.mbp` for the 52-byte header, so only `library_root` (the folder whose subfolders are the
70
+ style names) has to be written by hand. A same-name `.mbp` (or `.md`) is **overwritten in place** —
71
+ the run prints a line first — so keep a copy of `Playlists` if you want to keep old versions.
70
72
 
71
73
  ## How it works
72
74
 
package/README.zh.md CHANGED
@@ -57,8 +57,9 @@ scripts\mb-doctor.cmd -Json :: 给程序读的 JSON
57
57
  然后把 `references/party-2026-11-20-final.json` 复制一份,只改路径字段和 `library_root`,
58
58
  规则字段(`req`、`ending`、`body`、`share`、`long_sec`、`no_repeat_style`、`ballroom_gap_max`)原样保留。
59
59
  `party_build.py -h` 会列出所有可用字段;每条报错都会写清楚下一步该跑什么命令。
60
- 另外,**路径未确认前 `party_build.py` 拒绝写歌单**——`mb-doctor.cmd -Accept` 会把确认结果记到 `~/.musicbee-skill/paths.json`,
61
- 配置里的 `playlists_dir` / `library_root` 与记录不一致时同样拒绝,并打印两个值。
60
+ `playlists_dir` 和 `prefix_mbp` 现在可以**整个省略**:`party_build.py` 从 `<ENV_LibPath>` 读到 MusicBee 的
61
+ `Playlists` 目录,并自动挑一个同库 `.mbp` 取 52 字节文件头——手写只剩 `library_root`(风格子目录的父目录)。同名 `.mbp`(或 `.md`)会被**直接覆盖**(运行时先打印一行提示),
62
+ 想保留旧版本就先备份 `Playlists`。
62
63
 
63
64
  ## 实现方式
64
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenhao6682108/dsh-skill-musicbee",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "MusicBee playlist and library toolkit as a DSH skill plugin: scan a music library into a JSON index, write ID3/Vorbis/MP4 tags, build validated dsh (3dj) party playlists, rewrite and remap .mbp playlist files, and make MusicBee re-read them. Ships mb-doctor to auto-detect the MusicBee library, Playlists folder and Python. Windows and a local MusicBee install required; no network access and no audio data is modified.",
5
5
  "keywords": [
6
6
  "deepseek",
@@ -51,45 +51,28 @@ CLI 入口:`scripts\mb-tools.cmd`(内部 `python -X utf8 -m mb_tools`;命
51
51
 
52
52
  ---
53
53
 
54
- ## 零、首次使用(先跑这条,别猜路径)
54
+ ## 零、路径从哪来(默认自动,不用手填)
55
55
 
56
- 本技能要三样本机信息:MusicBee 的 `Playlists` 目录、曲库根目录(**风格子目录的父目录**)、一个装有 `mutagen` 的 Python。
57
- **不要手猜路径**,先自检——它从 `%APPDATA%\MusicBee\MusicBee3Settings.ini` 的 `<ENV_LibPath>` 自动解析:
56
+ 只有三样本机信息相关,其中**两样已经自动**:
58
57
 
59
- ```bat
60
- scripts\mb-doctor.cmd :: 人读的清单
61
- scripts\mb-doctor.cmd -StyleRoot "D:\你的曲库\1blues" :: 同时列出风格子目录名
62
- scripts\mb-doctor.cmd -Json :: 给程序读的 JSON
63
- ```
64
-
65
- | 输出项 | 含义 | 填到配置的哪 |
66
- |---|---|---|
67
- | `MusicBeeLibrary` | MusicBee 库目录 | (用来推导 `Playlists`) |
68
- | `PlaylistsDir` | `.mbp` 所在目录,须已存在 | `playlists_dir` |
69
- | `PlaylistGroups` | 已有分组(如 `1blues`、`3dj`) | 决定 `prefix_mbp` 和 `out_mbp` |
70
- | `StyleRoot` / `StyleSubfolders` | 风格子目录的父目录及其子目录名 | `library_root` 与 `styles` |
71
- | `Python` | 可用解释器路径 | 设环境变量 `MUSICBEE_PY`,或直接用它 |
72
-
73
- 三项齐了再改配置:复制 `references/party-2026-11-20-final.json` 一份,**只改路径字段和 `library_root`**,
74
- `req` / `ending` / `body` / `share` / `long_sec` / `no_repeat_style` / `ballroom_gap_max` 这些规则原样保留。
58
+ | 信息 | 现在怎么来 |
59
+ |---|---|
60
+ | `playlists_dir` | **自动**:`party_build.py` 直接读 `%APPDATA%\MusicBee\MusicBee3Settings.ini` 的 `<ENV_LibPath>`,得到 `<库>\Playlists` |
61
+ | `prefix_mbp` | **自动**:从上面那个 `Playlists` 目录里挑任意一个同库 `.mbp` 取 52 字节文件头 |
62
+ | `library_root` | 仍然要写一句:它是**风格子目录的父目录**(如 `C:\音乐分类\1blues`),机器猜不出你的分类习惯 |
75
63
 
76
- > ⚠️ **动手前必须让用户确认路径**。`mb-doctor` 探测到的是机器侧事实,但下面两件事只有用户知道:
77
- > ① `library_root` 的**层级**对不对(是 `…\1blues` 还是它的上一层/下一层,决定风格池能不能命中);
78
- > ② `playlists_dir` 是不是**用户想写入的那个库**(一台机器可能有多个 MusicBee 库/多份 Playlists)。
79
- >
80
- > 所以:先把 `mb-doctor` 的 `MusicBeeLibrary` / `PlaylistsDir` / `StyleRoot` / `StyleSubfolders` 贴给用户确认,
81
- > **得到「对」的答复后**再读索引、再跑 `party_build.py`、再写 `.mbp`。写歌单会直接改变 MusicBee 面板里的内容,
82
- > 宁可多问一句,也不要按探测结果直接落盘。
64
+ 所以配置里 `playlists_dir` 和 `prefix_mbp` **可以整个省略**;`out_mbp` 写相对路径时按 `Playlists` 目录解析(如 `3dj\2026-11-27 blues舞会6.mbp`)。
83
65
 
84
- **确认是硬门槛,不是靠自觉**:`party_build.py` 会读 `~/.musicbee-skill/paths.json`,**没有这个文件就拒绝写歌单**,并提示跑:
66
+ 想先看清本机状态(可选):
85
67
 
86
68
  ```bat
87
- scripts\mb-doctor.cmd -StyleRoot "D:\你的曲库\1blues" -Accept
69
+ scripts\mb-doctor.cmd :: MusicBee 库 / Playlists / 分组 / Python
70
+ scripts\mb-doctor.cmd -StyleRoot "D:\你的曲库\1blues" :: 顺便列出风格子目录名(写 styles 用)
71
+ scripts\mb-doctor.cmd -Json :: 给程序读的 JSON
88
72
  ```
89
73
 
90
- 它会再次列出探测结果,你输入 `y` 后把路径记下来(含时间戳与风格子目录列表)。之后配置里的
91
- `playlists_dir` / `library_root` 必须与记录一致,**不一致同样拒绝**并同时打印两个值,让你选。
92
- 换库或路径变了就重跑一次 `-Accept`。确实要跳过这道门:设环境变量 `MUSICBEE_SKIP_CONFIRM=1`。
74
+ 复制 `references/party-2026-11-20-final.json` 一份,改 `library_root`、`out_mbp`、`name` 即可;
75
+ `req` / `ending` / `body` / `share` / `long_sec` / `no_repeat_style` / `ballroom_gap_max` 这些规则原样保留。
93
76
 
94
77
  ### 报错 → 该做什么
95
78
 
@@ -97,8 +80,9 @@ scripts\mb-doctor.cmd -StyleRoot "D:\你的曲库\1blues" -Accept
97
80
  |---|---|
98
81
  | `配置缺少字段:library_root…` | 填「风格子目录的父目录」;用 `mb-doctor.cmd -StyleRoot <目录>` 确认 |
99
82
  | `索引文件不存在:…` | 先 `mb-tools.cmd scan --dir <曲库根> --out <那个 index 路径>` |
100
- | `playlists_dir 不存在:…` | 跑 `mb-doctor.cmd` 看探测结果;MusicBee 至少启动过一次才会写 settings ini |
101
- | `取不到 52 字节文件头…` | `prefix_mbp` 要指向 `<playlists_dir>` 下任意同库 `.mbp`(如 `1blues/ballroomin.mbp`) |
83
+ | `找不到 MusicBee 的 Playlists 目录…` | MusicBee 至少启动过一次才会写 settings ini;或在配置里显式写 `playlists_dir` |
84
+ | `playlists_dir 不存在:…` | 同上;或改正配置里的 `playlists_dir` |
85
+ | `Playlists 目录下没有任何 .mbp…` | 先在 MusicBee 里建一个歌单,或在配置里显式写 `prefix_mbp` |
102
86
  | `曲目无法唯一定位:…` | `set` 里的标题必须与索引完全一致;`scan` 后曲库改过要重扫 |
103
87
  | `风格池不存在于索引:…` | `library_root` 指错了层级(少了/多了 `1blues` 这层),或 `styles` 名与子目录名不符 |
104
88
 
@@ -377,7 +361,7 @@ scripts\restart-musicbee.cmd
377
361
  | 字段 | 说明 |
378
362
  |---|---|
379
363
  | `index` / `library_root` | 索引 JSON 与 1blues 根目录(按子目录判风格) |
380
- | `playlists_dir` / `prefix_mbp` / `out_mbp` | Playlists 根、52 字节头来源、输出 .mbp |
364
+ | `playlists_dir` / `prefix_mbp` / `out_mbp` | Playlists 根(**可省略,自动从 MusicBee 设置取**)、52 字节头来源(**可省略,自动挑同库 .mbp**)、输出 .mbp(相对路径按 Playlists 解析);**同名 `.mbp` 会被直接覆盖**,运行时会先打印一行提示 |
381
365
  | `name` / `start` | 歌单名(= 文件名)、开始时间 `"22:30"` |
382
366
  | `styles` / `req` / `body` | 可能用到的风格池、固定配额(风格→首数)、其余曲目允许的风格 |
383
367
  | `set` | 播放顺序曲目表,每行 `[风格, 艺人片段, 标题, 能量H/M/L, 理由, 段落]`;标题须与索引一致 |
@@ -3,8 +3,7 @@
3
3
  # so keep this file ASCII or the parser breaks. Chinese explanations live in SKILL.md.
4
4
  param(
5
5
  [string]$StyleRoot = "",
6
- [switch]$Json,
7
- [switch]$Accept
6
+ [switch]$Json
8
7
  )
9
8
 
10
9
  $ErrorActionPreference = "Stop"
@@ -113,39 +112,7 @@ if (-not $py) { Write-Host " python : set MUSICBEE_PY=%LOCALAP
113
112
  if (-not $exe) { Write-Host " MusicBee.exe : install MusicBee, or pass -MusicBeeExe to restart-musicbee.cmd" }
114
113
  if ($hasPlaylists -and $styleOk -and $py -and $exe) { Write-Host " everything needed was found. Next: fill a party config and run party_build.py <config.json>" }
115
114
  Write-Host ""
116
- Write-Host "IMPORTANT: show these paths to the user and get an explicit yes before writing any config or .mbp."
117
- Write-Host " A machine can hold several MusicBee libraries, and library_root must name the folder that"
118
- Write-Host " directly contains the style subfolders - only the user can confirm both."
119
-
120
- if ($Accept) {
121
- if (-not $hasPlaylists) {
122
- Write-Host ""
123
- Write-Host "cannot record: PlaylistsDir is unknown. Start MusicBee once so it writes its settings ini."
124
- exit 1
125
- }
126
- Write-Host ""
127
- Write-Host "-- record confirmed paths --"
128
- Write-Host (" playlists_dir : " + $playlists)
129
- Write-Host (" library_root : " + $(if ($styleOk) { $StyleRoot } else { "(not given; pass -StyleRoot to record it)" }))
130
- $ans = Read-Host "Are these the paths this machine should write to? type y to record"
131
- if ($ans -notin @("y", "Y", "yes", "YES")) { Write-Host "not recorded."; exit 1 }
132
- $dir = Join-Path $env:USERPROFILE ".musicbee-skill"
133
- New-Item -ItemType Directory -Force -Path $dir | Out-Null
134
- $record = [ordered]@{
135
- confirmedAt = (Get-Date).ToString("s")
136
- musicBeeExe = $exe
137
- musicBeeLibrary = $lib
138
- playlistsDir = $playlists
139
- libraryRoot = $StyleRoot
140
- styleSubfolders = $styleSub
141
- python = $py
142
- pythonVersion = $pyVer
143
- }
144
- $file = Join-Path $dir "paths.json"
145
- $record | ConvertTo-Json -Depth 4 | Set-Content -Path $file -Encoding UTF8
146
- Write-Host ("recorded -> " + $file)
147
- Write-Host "party_build.py now accepts configs whose playlists_dir/library_root match this record."
148
- exit 0
149
- }
115
+ Write-Host "IMPORTANT: playlists_dir and prefix_mbp are detected automatically by party_build.py, so the"
116
+ Write-Host " only path you still must supply is library_root (the folder whose subfolders are the styles)."
150
117
 
151
118
  if ($hasPlaylists -and $py) { exit 0 } else { exit 1 }
@@ -45,6 +45,7 @@
45
45
  """
46
46
  import json
47
47
  import os
48
+ import re
48
49
  import struct
49
50
  import sys
50
51
 
@@ -177,53 +178,70 @@ def mmss(t):
177
178
 
178
179
 
179
180
  # ---------------------------------------------------------------- 校验
180
- # ------------------------------------------------------------ 路径确认
181
- CONFIRM_FILE = os.path.join(os.path.expanduser("~"), ".musicbee-skill", "paths.json")
182
-
183
-
184
- def load_confirmed_paths():
185
- """The paths the user confirmed with `mb-doctor.cmd -Accept`, or None."""
186
- if not os.path.exists(CONFIRM_FILE):
187
- return None
181
+ # ------------------------------------------------------------ 默认路径
182
+ def default_playlists_dir():
183
+ """MusicBee 的 Playlists 目录:从 settings ini 的 <ENV_LibPath> 推导,取不到返回 ""。"""
184
+ ini = os.path.join(os.environ.get("APPDATA", ""), "MusicBee", "MusicBee3Settings.ini")
188
185
  try:
189
- with open(CONFIRM_FILE, encoding="utf-8-sig") as f:
190
- return json.load(f)
191
- except Exception:
192
- return None
193
-
194
-
195
- def same_path(a, b):
196
- return os.path.normcase(os.path.normpath(a)) == os.path.normcase(os.path.normpath(b))
197
-
198
-
199
- def require_confirmed_paths(cfg):
200
- """First-run gate: nothing is written until the user confirmed the machine's paths."""
201
- if os.environ.get("MUSICBEE_SKIP_CONFIRM"):
202
- return
203
- confirmed = load_confirmed_paths()
204
- if confirmed is None:
205
- die("首次使用:先确认路径,确认前不会写任何歌单文件。\n"
206
- " 跑这条:scripts\\mb-doctor.cmd -StyleRoot <曲库根> -Accept\n"
207
- " 它会列出探测到的 MusicBee 库 / Playlists / 风格目录,输入 y 后记录到\n"
208
- " " + CONFIRM_FILE + "\n"
209
- " (确实不想确认:设环境变量 MUSICBEE_SKIP_CONFIRM=1)")
210
- for cfg_key, rec_key in (("playlists_dir", "playlistsDir"), ("library_root", "libraryRoot")):
211
- got = cfg.get(cfg_key) or ""
212
- want = confirmed.get(rec_key) or ""
213
- if got and want and not same_path(got, want):
214
- die("配置里的 " + cfg_key + " 与已确认的路径不一致:\n"
215
- " 已确认:" + want + "\n"
216
- " 配置里:" + got + "\n"
217
- " 哪个才对就留哪个:改配置,或重跑 scripts\\mb-doctor.cmd -Accept 更新记录。")
186
+ with open(ini, encoding="utf-8-sig", errors="ignore") as f:
187
+ txt = f.read()
188
+ except OSError:
189
+ return ""
190
+ m = re.search(r"<ENV_LibPath>([^<]*)</ENV_LibPath>", txt)
191
+ if not m:
192
+ return ""
193
+ lib = m.group(1).strip()
194
+ return os.path.join(lib, "Playlists") if lib else ""
195
+
196
+
197
+ def auto_prefix_mbp(playlists_dir):
198
+ """同库任意一个 .mbp 都能提供那 52 字节文件头;按路径排序取第一个可读的。"""
199
+ found = []
200
+ for dirpath, _dirs, files in os.walk(playlists_dir):
201
+ for name in files:
202
+ if name.lower().endswith(".mbp"):
203
+ found.append(os.path.join(dirpath, name))
204
+ for p in sorted(found):
205
+ try:
206
+ if os.path.getsize(p) >= 56:
207
+ return p
208
+ except OSError:
209
+ continue
210
+ return ""
218
211
 
219
212
 
213
+ # ---------------------------------------------------------------- 校验
220
214
  def run(cfg):
221
- need = ["index", "playlists_dir", "out_mbp", "prefix_mbp", "name", "styles", "req", "body", "set"]
215
+ need = ["index", "out_mbp", "name", "styles", "req", "body", "set"]
222
216
  missing = [k for k in need if k not in cfg]
223
217
  if missing:
224
218
  die("配置缺少字段:" + "、".join(missing) +
225
219
  "\n 必填:" + " / ".join(need) +
226
- "\n 不知道路径填什么?先跑 scripts\\mb-doctor.cmd 看本机探测结果。")
220
+ "\n playlists_dir / prefix_mbp 可以省略:默认从 MusicBee 设置里自动取。")
221
+
222
+ # playlists_dir:配置没写就用 MusicBee 自己的 Playlists 目录
223
+ playlists_dir = cfg.get("playlists_dir") or default_playlists_dir()
224
+ if not playlists_dir:
225
+ die("找不到 MusicBee 的 Playlists 目录(settings ini 里没有 <ENV_LibPath>)。\n"
226
+ " 先启动一次 MusicBee,或在配置里显式写 playlists_dir。")
227
+ if not os.path.isdir(playlists_dir):
228
+ die("playlists_dir 不存在:" + playlists_dir +
229
+ "\n 先启动一次 MusicBee 让它写出库路径,或在配置里改正 playlists_dir。")
230
+ cfg["playlists_dir"] = playlists_dir
231
+ print("playlists_dir = " + playlists_dir)
232
+
233
+ # prefix_mbp:没写就从 Playlists 目录里自动挑一个同库 .mbp 取 52 字节头
234
+ if not cfg.get("prefix_mbp"):
235
+ prefix = auto_prefix_mbp(playlists_dir)
236
+ if not prefix:
237
+ die("Playlists 目录下没有任何 .mbp,取不到 52 字节文件头。\n"
238
+ " 先在 MusicBee 里建一个歌单,或在配置里显式写 prefix_mbp。")
239
+ cfg["prefix_mbp"] = prefix
240
+ print("prefix_mbp = " + prefix + " (auto)")
241
+
242
+ # out_mbp 写成相对路径时,按 Playlists 目录解析
243
+ if not os.path.isabs(cfg["out_mbp"]):
244
+ cfg["out_mbp"] = os.path.join(playlists_dir, cfg["out_mbp"])
227
245
 
228
246
  library_root = cfg.get("library_root")
229
247
  if not library_root:
@@ -231,11 +249,6 @@ def run(cfg):
231
249
  "\n 先跑 scripts\\mb-doctor.cmd -StyleRoot <那个目录> 确认风格子目录名")
232
250
  if not os.path.isdir(library_root):
233
251
  die("library_root 不是有效目录:" + library_root)
234
- if not os.path.isdir(cfg["playlists_dir"]):
235
- die("playlists_dir 不存在:" + cfg["playlists_dir"] +
236
- "\n 先跑 scripts\\mb-doctor.cmd 查看探测到的 Playlists 目录")
237
-
238
- require_confirmed_paths(cfg)
239
252
 
240
253
  index_path = cfg["index"]
241
254
  if not os.path.exists(index_path):
@@ -409,18 +422,22 @@ def run(cfg):
409
422
  print("排除曲目: " + ("无" if not excl_details else
410
423
  " + ".join(f"{os.path.basename(f)} {c} 首" for f, c in excl_details)))
411
424
 
412
- # 写 .mbp
425
+ # 写 .mbp(同名文件直接覆盖,但打印提示,不静默)
413
426
  prefix = cfg["prefix_mbp"]
414
427
  if not os.path.isabs(prefix):
415
428
  prefix = os.path.join(cfg["playlists_dir"], prefix)
416
429
  if not os.path.exists(prefix):
417
430
  die("取不到 52 字节文件头,来源 .mbp 不存在:" + prefix +
418
431
  "\n prefix_mbp 要指向 <playlists_dir> 下任意一个同库 .mbp(例如 \"1blues/ballroomin.mbp\")")
432
+ if os.path.exists(cfg["out_mbp"]):
433
+ print("目标歌单已存在,覆盖:" + cfg["out_mbp"])
419
434
  size = write_mbp(prefix, cfg["out_mbp"], paths)
420
435
  print(f"wrote {cfg['out_mbp']} {size} bytes round-trip OK")
421
436
 
422
- # 写分享说明
437
+ # 写分享说明(同样覆盖同名文件)
423
438
  if cfg.get("out_md"):
439
+ if os.path.exists(cfg["out_md"]):
440
+ print("说明文件已存在,覆盖:" + cfg["out_md"])
424
441
  write_md(cfg, stats)
425
442
  print("wrote " + cfg["out_md"])
426
443