@chenhao6682108/dsh-skill-musicbee 0.1.1 → 0.1.2

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,7 +64,9 @@ 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.
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.
68
70
 
69
71
  ## How it works
70
72
 
package/README.zh.md CHANGED
@@ -57,6 +57,8 @@ 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
62
 
61
63
  ## 实现方式
62
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenhao6682108/dsh-skill-musicbee",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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",
@@ -73,6 +73,24 @@ scripts\mb-doctor.cmd -Json :: 给程序读的 JSON
73
73
  三项齐了再改配置:复制 `references/party-2026-11-20-final.json` 一份,**只改路径字段和 `library_root`**,
74
74
  `req` / `ending` / `body` / `share` / `long_sec` / `no_repeat_style` / `ballroom_gap_max` 这些规则原样保留。
75
75
 
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
+ > 宁可多问一句,也不要按探测结果直接落盘。
83
+
84
+ **确认是硬门槛,不是靠自觉**:`party_build.py` 会读 `~/.musicbee-skill/paths.json`,**没有这个文件就拒绝写歌单**,并提示跑:
85
+
86
+ ```bat
87
+ scripts\mb-doctor.cmd -StyleRoot "D:\你的曲库\1blues" -Accept
88
+ ```
89
+
90
+ 它会再次列出探测结果,你输入 `y` 后把路径记下来(含时间戳与风格子目录列表)。之后配置里的
91
+ `playlists_dir` / `library_root` 必须与记录一致,**不一致同样拒绝**并同时打印两个值,让你选。
92
+ 换库或路径变了就重跑一次 `-Accept`。确实要跳过这道门:设环境变量 `MUSICBEE_SKIP_CONFIRM=1`。
93
+
76
94
  ### 报错 → 该做什么
77
95
 
78
96
  | 报错 | 修法 |
@@ -3,7 +3,8 @@
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
6
+ [switch]$Json,
7
+ [switch]$Accept
7
8
  )
8
9
 
9
10
  $ErrorActionPreference = "Stop"
@@ -111,5 +112,40 @@ if (-not $styleOk) { Write-Host " library_root : pass -StyleRoot to see i
111
112
  if (-not $py) { Write-Host " python : set MUSICBEE_PY=%LOCALAPPDATA%\Programs\Python\...\python.exe, or run scripts\bootstrap.ps1" }
112
113
  if (-not $exe) { Write-Host " MusicBee.exe : install MusicBee, or pass -MusicBeeExe to restart-musicbee.cmd" }
113
114
  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
+ 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
+ }
114
150
 
115
151
  if ($hasPlaylists -and $py) { exit 0 } else { exit 1 }
@@ -177,6 +177,46 @@ def mmss(t):
177
177
 
178
178
 
179
179
  # ---------------------------------------------------------------- 校验
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
188
+ 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 更新记录。")
218
+
219
+
180
220
  def run(cfg):
181
221
  need = ["index", "playlists_dir", "out_mbp", "prefix_mbp", "name", "styles", "req", "body", "set"]
182
222
  missing = [k for k in need if k not in cfg]
@@ -185,23 +225,26 @@ def run(cfg):
185
225
  "\n 必填:" + " / ".join(need) +
186
226
  "\n 不知道路径填什么?先跑 scripts\\mb-doctor.cmd 看本机探测结果。")
187
227
 
228
+ library_root = cfg.get("library_root")
229
+ if not library_root:
230
+ die("配置缺少字段:library_root(风格子目录的父目录,例如 ...\\1blues)" +
231
+ "\n 先跑 scripts\\mb-doctor.cmd -StyleRoot <那个目录> 确认风格子目录名")
232
+ if not os.path.isdir(library_root):
233
+ 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
+
188
240
  index_path = cfg["index"]
189
241
  if not os.path.exists(index_path):
190
242
  die("索引文件不存在:" + index_path +
191
243
  "\n 它是 mb-tools scan 的产物,先生成:mb-tools.cmd scan --dir <曲库根> --out " + index_path)
192
- if not os.path.isdir(cfg["playlists_dir"]):
193
- die("playlists_dir 不存在:" + cfg["playlists_dir"] +
194
- "\n 先跑 scripts\\mb-doctor.cmd 查看探测到的 Playlists 目录")
195
244
 
196
245
  tracks = json.load(open(index_path, encoding="utf-8"))
197
246
  if isinstance(tracks, dict):
198
247
  tracks = tracks.get("tracks") or tracks.get("items") or []
199
- library_root = cfg.get("library_root")
200
- if not library_root:
201
- die("配置缺少字段:library_root(风格子目录的父目录,例如 ...\\1blues)" +
202
- "\n 先跑 scripts\\mb-doctor.cmd -StyleRoot <那个目录> 确认风格子目录名")
203
- if not os.path.isdir(library_root):
204
- die("library_root 不是有效目录:" + library_root)
205
248
  pools = load_pools(tracks, library_root)
206
249
  for st in cfg["styles"]:
207
250
  if st not in pools: