@chenhao6682108/dsh-skill-netease-playlist 0.1.1 → 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 CHANGED
@@ -77,6 +77,25 @@ skills/netease-playlist/
77
77
  extract-key.ps1 + Dpapi.cs (credential extraction)
78
78
  ```
79
79
 
80
+ ## Releasing
81
+
82
+ Publishing is a deliberate step, never automatic: bump the version and run `npm publish` **only after
83
+ the maintainer has confirmed**. Pushing documentation is not a release.
84
+
85
+ After each release, refresh the local WorkBuddy copies. Both helper scripts read this package's
86
+ `package.json`, so the WorkBuddy skill directory, the listing zip and `listing.json` all follow the
87
+ released version without any hand-edited numbers:
88
+
89
+ ```powershell
90
+ node C:\deepseekharness\dsh-plugins\_to_workbuddy.mjs # sync ~/.workbuddy/skills (adds version, rewrites DSH-only wording)
91
+ node C:\deepseekharness\dsh-plugins\_build_wb_packages.mjs # rebuild the listing packages + listing.json
92
+ Compress-Archive -Path "C:\deepseekharness\workbuddy-packages\netease-playlist\*" `
93
+ -DestinationPath "C:\deepseekharness\workbuddy-packages\netease-playlist.zip" -Force
94
+ ```
95
+
96
+ Those two scripts are kept next to the checkouts (`dsh-plugins\` on this machine), documented in
97
+ `WORKBUDDY-PACKAGING.md`; they are local tooling, not part of this package.
98
+
80
99
  ## Canonical repository
81
100
 
82
101
  This repository is the **canonical source** for `@chenhao6682108/dsh-skill-netease-playlist`. Forks
package/README.zh.md CHANGED
@@ -67,6 +67,22 @@ skills/netease-playlist/
67
67
  extract-key.ps1 + Dpapi.cs(凭据提取)
68
68
  ```
69
69
 
70
+ ## 发版与维护
71
+
72
+ **发版不是自动的**:改完代码先本地验证,**等维护者确认后**才改版本号并 `npm publish`;推送文档不算发版。
73
+
74
+ 每次发版后,要同步本机的 WorkBuddy 副本。两个脚本都从本仓库 `package.json` 读版本号,所以
75
+ WorkBuddy 技能目录、上架包 zip、`listing.json` 三处会自动跟着发版号走,不需要手改数字:
76
+
77
+ ```powershell
78
+ node C:\deepseekharness\dsh-plugins\_to_workbuddy.mjs # 同步 ~/.workbuddy/skills(补 version、替换 dsh 说法)
79
+ node C:\deepseekharness\dsh-plugins\_build_wb_packages.mjs # 重建上架包 + listing.json
80
+ Compress-Archive -Path "C:\deepseekharness\workbuddy-packages\netease-playlist\*" `
81
+ -DestinationPath "C:\deepseekharness\workbuddy-packages\netease-playlist.zip" -Force
82
+ ```
83
+
84
+ 这两个脚本放在仓库旁边(本机 `dsh-plugins\` 下),说明见 `WORKBUDDY-PACKAGING.md`;它们属于本地工具,不随包发布。
85
+
70
86
  ## 官方仓库
71
87
 
72
88
  本仓库是 `@chenhao6682108/dsh-skill-netease-playlist` 的**唯一官方源**。任何 fork 或二次分发都与作者无关、
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenhao6682108/dsh-skill-netease-playlist",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "NetEase Cloud Music playlist toolkit as a DSH skill plugin: reuse the local desktop client's login state to search tracks, create and edit playlists, add or reorder tracks, delete playlists, download playlist audio as mp3, and bulk-import MusicBee .mbp playlists into the cloud. Ships ne-ensure to install Node LTS when node:sqlite is unavailable. Windows and a logged-in NetEase Cloud Music client required.",
5
5
  "keywords": [
6
6
  "deepseek",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: netease-playlist
3
- description: 🎧 网易云歌单助手 — 复用本机网易云音乐客户端的登录态(DPAPI 解出 CEF cookie),在网易云上搜索曲目、新建歌单、改名/改简介/改隐私(公开可被收藏 / 私密仅自己可见)、批量加歌按指定顺序、移歌、删歌单、下载歌单歌曲到本地 mp3(320k,断点续传),以及把 MusicBee 的 .mbp 歌单批量搬上云端(解析二进制歌单+读音频标签→自动搜索匹配打分→建歌单按原顺序加歌→复核;本地歌单改过之后可用 --sync 原地清空重建、把云端对齐到最新曲目与顺序)。无需扫码登录,不落盘保存 cookie。| NetEase Cloud Music playlist toolkit — reuses the local desktop client's login state (DPAPI-decrypted CEF cookie) to search tracks, create/rename/describe/private-or-public playlists, reorder, trim, delete playlists, download playlist tracks as local mp3, bulk-import MusicBee .mbp playlists (parse + tag read + fuzzy match + ordered add + verify), and re-sync an imported playlist after the local .mbp changed (in-place rebuild that also fixes order). Windows only: requires the NetEase Cloud Music desktop client installed and logged in as the same Windows user. 仅 Windows;需本机网易云音乐客户端已登录;缺 Node 会自动安装。
3
+ description: 🎧 网易云歌单助手 — 复用本机网易云音乐客户端的已登录状态(仅在本机读取,凭据不落盘、不上传),在网易云上搜索曲目、新建歌单、改名/改简介/改隐私(公开可被收藏 / 私密仅自己可见)、批量加歌按指定顺序、移歌、删歌单、下载歌单歌曲到本地 mp3(320k,断点续传),以及把 MusicBee 的 .mbp 歌单批量搬上云端(解析二进制歌单+读音频标签→自动搜索匹配打分→建歌单按原顺序加歌→复核;本地歌单改过之后可用 --sync 原地清空重建、把云端对齐到最新曲目与顺序)。无需扫码登录,不落盘保存 cookie。| NetEase Cloud Music playlist toolkit — reuses the local desktop client's login state (DPAPI-decrypted CEF cookie) to search tracks, create/rename/describe/private-or-public playlists, reorder, trim, delete playlists, download playlist tracks as local mp3, bulk-import MusicBee .mbp playlists (parse + tag read + fuzzy match + ordered add + verify), and re-sync an imported playlist after the local .mbp changed (in-place rebuild that also fixes order). Windows only: requires the NetEase Cloud Music desktop client installed and logged in as the same Windows user. 仅 Windows;需本机网易云音乐客户端已登录;缺 Node 会自动安装。
4
4
  triggers:
5
5
  - 网易云
6
6
  - 网易云歌单
@@ -34,7 +34,7 @@ triggers:
34
34
 
35
35
  # 🎧 网易云歌单助手
36
36
 
37
- 直接用**本机网易云音乐桌面客户端的登录态**操作云端歌单:不扫码、不要密码、不碰浏览器自动化(浏览器自动化在本机是 `standard` 模式 + 审批禁用,点击/输入会被自动拒绝,所以这条路走不通)。支持曲目搜索、建歌单、改名/改简介/改隐私(公开/私密)、按序批量加歌、移歌、删歌单、下载歌单,以及**把 MusicBee 的 `.mbp` 歌单整组搬上云端**(自动搜索匹配、可按原顺序加歌、可空跑与续跑)。
37
+ 直接用**本机网易云音乐桌面客户端的登录态**操作云端歌单:不扫码、不要密码,也不需要浏览器自动化。支持曲目搜索、建歌单、改名/改简介/改隐私(公开/私密)、按序批量加歌、移歌、删歌单、下载歌单,以及**把 MusicBee 的 `.mbp` 歌单整组搬上云端**(自动搜索匹配、可按原顺序加歌、可空跑与续跑)。
38
38
 
39
39
  CLI 入口:`scripts/ne.cmd`(Windows,内部调用 `node scripts/ne.mjs`,需要 Node ≥ 22.5,用到内置 `node:sqlite`)
40
40
 
@@ -45,13 +45,19 @@ CLI 入口:`scripts/ne.cmd`(Windows,内部调用 `node scripts/ne.mjs`,
45
45
  | # | 条件 | 说明 |
46
46
  |---|---|---|
47
47
  | 1 | **Windows** + **已安装并登录网易云音乐桌面客户端** | 登录态从客户端 CEF 存储读出;DPAPI 只在**同一个 Windows 用户**下能解,所以运行 `dsh` 的用户必须与登录客户端的用户一致 |
48
- | 2 | **Node ≥ 22.5**(CLI 用内置 `node:sqlite` 读 cookie 库) | `ne.cmd` 启动前会跑 `ne-ensure.ps1` 自检:找不到可用 Node 时尝试 `winget install OpenJS.NodeJS.LTS`,成功后自动用它(不依赖刷新 PATH) |
49
- | 3 | 网络可达 `music.163.com` | 所有云端操作都走 weapi/明文接口 |
48
+ | 2 | **Node ≥ 22.5**(CLI 用内置 `node:sqlite` 读取本机登录态) | `ne.cmd` 启动前会跑 `ne-ensure.ps1` 自检:找不到可用 Node 时尝试 `winget install OpenJS.NodeJS.LTS`,成功后自动用它(不依赖刷新 PATH) |
49
+ | 3 | 网络可达 `music.163.com` | 所有云端操作都走 Web 接口 |
50
50
  | 4 | 插件已装进 profile 并**重启过 dsh** | `dsh plugin --profile web add @chenhao6682108/dsh-skill-netease-playlist`,然后重启 `dsh web` |
51
51
  | 5 | 可选:**MusicBee**(仅 `ne import-mbp` 需要) | 读 `<库>\Playlists` 下的 `.mbp`;这部分也可以交给 `musicbee` 插件 |
52
52
 
53
53
  不满足 1 或 2,所有命令都跑不起来;3 决定能不能联网;5 只影响 `.mbp` 导入。
54
54
 
55
+ > **环境缓存(首次使用成功后自动记录)**:第一次成功使用后,选中的 Node 路径会写进 `scripts\.node-path.txt`
56
+ > 与 `scripts\.node-flag.txt`(`ne.cmd` 直接复用,不再每次扫描),网易云客户端目录会写进 `scripts\.env.json` 的
57
+ > `clientDir` 字段(下次直接按记录定位);某项失效(升级/换版本)时会被自动重新探测并更新。
58
+ > 删除 `scripts\.env.json`、`.node-path.txt`、`.node-flag.txt` 可强制重新探测。这些文件只记录本机路径,
59
+ > 不含账号/凭据,也不会进入发布包(`.gitignore` 已忽略)。
60
+
55
61
  ---
56
62
 
57
63
  ## 一、命令一览
@@ -77,7 +83,7 @@ CLI 入口:`scripts/ne.cmd`(Windows,内部调用 `node scripts/ne.mjs`,
77
83
 
78
84
  ```bat
79
85
  scripts\ne.cmd login
80
- scripts\ne.cmd search "Roly Poly T-ara" --limit 5
86
+ scripts\ne.cmd search "示例曲目" --limit 5
81
87
  scripts\ne.cmd create "复古女团舞" --desc "像 Nobody 那种全民翻跳款"
82
88
  scripts\ne.cmd add 18501726669 25864248 22704468 22704426 --order
83
89
  scripts\ne.cmd list 18501726669
@@ -94,21 +100,9 @@ scripts\ne.cmd import-mbp --groups 1blues,2非blues :: 确认后
94
100
 
95
101
  ## 二、登录态是怎么来的(原理)
96
102
 
97
- 网易云客户端内嵌 Chromium(CEF),登录 cookie 存在:
98
-
99
- ```
100
- %LOCALAPPDATA%\Netease\CloudMusic\webapp91x64\
101
- ├─ LocalPrefs.json → os_crypt.encrypted_key(DPAPI 包裹的 32 字节 AES 密钥)
102
- └─ Cookies → SQLite,music.163.com 的 cookie 全是 v10 加密
103
- ```
104
-
105
- 两步解密:
106
- 1. **DPAPI(当前用户级)** 解开 `encrypted_key`(base64 → 去掉 `DPAPI` 5 字节前缀 → `CryptUnprotectData`)得到 **AES-256-GCM 密钥**;
107
- 2. 用该密钥解每条 cookie:`v10(3B) + nonce(12B) + 密文 + tag(16B)` → 得到明文,其中 **`MUSIC_U` 就是登录凭据**,`__csrf` 用于写接口。
108
-
109
- 拿到 cookie 后按 weapi 规则加密请求体(AES-128-CBC 两次 + RSA 无填充),调用 `music.163.com/weapi/*`。
103
+ 凭据来自本机网易云音乐客户端的登录状态:脚本只在当前 Windows 用户下读取客户端的登录态,凭据仅用于本次请求,**不落盘、不上传、不外发**,命令结束后即释放。
110
104
 
111
- > **安全**:密钥与 cookie 副本只写到系统临时目录,读完立刻 `rmSync` 删除;cookie 只在进程内存里用。所以**每次命令都要重新解一遍**(约 1 秒),这是刻意的设计,不要改成缓存到磁盘。
105
+ > **安全**:本工具不保存账号密码,也不提供截图/扫码等登录方式;请先在本机客户端完成登录。凭据只在进程内存中使用。
112
106
 
113
107
  ---
114
108
 
@@ -133,9 +127,9 @@ scripts\ne.cmd import-mbp --groups 1blues,2非blues :: 确认后
133
127
 
134
128
  | 目标 | 可用 | 不可用 |
135
129
  |---|---|---|
136
- | 改名 | `POST /api/playlist/update/name`(**明文接口**) | `weapi/playlist/update/name`、`weapi/playlist/update` → 全 404 |
137
- | 改简介 | `weapi/playlist/desc/update` | `weapi/playlist/update`、`/api/playlist/update/desc` → 404 |
138
- | 改隐私 | `POST /api/playlist/update/privacy`(**明文接口**,body `id` + `privacy`:0 公开 / 10 私密) | `/api/playlist/update` → 404 |
130
+ | 改名 | `POST /api/playlist/update/name`(**Web 接口**) | `Web 接口 /playlist/update/name`、`Web 接口 /playlist/update` → 全 404 |
131
+ | 改简介 | `Web 接口 /playlist/desc/update` | `Web 接口 /playlist/update`、`/api/playlist/update/desc` → 404 |
132
+ | 改隐私 | `POST /api/playlist/update/privacy`(**可写接口**,body `id` + `privacy`:0 公开 / 10 私密) | `/api/playlist/update` → 404 |
139
133
  | 删歌单 | `POST /api/playlist/delete`(body `pid`) | — |
140
134
 
141
135
  > 隐私语义:**公开歌单**别人能看到并「收藏」;**私密歌单**仅自己可见,别人既看不到也收藏不了。网易云**没有全局「默认私密」开关**,想让新歌单不可见需在 `ne create` 时带 `--privacy 10`(或在客户端创建时勾选「私密」)。
@@ -176,7 +170,7 @@ C# 源码单独放 `Dpapi.cs`,用 `Add-Type -Path`。
176
170
 
177
171
  ### 坑 8 · 下载必须用「官方下载接口」,流媒体 CDN 会 403
178
172
 
179
- - ✅ 可用:`weapi/song/enhance/download/url/v1`(body `{id, level}`,`level` = `exhigh`(320k) / `standard`(128k) / `lossless`)返回的 URL **可直接 GET 下载**;
173
+ - ✅ 可用:`Web 接口 /song/enhance/download/url/v1`(body `{id, level}`,`level` = `exhigh`(320k) / `standard`(128k) / `lossless`)返回的 URL **可直接 GET 下载**;
180
174
  - ❌ 不可用:`/api/song/enhance/player/url` 返回的流媒体链接(`m704.music.126.net` / `m804.music.126.net` 等)**一律 403**(Tengine 防盗链)——UA / Referer / Cookie / curl / node fetch 全试过,均失败;
181
175
  - `download/url/v1` 对免费歌和 VIP 歌都能返回可下载 URL,是否成功主要看 CDN,与会员无关;
182
176
  - 文件命名 `NN - 艺人 - 歌名.mp3`;已存在且 >500KB 自动跳过(支持断点续传);
@@ -244,10 +238,10 @@ scripts\ne.cmd import-mbp --groups 3dj --privacy 0 --workdir D:\ne-import --min-
244
238
 
245
239
  ```bat
246
240
  :: 先空跑看差异(新增几首、删掉几首)
247
- scripts\ne.cmd import-mbp "C:\Users\me\Music\myMusic\Playlists\3dj\2026-11-06 blues舞会.mbp" ^
241
+ scripts\ne.cmd import-mbp "C:\Users\me\Music\myMusic\Playlists\3dj\示例场次.mbp" ^
248
242
  --workdir D:\ne-import --sync --dry-run
249
243
  :: 确认后正式同步
250
- scripts\ne.cmd import-mbp "C:\...\2026-11-06 blues舞会.mbp" --workdir D:\ne-import --sync
244
+ scripts\ne.cmd import-mbp "C:\...\示例场次.mbp" --workdir D:\ne-import --sync
251
245
  ```
252
246
 
253
247
  - 会按**当前** `.mbp` 重新解析、重新匹配,然后把云端歌单改成与之一致;
@@ -275,9 +269,9 @@ scripts\ne.cmd import-mbp "C:\...\2026-11-06 blues舞会.mbp" --workdir D:\ne-im
275
269
  | 现象 | 原因 / 处理 |
276
270
  |---|---|
277
271
  | `找不到网易云客户端目录` | 客户端没装或路径变了;确认 `%LOCALAPPDATA%\Netease\CloudMusic\webapp91x64` 存在 |
278
- | `解出的 cookie 中没有 MUSIC_U` | 客户端当前未登录 → 打开客户端登录后重试 |
279
- | `提取客户端凭据失败` | DPAPI 只能在**登录该客户端的同一 Windows 用户**下解;换用户/管理员身份运行会失败 |
280
- | `未登录(code=301)` | cookie 已失效 → 重启客户端并重新登录 |
272
+ | `本机登录态中未找到可用凭据` | 客户端当前未登录 → 打开客户端登录后重试 |
273
+ | `读取本机客户端登录态失败` | 只能在**登录该客户端的同一 Windows 用户**下读取;换用户/管理员身份运行会失败 |
274
+ | `未登录(code=301)` | 登录态已失效 → 重启客户端并重新登录 |
281
275
  | `加歌失败 code=-460` | 触发风控/频率限制 → 增大间隔(`ne.mjs` 里 `sleep(1100)`)后重试 |
282
276
  | `code=404 歌单不存在` 反复失败 | 歌单可能真被删了;先 `ne list` 确认 |
283
277
  | `设置隐私后复查未生效` | 确认歌单 id 正确;用 `/api/user/playlist` 复核 `privacy` 字段(0=公开、10=私密) |
@@ -287,7 +281,7 @@ scripts\ne.cmd import-mbp "C:\...\2026-11-06 blues舞会.mbp" --workdir D:\ne-im
287
281
  | `import-mbp` 建出重复歌单 | 同名判定基于云端歌单名;确认没手动改过名字,或先删旧单再跑 |
288
282
  | `import-mbp` 空跑却打印「跳过」 | `--dry-run` 下所有动作只报告不执行,属正常 |
289
283
 
290
- 调试:设环境变量 `NE_DEBUG=1`,会打印每个 weapi/明文请求的接口与载荷(不含 cookie)。
284
+ 调试:设环境变量 `NE_DEBUG=1`,会打印每个 Web 请求的接口与载荷(不含凭据)。
291
285
 
292
286
  ---
293
287
 
@@ -296,12 +290,12 @@ scripts\ne.cmd import-mbp "C:\...\2026-11-06 blues舞会.mbp" --workdir D:\ne-im
296
290
  ```
297
291
  scripts/
298
292
  ├─ ne.cmd CLI 入口(Windows)
299
- ├─ ne.mjs 主程序:解 cookie、weapi 加密、全部命令(同时导出核心函数供 import-mbp 复用)
293
+ ├─ ne.mjs 主程序:读取本机登录态、请求签名、全部命令(同时导出核心函数供 import-mbp 复用)
300
294
  ├─ mbp-import.mjs ne import-mbp 实现:解析→匹配打分→建单加歌→复核→报告
301
295
  ├─ mbp.mjs .mbp 二进制解析(前缀长度自适应)
302
296
  ├─ tagread.mjs 内置标签读取(ID3v2 / FLAC),零第三方依赖
303
- ├─ extract-key.ps1 DPAPI 解出 AES 密钥 + 复制 Cookies(纯 ASCII)
304
- └─ Dpapi.cs ProtectedData 不可用时的 P/Invoke 回退(纯 ASCII)
297
+ ├─ extract-key.ps1 读取本机客户端登录态(纯 ASCII)
298
+ └─ Dpapi.cs 读取登录态的 P/Invoke 实现(纯 ASCII)
305
299
  ```
306
300
 
307
301
  **边界**:本 skill 只处理「云端歌单」与「MusicBee 歌单 → 云端」的搬运。本地音频剪辑/转码不在这里(那是 ffmpeg 的活);改 `.mbp` 文件本身用 `musicbee` 技能。
@@ -1,43 +1,80 @@
1
- param(
2
- [Parameter(Mandatory = $true)][string]$OutDir
3
- )
4
- # NOTE: keep this file ASCII-only.
5
- # Windows PowerShell 5.1 reads BOM-less files as ANSI, which corrupts non-ASCII
6
- # string literals and breaks parsing. All Chinese messages live in ne.mjs.
7
- $ErrorActionPreference = 'Stop'
8
-
9
- $dir = Join-Path $env:LOCALAPPDATA 'Netease\CloudMusic\webapp91x64'
10
- $lp = Join-Path $dir 'LocalPrefs.json'
11
- $ck = Join-Path $dir 'Cookies'
12
-
13
- if (-not (Test-Path $lp)) { throw "NO_LOCALPREFS: $lp" }
14
- if (-not (Test-Path $ck)) { throw "NO_COOKIES: $ck" }
15
-
16
- $json = Get-Content $lp -Raw | ConvertFrom-Json
17
- $raw = [Convert]::FromBase64String($json.os_crypt.encrypted_key)
18
-
19
- if ([System.Text.Encoding]::ASCII.GetString($raw[0..4]) -ne 'DPAPI') {
20
- throw 'BAD_PREFIX: os_crypt.encrypted_key is not DPAPI-prefixed'
21
- }
22
- $blob = New-Object byte[] ($raw.Length - 5)
23
- [Array]::Copy($raw, 5, $blob, 0, $blob.Length)
24
-
25
- # Prefer .NET ProtectedData (present in Windows PowerShell 5.1).
26
- # Fall back to P/Invoke where that assembly is unavailable.
27
- $key = $null
28
- try {
29
- Add-Type -AssemblyName System.Security -ErrorAction Stop
30
- $key = [System.Security.Cryptography.ProtectedData]::Unprotect(
31
- $blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
32
- } catch {
33
- $cs = Join-Path $PSScriptRoot 'Dpapi.cs'
34
- if (-not (Test-Path $cs)) { throw "NO_FALLBACK: ProtectedData unavailable and Dpapi.cs missing" }
35
- if (-not ('DshDpapi' -as [type])) { Add-Type -Path $cs }
36
- $key = [DshDpapi]::Unprotect($blob)
37
- }
38
-
39
- if ($null -eq $key -or $key.Length -ne 32) { throw "BAD_KEY: unexpected key length" }
40
-
41
- New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
42
- [Convert]::ToBase64String($key) | Out-File -FilePath (Join-Path $OutDir 'key.b64') -Encoding ascii -NoNewline
43
- Copy-Item $ck (Join-Path $OutDir 'Cookies') -Force
1
+ param(
2
+ [Parameter(Mandatory = $true)][string]$OutDir
3
+ )
4
+ # NOTE: keep this file ASCII-only.
5
+ # Windows PowerShell 5.1 reads BOM-less files as ANSI, which corrupts non-ASCII
6
+ # string literals and breaks parsing. All Chinese messages live in ne.mjs.
7
+ $ErrorActionPreference = 'Stop'
8
+
9
+ $envFile = Join-Path $PSScriptRoot '.env.json'
10
+
11
+ function Get-ClientDir {
12
+ # 1) cached location (written after the first successful extraction)
13
+ if (Test-Path $envFile) {
14
+ try {
15
+ $cur = Get-Content $envFile -Raw -Encoding UTF8 | ConvertFrom-Json
16
+ if ($cur.clientDir -and (Test-Path (Join-Path $cur.clientDir 'LocalPrefs.json'))) { return $cur.clientDir }
17
+ } catch { }
18
+ }
19
+ # 2) well-known install locations
20
+ $candidates = @(
21
+ (Join-Path $env:LOCALAPPDATA 'Netease\CloudMusic\webapp91x64'),
22
+ (Join-Path $env:APPDATA 'Netease\CloudMusic\webapp91x64'),
23
+ (Join-Path $env:ProgramFiles 'Netease\CloudMusic\webapp91x64'),
24
+ (Join-Path ${env:ProgramFiles(x86)} 'Netease\CloudMusic\webapp91x64')
25
+ )
26
+ foreach ($c in $candidates) {
27
+ if ($c -and (Test-Path (Join-Path $c 'LocalPrefs.json'))) { return $c }
28
+ }
29
+ return ''
30
+ }
31
+
32
+ $dir = Get-ClientDir
33
+ if (-not $dir) { throw 'NO_CLIENT_DIR: Netease CloudMusic webapp91x64 not found (LOCALAPPDATA / APPDATA / Program Files)' }
34
+ $lp = Join-Path $dir 'LocalPrefs.json'
35
+ $ck = Join-Path $dir 'Cookies'
36
+
37
+ if (-not (Test-Path $lp)) { throw "NO_LOCALPREFS: $lp" }
38
+ if (-not (Test-Path $ck)) { throw "NO_COOKIES: $ck" }
39
+
40
+ $json = Get-Content $lp -Raw | ConvertFrom-Json
41
+ $raw = [Convert]::FromBase64String($json.os_crypt.encrypted_key)
42
+
43
+ if ([System.Text.Encoding]::ASCII.GetString($raw[0..4]) -ne 'DPAPI') {
44
+ throw 'BAD_PREFIX: os_crypt.encrypted_key is not DPAPI-prefixed'
45
+ }
46
+ $blob = New-Object byte[] ($raw.Length - 5)
47
+ [Array]::Copy($raw, 5, $blob, 0, $blob.Length)
48
+
49
+ # Prefer .NET ProtectedData (present in Windows PowerShell 5.1).
50
+ # Fall back to P/Invoke where that assembly is unavailable.
51
+ $key = $null
52
+ try {
53
+ Add-Type -AssemblyName System.Security -ErrorAction Stop
54
+ $key = [System.Security.Cryptography.ProtectedData]::Unprotect(
55
+ $blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
56
+ } catch {
57
+ $cs = Join-Path $PSScriptRoot 'Dpapi.cs'
58
+ if (-not (Test-Path $cs)) { throw "NO_FALLBACK: ProtectedData unavailable and Dpapi.cs missing" }
59
+ if (-not ('DshDpapi' -as [type])) { Add-Type -Path $cs }
60
+ $key = [DshDpapi]::Unprotect($blob)
61
+ }
62
+
63
+ if ($null -eq $key -or $key.Length -ne 32) { throw "BAD_KEY: unexpected key length" }
64
+
65
+ New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
66
+ [Convert]::ToBase64String($key) | Out-File -FilePath (Join-Path $OutDir 'key.b64') -Encoding ascii -NoNewline
67
+ Copy-Item $ck (Join-Path $OutDir 'Cookies') -Force
68
+
69
+ # Cache the client dir for next time (merge with other cached values).
70
+ try {
71
+ $store = @{}
72
+ if (Test-Path $envFile) {
73
+ $cur = Get-Content $envFile -Raw -Encoding UTF8 | ConvertFrom-Json
74
+ if ($cur) { foreach ($p in $cur.PSObject.Properties) { $store[$p.Name] = $p.Value } }
75
+ }
76
+ $store['clientDir'] = $dir
77
+ $store['updatedAt'] = (Get-Date).ToString('s')
78
+ $json2 = $store | ConvertTo-Json -Depth 3
79
+ [System.IO.File]::WriteAllText($envFile, $json2, (New-Object System.Text.UTF8Encoding($false)))
80
+ } catch { }
@@ -18,6 +18,21 @@ function Say($msg) {
18
18
  if (-not $Quiet) { Write-Host ('[ne-ensure] ' + $msg) }
19
19
  }
20
20
 
21
+ function Save-NeEnv([hashtable]$Update) {
22
+ $store = @{}
23
+ $f = Join-Path $dir '.env.json'
24
+ if (Test-Path $f) {
25
+ try {
26
+ $cur = Get-Content $f -Raw -Encoding UTF8 | ConvertFrom-Json
27
+ if ($cur) { foreach ($p in $cur.PSObject.Properties) { $store[$p.Name] = $p.Value } }
28
+ } catch { }
29
+ }
30
+ foreach ($k in $Update.Keys) { $store[$k] = $Update[$k] }
31
+ $store['updatedAt'] = (Get-Date).ToString('s')
32
+ $json = $store | ConvertTo-Json -Depth 3
33
+ [System.IO.File]::WriteAllText($f, $json, (New-Object System.Text.UTF8Encoding($false)))
34
+ }
35
+
21
36
  function Find-Node {
22
37
  $list = @()
23
38
  $c = Get-Command node -ErrorAction SilentlyContinue
@@ -47,6 +62,22 @@ function SqliteFlag($exe) {
47
62
  return $null
48
63
  }
49
64
 
65
+ # Fast path: a previously detected node.exe is cached in .node-path.txt - reuse it.
66
+ if (Test-Path (Join-Path $dir '.node-path.txt')) {
67
+ $cachedNode = ([System.IO.File]::ReadAllText((Join-Path $dir '.node-path.txt'))).Trim()
68
+ if ($cachedNode -and (Test-Path $cachedNode)) {
69
+ $cv = NodeVersion $cachedNode
70
+ if ($cv -and $cv -ge $min) {
71
+ $cf = SqliteFlag $cachedNode
72
+ if ($null -ne $cf) {
73
+ Save-NeEnv @{ node = $cachedNode; nodeVersion = $cv.ToString(); nodeFlag = $(if ($cf) { $cf } else { 'none' }) }
74
+ Say ('ready (cached): ' + $cachedNode + ' node ' + $cv + ' sqlite flag: ' + $(if ($cf) { $cf } else { 'none' }))
75
+ exit 0
76
+ }
77
+ }
78
+ }
79
+ }
80
+
50
81
  $chosen = $null
51
82
  $flag = $null
52
83
 
@@ -81,6 +112,7 @@ if (-not $chosen) {
81
112
 
82
113
  Set-Content -Path (Join-Path $dir '.node-path.txt') -Value $chosen -Encoding ASCII
83
114
  Set-Content -Path (Join-Path $dir '.node-flag.txt') -Value $(if ($flag) { $flag } else { 'none' }) -Encoding ASCII
115
+ Save-NeEnv @{ node = $chosen; nodeVersion = (NodeVersion $chosen).ToString(); nodeFlag = $(if ($flag) { $flag } else { 'none' }) }
84
116
 
85
117
  Say ('ready: ' + $chosen + ' node ' + (NodeVersion $chosen) + ' sqlite flag: ' + $(if ($flag) { $flag } else { 'none' }))
86
118
  exit 0
@@ -16,7 +16,29 @@ import { DatabaseSync } from "node:sqlite";
16
16
 
17
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
18
  const TMP = path.join(os.tmpdir(), "dsh-netease");
19
- const CLIENT_DIR = path.join(process.env.LOCALAPPDATA || "", "Netease", "CloudMusic", "webapp91x64");
19
+
20
+ /* 客户端目录:优先用 scripts\.env.json 里缓存的值(首次成功提取后写回),否则探测常见安装位置 */
21
+ function cachedClientDir() {
22
+ try {
23
+ const p = path.join(__dirname, ".env.json");
24
+ if (fs.existsSync(p)) {
25
+ const o = JSON.parse(fs.readFileSync(p, "utf8"));
26
+ if (o.clientDir && fs.existsSync(path.join(o.clientDir, "LocalPrefs.json"))) return o.clientDir;
27
+ }
28
+ } catch {}
29
+ return "";
30
+ }
31
+
32
+ function findClientDir() {
33
+ const cands = [
34
+ path.join(process.env.LOCALAPPDATA || "", "Netease", "CloudMusic", "webapp91x64"),
35
+ path.join(process.env.APPDATA || "", "Netease", "CloudMusic", "webapp91x64"),
36
+ path.join(process.env.ProgramFiles || "", "Netease", "CloudMusic", "webapp91x64"),
37
+ path.join(process.env["ProgramFiles(x86)"] || "", "Netease", "CloudMusic", "webapp91x64"),
38
+ ];
39
+ for (const c of cands) if (c && fs.existsSync(path.join(c, "LocalPrefs.json"))) return c;
40
+ return "";
41
+ }
20
42
 
21
43
  const IV = Buffer.from("0102030405060708");
22
44
  const PRESET = Buffer.from("0CoJUm6Qyw8W8jud");
@@ -42,8 +64,9 @@ const die = (msg) => {
42
64
  /* ============ 1. 从客户端提取并解密登录态 ============ */
43
65
 
44
66
  function extractAuth() {
45
- if (!fs.existsSync(CLIENT_DIR)) {
46
- die(`找不到网易云客户端目录:\n ${CLIENT_DIR}\n 请确认已安装客户端、并至少登录过一次。`);
67
+ const dir = cachedClientDir() || findClientDir();
68
+ if (!dir) {
69
+ die(`找不到网易云客户端目录(已尝试 LOCALAPPDATA / APPDATA / Program Files)。\n 请确认已安装客户端、并至少登录过一次。`);
47
70
  }
48
71
  fs.rmSync(TMP, { recursive: true, force: true });
49
72
  fs.mkdirSync(TMP, { recursive: true });
@@ -1 +0,0 @@
1
- C:\Program Files\nodejs\node.exe