@chenhao6682108/dsh-skill-netease-playlist 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 chenhao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # dsh-skill-netease-playlist
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [中文](README.zh.md)
4
+
5
+ A [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`) plugin that ships the
6
+ `netease-playlist` skill: drive NetEase Cloud Music (网易云音乐) playlists through the **local desktop
7
+ client's own login state** — no QR scan, no password, no browser automation, and no cookie written to
8
+ disk.
9
+
10
+ It is a **skill plugin**: installing it registers one agent skill (plus its scripts) into the harness,
11
+ so the agent can search tracks, build playlists, and move MusicBee `.mbp` playlists to the cloud.
12
+
13
+ ## How the login state is obtained
14
+
15
+ The NetEase desktop client embeds Chromium (CEF). Its cookies live in an encrypted SQLite store, and the
16
+ AES key is wrapped by Windows DPAPI under the current user. The skill:
17
+
18
+ 1. DPAPI-unwraps `os_crypt.encrypted_key` → an AES-256-GCM key;
19
+ 2. decrypts each `v10` cookie with it, extracting `MUSIC_U` (the login credential) and `__csrf`;
20
+ 3. encrypts every `weapi/*` request body the way the client does and calls `music.163.com`.
21
+
22
+ The key and cookie copies are written only to a system temp directory and deleted immediately after
23
+ reading; cookies live in process memory only. Every command re-derives them (~1 s) by design.
24
+
25
+ ## What the skill does
26
+
27
+ | Command | Purpose |
28
+ |---|---|
29
+ | `ne login` | Verify the login state, print nickname and uid |
30
+ | `ne search <keywords>` | Search tracks |
31
+ | `ne create / rename / desc / privacy` | Create a playlist and edit its name, description, privacy (public or private) |
32
+ | `ne add / remove / list / delete` | Add tracks (`--order` preserves the given order), remove tracks, list, delete a playlist |
33
+ | `ne download <id>` | Download every track as local mp3 (320k, resumable) |
34
+ | `ne import-mbp [target] --groups a,b` | Bulk-import MusicBee `.mbp` playlists: parse → read tags → fuzzy-match → create → add in order → verify; `--sync` re-aligns the cloud playlist after the local one changed |
35
+
36
+ ## Requirements
37
+
38
+ - **Windows** — DPAPI and the desktop client's CEF store are Windows-only, and the scripts are `.cmd`.
39
+ - **NetEase Cloud Music desktop client installed and logged in** as the same Windows user that runs
40
+ `dsh` (DPAPI cannot decrypt another user's key).
41
+ - **Node ≥ 22.5** (the CLI uses the built-in `node:sqlite` to read the cookie store). The bundled DSH
42
+ host already satisfies this.
43
+
44
+ ## Install
45
+
46
+ ```sh
47
+ dsh plugin --profile web add @chenhao6682108/dsh-skill-netease-playlist # npm (once published)
48
+ dsh plugin --profile web add github:chenhao6682108/dsh-skill-netease-playlist # straight from the repo
49
+ dsh plugin --profile web add . # from a local checkout
50
+ ```
51
+
52
+ Restart `dsh web`; the skill catalog lists `netease-playlist`.
53
+
54
+ Uninstall with `dsh plugin --profile web remove @chenhao6682108/dsh-skill-netease-playlist`.
55
+
56
+ ## Known traps the skill documents
57
+
58
+ - Adding tracks inserts them **in reverse** (and batches of 25 internally too) — `--order` submits the
59
+ reversed array so display order matches; preserving order after an edit means "clear and rebuild".
60
+ - Write endpoints intermittently return `404 playlist not found`; the CLI retries 3× at 1.5 s.
61
+ - Rename/privacy only work through the plaintext `/api/playlist/update/*` endpoints.
62
+ - Search results are polluted by covers/remixes/live takes; the importer scores title/artist/duration
63
+ and refuses to substitute a different recording for the original.
64
+ - Downloading needs `weapi/song/enhance/download/url/v1`; streaming CDN URLs return 403.
65
+ - The `.mbp` prefix length varies per library, so the parser probes offsets 40–120 and requires an
66
+ exact end-of-file match.
67
+
68
+ ## Layout
69
+
70
+ ```text
71
+ package.json dsh.bundle.patch + engines.dsh
72
+ cordis.patch.yml inserts the plugin into the profile layer stack
73
+ lib/index.js registers the bundled skill (no dependencies, no build)
74
+ skills/netease-playlist/
75
+ SKILL.md the skill body the agent loads
76
+ scripts/ ne.cmd / ne.mjs (CLI), mbp-import.mjs, mbp.mjs, tagread.mjs,
77
+ extract-key.ps1 + Dpapi.cs (credential extraction)
78
+ ```
79
+
80
+ ## Notes
81
+
82
+ - Pairs with [`@chenhao6682108/dsh-skill-musicbee`](../dsh-skill-musicbee): download from NetEase, tag the
83
+ files, publish the playlist into MusicBee.
84
+ - `extract-key.ps1` and `Dpapi.cs` are deliberately ASCII-only — Windows PowerShell 5.1 decodes
85
+ BOM-less UTF-8 as ANSI and would mangle non-ASCII source.
86
+
87
+ ## License
88
+
89
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,78 @@
1
+ # dsh-skill-netease-playlist
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 把 `netease-playlist` 技能打包成 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)插件的仓库。
6
+ 它直接复用**本机网易云音乐桌面客户端自己的登录态**:不扫码、不要密码、不走浏览器自动化,cookie 也不落盘。
7
+
8
+ 属于**技能型插件**:装上之后技能出现在会话目录里,模型按需加载并调用包内脚本搜索曲目、建歌单、把 MusicBee 的 `.mbp` 歌单搬上云端。
9
+
10
+ ## 登录态是怎么来的
11
+
12
+ 网易云客户端内嵌 Chromium(CEF),cookie 存在加密 SQLite 里,密钥由 Windows DPAPI 按当前用户加密包裹。技能会:
13
+
14
+ 1. 用 DPAPI 解开 `os_crypt.encrypted_key` → 得到 AES-256-GCM 密钥;
15
+ 2. 用它解每条 `v10` cookie,取出 `MUSIC_U`(登录凭据)与 `__csrf`;
16
+ 3. 按客户端的规则加密 `weapi/*` 请求体后调用 `music.163.com`。
17
+
18
+ 密钥与 cookie 副本只写到系统临时目录、读完立刻删除,cookie 只在进程内存里用。每条命令都重新解一次(约 1 秒),这是刻意的设计。
19
+
20
+ ## 技能能做什么
21
+
22
+ | 命令 | 作用 |
23
+ |---|---|
24
+ | `ne login` | 验证登录态,打印昵称与 uid |
25
+ | `ne search <关键词>` | 搜索曲目 |
26
+ | `ne create / rename / desc / privacy` | 新建歌单,改名/改简介/改隐私(公开可被收藏、私密仅自己可见) |
27
+ | `ne add / remove / list / delete` | 加歌(`--order` 保证显示顺序=给定顺序)、移歌、列曲目、删歌单 |
28
+ | `ne download <id>` | 下载歌单全部歌曲为本地 mp3(320k,断点续传) |
29
+ | `ne import-mbp [目标] --groups a,b` | 把 MusicBee `.mbp` 歌单批量搬上云端:解析→读标签→模糊匹配→建单→按序加歌→复核;`--sync` 在本地歌单改过后把云端对齐 |
30
+
31
+ ## 环境要求
32
+
33
+ - **Windows**:DPAPI 与客户端 CEF 存储都是 Windows 专有,脚本也是 `.cmd`。
34
+ - **已安装并登录网易云音乐桌面客户端**,且运行 `dsh` 的是**同一个 Windows 用户**(DPAPI 解不了别的用户的密钥)。
35
+ - **Node ≥ 22.5**(CLI 用内置 `node:sqlite` 读 cookie 库)。DSH 宿主本身已满足。
36
+
37
+ ## 安装
38
+
39
+ ```sh
40
+ dsh plugin --profile web add @chenhao6682108/dsh-skill-netease-playlist # npm(发布后)
41
+ dsh plugin --profile web add github:chenhao6682108/dsh-skill-netease-playlist # 直接从仓库装
42
+ dsh plugin --profile web add . # 从本地 checkout 装
43
+ ```
44
+
45
+ 重启 `dsh web`,技能目录里就有 `netease-playlist`。
46
+
47
+ 卸载:`dsh plugin --profile web remove @chenhao6682108/dsh-skill-netease-playlist`。
48
+
49
+ ## 技能里记录的坑
50
+
51
+ - 加歌是**倒序插入**(同批 25 首内部也倒序)→ `--order` 提交倒序数组来保证显示顺序;改过歌单后要保序只能整单清空重建。
52
+ - 写接口偶发 `404 歌单不存在`,CLI 内置 3 次重试、间隔 1.5s。
53
+ - 改名/隐私只有明文 `/api/playlist/update/*` 接口可用。
54
+ - 搜索被翻唱/remix/Live 污染,导入流程按标题/艺人/时长打分,低于阈值宁可不加。
55
+ - 下载必须用 `weapi/song/enhance/download/url/v1`,流媒体 CDN 链接一律 403。
56
+ - `.mbp` 前缀长度因库而异,解析器从 40~120 字节逐个偏移试解并要求恰好读到文件末尾。
57
+
58
+ ## 目录结构
59
+
60
+ ```text
61
+ package.json dsh.bundle.patch + engines.dsh
62
+ cordis.patch.yml 把插件插入 profile 层栈
63
+ lib/index.js 注册包内技能(零依赖、零构建)
64
+ skills/netease-playlist/
65
+ SKILL.md 模型加载的技能正文
66
+ scripts/ ne.cmd / ne.mjs(CLI)、mbp-import.mjs、mbp.mjs、tagread.mjs、
67
+ extract-key.ps1 + Dpapi.cs(凭据提取)
68
+ ```
69
+
70
+ ## 注意
71
+
72
+ - 和 [`@chenhao6682108/dsh-skill-musicbee`](../dsh-skill-musicbee) 配套:从网易云下载 → 补标签 → 进 MusicBee。
73
+ - `extract-key.ps1` 与 `Dpapi.cs` **刻意保持纯 ASCII**——Windows PowerShell 5.1 会把无 BOM 的 UTF-8 当 ANSI 解码,
74
+ 非 ASCII 源码会解析失败。
75
+
76
+ ## 许可
77
+
78
+ MIT
@@ -0,0 +1,5 @@
1
+ # DSH bundle patch: inserts this plugin into a profile's plugin layer stack.
2
+ # Installed with: dsh plugin --profile <profile> add <package-or-tarball>
3
+ - insert:
4
+ - id: skill-netease-playlist
5
+ name: '@chenhao6682108/dsh-skill-netease-playlist'
package/lib/index.js ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * `@chenhao6682108/dsh-skill-netease-playlist` — ships the `netease-playlist` skill as
3
+ * an installable DSH plugin.
4
+ *
5
+ * A Cordis function plugin with no dependencies and no build step: `apply()`
6
+ * reads this package's bundled `skills/netease-playlist/SKILL.md`, parses its
7
+ * frontmatter, and registers the body into the harness skill registry
8
+ * (`ctx.skills`) with a directory resource base, so the relative `scripts/`
9
+ * paths in the body resolve against the installed package.
10
+ *
11
+ * The plugin is a bundle: `cordis.patch.yml` inserts it into a profile's layer
12
+ * stack when installed with `dsh plugin add`.
13
+ *
14
+ * @module @chenhao6682108/dsh-skill-netease-playlist
15
+ */
16
+
17
+ import { readFileSync } from 'node:fs'
18
+ import { fileURLToPath } from 'node:url'
19
+
20
+ /** Plugin name shown by the loader. */
21
+ export const name = 'skill-netease-playlist'
22
+
23
+ /** The skill registry is the only host service this plugin touches. */
24
+ export const inject = ['skills']
25
+
26
+ const SKILL_DIR = new URL('../skills/netease-playlist/', import.meta.url)
27
+
28
+ /** Shown only when the bundled SKILL.md loses its frontmatter description. */
29
+ const FALLBACK_DESCRIPTION =
30
+ 'NetEase Cloud Music playlist toolkit: reuse the local desktop client login state ' +
31
+ '(DPAPI-decrypted CEF cookie) to search tracks, create/rename/describe/private playlists, ' +
32
+ 'add and reorder tracks, delete playlists, download playlist audio as mp3, and bulk-import ' +
33
+ 'MusicBee .mbp playlists into the cloud. Windows plus a logged-in NetEase Cloud Music ' +
34
+ 'client required.'
35
+
36
+ /**
37
+ * Parse leading YAML frontmatter into flat fields.
38
+ *
39
+ * Only the subset a SKILL.md uses is understood: `key: value` scalars and
40
+ * `key:` followed by `- item` lists. Deeper YAML (nested maps, block scalars)
41
+ * is not needed by any argument this plugin ships, so it is left alone rather
42
+ * than half-parsed.
43
+ *
44
+ * @param {string} raw - full SKILL.md text.
45
+ * @returns {{ fields: Record<string, string | string[]>, body: string }}
46
+ */
47
+ function parseFrontmatter(raw) {
48
+ const text = raw.replace(/^\uFEFF/, '')
49
+ const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text)
50
+ if (match === null) return { fields: {}, body: text }
51
+
52
+ /** @type {Record<string, string | string[]>} */
53
+ const fields = {}
54
+ let key = null
55
+ for (const line of match[1].split(/\r?\n/)) {
56
+ if (line.trim() === '' || /^[ \t]*#/.test(line)) continue
57
+
58
+ const item = /^[ \t]*-[ \t]+(.*)$/.exec(line)
59
+ if (item !== null && key !== null) {
60
+ const list = Array.isArray(fields[key]) ? fields[key] : []
61
+ list.push(unquote(item[1].trim()))
62
+ fields[key] = list
63
+ continue
64
+ }
65
+
66
+ const pair = /^([A-Za-z][\w-]*)[ \t]*:[ \t]*(.*)$/.exec(line)
67
+ if (pair === null) continue
68
+ key = pair[1]
69
+ const value = pair[2].trim()
70
+ fields[key] = value === '' ? [] : unquote(value)
71
+ }
72
+ return { fields, body: text.slice(match[0].length) }
73
+ }
74
+
75
+ /**
76
+ * Strip one layer of matching single or double quotes.
77
+ * @param {string} value - raw scalar.
78
+ * @returns {string} the unquoted scalar.
79
+ */
80
+ function unquote(value) {
81
+ const quoted = /^(['"])([\s\S]*)\1$/.exec(value)
82
+ return quoted === null ? value : quoted[2]
83
+ }
84
+
85
+ /**
86
+ * Register the bundled skill into the harness skill registry.
87
+ * @param {import('@deepseek-ai/cordis').Context} ctx - plugin context.
88
+ */
89
+ export function apply(ctx) {
90
+ const source = readFileSync(new URL('SKILL.md', SKILL_DIR), 'utf8')
91
+ const { fields, body } = parseFrontmatter(source)
92
+
93
+ ctx.skills.register({
94
+ name: typeof fields.name === 'string' ? fields.name : 'netease-playlist',
95
+ description:
96
+ typeof fields.description === 'string' && fields.description !== ''
97
+ ? fields.description
98
+ : FALLBACK_DESCRIPTION,
99
+ ...(typeof fields.whenToUse === 'string' ? { whenToUse: fields.whenToUse } : {}),
100
+ content: body.trim(),
101
+ source: 'bundled',
102
+ path: fileURLToPath(new URL('SKILL.md', SKILL_DIR)),
103
+ resourceBase: { kind: 'directory', path: fileURLToPath(SKILL_DIR) },
104
+ metadata: { triggers: fields.triggers ?? [] },
105
+ })
106
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@chenhao6682108/dsh-skill-netease-playlist",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
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. Windows and a logged-in NetEase Cloud Music client required.",
5
+ "keywords": [
6
+ "deepseek",
7
+ "harness",
8
+ "dsh",
9
+ "dsh-plugin",
10
+ "skill",
11
+ "netease",
12
+ "playlist",
13
+ "musicbee",
14
+ "mbp",
15
+ "music"
16
+ ],
17
+ "license": "MIT",
18
+ "type": "module",
19
+ "main": "./lib/index.js",
20
+ "exports": {
21
+ ".": "./lib/index.js",
22
+ "./cordis.patch.yml": "./cordis.patch.yml",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "lib",
27
+ "skills",
28
+ "cordis.patch.yml",
29
+ "README.md",
30
+ "README.zh.md",
31
+ "LICENSE"
32
+ ],
33
+ "engines": {
34
+ "node": ">=24.9.0",
35
+ "dsh": ">=0.1.2-rc.1 <0.2.0"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/chenhao6682108/dsh-skill-netease-playlist.git"
40
+ },
41
+ "dsh": {
42
+ "bundle": {
43
+ "patch": "./cordis.patch.yml"
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,293 @@
1
+ ---
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;需本机网易云音乐客户端已登录。
4
+ triggers:
5
+ - 网易云
6
+ - 网易云歌单
7
+ - 新建歌单
8
+ - 建歌单
9
+ - 加歌到歌单
10
+ - 歌单加歌
11
+ - 网易云搜索
12
+ - netease
13
+ - 云音乐
14
+ - 歌单隐私
15
+ - 设为私密
16
+ - 公开歌单
17
+ - privacy
18
+ - 歌单设置私密
19
+ - 下载歌单
20
+ - 下载歌曲
21
+ - 歌曲下载
22
+ - 网易云下载
23
+ - 歌单加到网易云
24
+ - 歌单导入网易云
25
+ - 导入网易云
26
+ - MusicBee 歌单
27
+ - mbp
28
+ - import-mbp
29
+ - 同步歌单
30
+ - 歌单已更改
31
+ - 更新网易云歌单
32
+ - 歌单同步
33
+ ---
34
+
35
+ # 🎧 网易云歌单助手
36
+
37
+ 直接用**本机网易云音乐桌面客户端的登录态**操作云端歌单:不扫码、不要密码、不碰浏览器自动化(浏览器自动化在本机是 `standard` 模式 + 审批禁用,点击/输入会被自动拒绝,所以这条路走不通)。支持曲目搜索、建歌单、改名/改简介/改隐私(公开/私密)、按序批量加歌、移歌、删歌单、下载歌单,以及**把 MusicBee 的 `.mbp` 歌单整组搬上云端**(自动搜索匹配、可按原顺序加歌、可空跑与续跑)。
38
+
39
+ CLI 入口:`scripts/ne.cmd`(Windows,内部调用 `node scripts/ne.mjs`,需要 Node ≥ 22.5,用到内置 `node:sqlite`)
40
+
41
+ ---
42
+
43
+ ## 一、命令一览
44
+
45
+ | 命令 | 作用 |
46
+ |---|---|
47
+ | `ne login` | 验证登录态,打印昵称与 uid |
48
+ | `ne search <关键词> [--limit 10] [--json]` | 搜索曲目,输出 `曲目id \| 歌名 - 艺人 \| 时长 \| 专辑 \| fee` |
49
+ | `ne create <歌单名> [--privacy 0\|10] [--desc 文案]` | 新建歌单,输出歌单 id 与链接 |
50
+ | `ne add <歌单id> <曲目id...> [--order]` | 加歌;**`--order` 保证显示顺序=给定顺序** |
51
+ | `ne remove <歌单id> <曲目id...>` | 移除曲目 |
52
+ | `ne delete <歌单id>` | 删除整个歌单 |
53
+ | `ne list <歌单id>` | 列出曲目(带曲目 id,便于后续删改) |
54
+ | `ne rename <歌单id> <新名称>` | 改名 |
55
+ | `ne desc <歌单id> <文案>` | 改简介 |
56
+ | `ne privacy <歌单id> <0\|10>` | 设置隐私:`0` 公开(可被收藏)、`10` 私密(仅自己可见) |
57
+ | `ne download <歌单id> [--out 目录] [--level exhigh\|standard\|lossless]` | 下载歌单全部歌曲为本地 mp3(默认 `%USERPROFILE%\CloudMusic\<歌单名>`),已存在自动跳过 |
58
+ | `ne import-mbp [目标] [--groups a,b] [--privacy 0\|10] [--workdir 目录] [--dry-run] [--reuse] [--limit N] [--sync]` | **把 MusicBee 的 `.mbp` 歌单批量搬上云端**:解析曲目→读标签→搜索匹配→建歌单按原顺序加歌→复核;**`--sync` 在本地歌单改过之后把云端对齐**。可分段跑(`--build`/`--match`/`--rescue`/`--create`/`--verify`),详见**第四节** |
59
+
60
+ `--privacy`:`0` 公开(默认)、`10` 私密。
61
+
62
+ ### 典型流程
63
+
64
+ ```bat
65
+ scripts\ne.cmd login
66
+ scripts\ne.cmd search "Roly Poly T-ara" --limit 5
67
+ scripts\ne.cmd create "复古女团舞" --desc "像 Nobody 那种全民翻跳款"
68
+ scripts\ne.cmd add 18501726669 25864248 22704468 22704426 --order
69
+ scripts\ne.cmd list 18501726669
70
+ scripts\ne.cmd privacy 18501726669 10
71
+ scripts\ne.cmd download 18501726669 --out "C:\CloudMusic"
72
+ scripts\ne.cmd import-mbp --groups 1blues,2非blues --dry-run :: 先空跑看匹配情况
73
+ scripts\ne.cmd import-mbp --groups 1blues,2非blues :: 确认后正式导入(默认私密)
74
+ ```
75
+
76
+ > `ne download` 下载的 mp3 **不带 ID3 标签**(个别带来源专辑旧标签);若要把下载的歌导入 MusicBee 曲库
77
+ > (补标签 → 生成 .mbp → MusicBee 里 Rescan),完整流程见 `musicbee` 技能第十节。
78
+
79
+ ---
80
+
81
+ ## 二、登录态是怎么来的(原理)
82
+
83
+ 网易云客户端内嵌 Chromium(CEF),登录 cookie 存在:
84
+
85
+ ```
86
+ %LOCALAPPDATA%\Netease\CloudMusic\webapp91x64\
87
+ ├─ LocalPrefs.json → os_crypt.encrypted_key(DPAPI 包裹的 32 字节 AES 密钥)
88
+ └─ Cookies → SQLite,music.163.com 的 cookie 全是 v10 加密
89
+ ```
90
+
91
+ 两步解密:
92
+ 1. **DPAPI(当前用户级)** 解开 `encrypted_key`(base64 → 去掉 `DPAPI` 5 字节前缀 → `CryptUnprotectData`)得到 **AES-256-GCM 密钥**;
93
+ 2. 用该密钥解每条 cookie:`v10(3B) + nonce(12B) + 密文 + tag(16B)` → 得到明文,其中 **`MUSIC_U` 就是登录凭据**,`__csrf` 用于写接口。
94
+
95
+ 拿到 cookie 后按 weapi 规则加密请求体(AES-128-CBC 两次 + RSA 无填充),调用 `music.163.com/weapi/*`。
96
+
97
+ > **安全**:密钥与 cookie 副本只写到系统临时目录,读完立刻 `rmSync` 删除;cookie 只在进程内存里用。所以**每次命令都要重新解一遍**(约 1 秒),这是刻意的设计,不要改成缓存到磁盘。
98
+
99
+ ---
100
+
101
+ ## 三、必须知道的 10 个坑(都是踩过的)
102
+
103
+ ### 坑 1 · 加歌会**倒序**插入
104
+
105
+ `playlist/manipulate/tracks` 把新曲目加到**最前面**,而且**同一批(≤25 首)内部也是倒序**。
106
+ 所以:**想正序显示,就要把数组倒序提交** —— 这就是 `--order` 干的事(内部 `[...ids].reverse()` 后按 25 首分批)。
107
+ 不加 `--order` 时顺序无所谓,只适合「只要歌都进去」的场合。
108
+
109
+ > 由此推论(2026-11-02 实测踩过):**改歌单(删歌/加歌/调序)后要保序,只能整单清空重建**。
110
+ > 「保留前 N 首不动、只重建后半段」是错的——重建段会被插到那 N 首**前面**。
111
+ > `ne import-mbp --sync` 就是这样实现的(原地清空 + 按目标顺序重加,歌单 pid/名字/简介/隐私不变)。
112
+
113
+ ### 坑 2 · 写接口会偶发 `404 歌单不存在`
114
+
115
+ 歌单明明存在、`ne list` 也能读,`add`/`remove` 却返回 `{"code":404,"message":"歌单不存在"}`。**不是权限问题**,隔一两秒重试就成功。
116
+ `ne.mjs` 里已经内置 `retry()`(默认 3 次、间隔 1.5s)覆盖 add / remove / delete。**如果你自己写脚本,务必加重试。**
117
+
118
+ ### 坑 3 · 改名只有一个可用接口
119
+
120
+ | 目标 | 可用 | 不可用 |
121
+ |---|---|---|
122
+ | 改名 | `POST /api/playlist/update/name`(**明文接口**) | `weapi/playlist/update/name`、`weapi/playlist/update` → 全 404 |
123
+ | 改简介 | `weapi/playlist/desc/update` | `weapi/playlist/update`、`/api/playlist/update/desc` → 404 |
124
+ | 改隐私 | `POST /api/playlist/update/privacy`(**明文接口**,body `id` + `privacy`:0 公开 / 10 私密) | `/api/playlist/update` → 404 |
125
+ | 删歌单 | `POST /api/playlist/delete`(body `pid`) | — |
126
+
127
+ > 隐私语义:**公开歌单**别人能看到并「收藏」;**私密歌单**仅自己可见,别人既看不到也收藏不了。网易云**没有全局「默认私密」开关**,想让新歌单不可见需在 `ne create` 时带 `--privacy 10`(或在客户端创建时勾选「私密」)。
128
+
129
+ > 隐私的实测边界(本机验证过):
130
+ > - **只能改自己创建的歌单**;收藏的别人歌单返回 `code=401 无权限操作歌单`(歌单列表里显示但无法修改,想让它们不出现只能取消收藏);
131
+ > - 「我喜欢的音乐」(系统内置歌单)返回 `code=500 请求异常`,**不支持设私密**;
132
+ > - 批量设置时逐个请求、间隔约 0.6s 即可,无风控问题。
133
+
134
+ ### 坑 4 · PowerShell 脚本必须**纯 ASCII**
135
+
136
+ Windows PowerShell 5.1 读无 BOM 的 UTF-8 文件会按 ANSI 解码,中文字符串会被撑坏 → 解析报错(`The string is missing the terminator`)。
137
+ 本 skill 的 `extract-key.ps1` / `Dpapi.cs` **刻意全英文**,中文提示都放在 `ne.mjs`。修改这两个文件时不要加中文。
138
+
139
+ ### 坑 5 · 不要用 here-string 传 C#
140
+
141
+ `Add-Type -TypeDefinition @"..."@` 在 LF 换行的 `.ps1` 里可能不被识别(脚本被当成语句逐行解析)。
142
+ C# 源码单独放 `Dpapi.cs`,用 `Add-Type -Path`。
143
+
144
+ ### 坑 6 · 搜索结果严重污染,必须校验艺人
145
+
146
+ 同名曲目第一名经常是**翻唱 / remix / Live / bootleg / 合辑版**。挑选规则:
147
+
148
+ 1. 艺人名必须与目标艺人**基本一致**(`artists` 逐段比对);
149
+ 2. 排除名字里含 `remix / instrumental / live / cover / bootleg / karaoke / sped up / 伴奏 / DJ版 / 钢琴版` 的条目;
150
+ 3. 仍不确定就查**艺人主页热歌**(`/api/v1/artist/{id}`)或**专辑曲目**(`/api/v1/album/{id}`)确认官方版本;
151
+ 4. 韩语原名曲目(`뿜뿜`、`까탈레나`、`립스틱`)用英文名搜不到,按韩文搜。
152
+
153
+ **版权现实**:HYBE 系(NewJeans、LE SSERAFIM、ILLIT)以及部分欧美曲目在大陆区常**只有 remix / Live / 日文版**,热门歌曲和专辑里都查过还是找不到原版——这时应如实告知,不要用替代版本冒充原版。
154
+
155
+ ### 坑 7 · `fee` 字段含义
156
+
157
+ | fee | 含义 |
158
+ |---|---|
159
+ | `0` | 免费 |
160
+ | `1` | VIP 曲目(歌单能加、能收藏,播放需会员) |
161
+ | `8` | 免费/低音质(高音质需会员) |
162
+
163
+ ### 坑 8 · 下载必须用「官方下载接口」,流媒体 CDN 会 403
164
+
165
+ - ✅ 可用:`weapi/song/enhance/download/url/v1`(body `{id, level}`,`level` = `exhigh`(320k) / `standard`(128k) / `lossless`)返回的 URL **可直接 GET 下载**;
166
+ - ❌ 不可用:`/api/song/enhance/player/url` 返回的流媒体链接(`m704.music.126.net` / `m804.music.126.net` 等)**一律 403**(Tengine 防盗链)——UA / Referer / Cookie / curl / node fetch 全试过,均失败;
167
+ - `download/url/v1` 对免费歌和 VIP 歌都能返回可下载 URL,是否成功主要看 CDN,与会员无关;
168
+ - 文件命名 `NN - 艺人 - 歌名.mp3`;已存在且 >500KB 自动跳过(支持断点续传);
169
+ - 下载得到的是**原始 mp3 文件**(非加密 ncm),**不需要 NCM 转换器**。
170
+
171
+ ### 坑 9 · `.mbp` 的前缀长度**不是固定的**
172
+
173
+ MusicBee 播放列表文件结构是 `[前缀][int32 曲目数][每条:1 字节长度 + UTF-8 绝对路径 + FF FF FF FF]`,
174
+ 但这个**前缀长度因库而异**(本机实测 52 字节,也有资料写 53)。写死偏移会解析出乱码或 `Invalid array length`。
175
+ `mbp.mjs` 的做法:从 40~120 字节逐个偏移试解,**要求「解析到文件末尾恰好结束」**才采纳——换库也不会错。
176
+
177
+ ### 坑 10 · 改这些 `.mjs` 不要用 PowerShell 的 `-replace` / `Set-Content`
178
+
179
+ 实测(2026-11-02):用 `(Get-Content -Raw x) -replace ... | Set-Content x` 批量改 `mbp-import.mjs`,
180
+ 文件里的中文全被写成 `U+FFFD`(56 处乱码),脚本表面还能跑但提示语全废。
181
+ **改这些脚本请用编辑器(edit/write 工具)**;实在要命令行改,用 Node:`fs.writeFileSync(p, s, 'utf8')`。
182
+
183
+ ---
184
+
185
+ ## 四、MusicBee `.mbp` 歌单批量导入(`ne import-mbp`)
186
+
187
+ 一条链路:**解析 MusicBee 歌单 → 读本地标签 → 网易云搜索打分匹配 → 建歌单按原顺序加歌 → 复核**。
188
+
189
+ ```bat
190
+ :: 最常用:把「1blues」「2非blues」两个分组整组搬上云端(默认私密)
191
+ scripts\ne.cmd import-mbp --groups 1blues,2非blues --dry-run :: 先空跑,只看匹配情况
192
+ scripts\ne.cmd import-mbp --groups 1blues,2非blues :: 确认后正式导入
193
+
194
+ :: 指定目标(单个 .mbp / 某个分组目录 / Playlists 根目录)
195
+ scripts\ne.cmd import-mbp "C:\Users\me\Music\myMusic\Playlists\1blues"
196
+ :: 公开歌单 + 自定义工作目录 + 放宽匹配阈值
197
+ scripts\ne.cmd import-mbp --groups 3dj --privacy 0 --workdir D:\ne-import --min-score 0.66
198
+ ```
199
+
200
+ **目标自动探测**:不传目标时读 `%APPDATA%\MusicBee\MusicBee3Settings.ini` 里的 `<ENV_LibPath>` → `<库>\Playlists`。
201
+ `--groups` 只对「Playlists 根目录」生效(子文件夹名就是 MusicBee 面板里的分组);直接给分组目录或单个 `.mbp` 时无需它。
202
+
203
+ **阶段与参数**
204
+
205
+ | 参数 | 作用 |
206
+ |---|---|
207
+ | (不给阶段参数) | 全跑 `build → match → rescue → create → verify` |
208
+ | `--build` | 只解析 `.mbp` + 读标签,写 `tracks.json` |
209
+ | `--match` | 只做搜索匹配(带缓存,重跑很快) |
210
+ | `--rescue` | 只对未匹配曲目按**艺人页**二次救援 |
211
+ | `--create` | 只建歌单 + 加歌 |
212
+ | `--sync` | **本地歌单改过之后同步云端**:补新增、删多余的、按 MusicBee 顺序整单重建(pid/名字/简介/隐私不变) |
213
+ | `--verify` | 只复核云端(曲目数 / 隐私 / 顺序) |
214
+ | `--dry-run` | 空跑:只报告会做什么,**不写云端、也不写结果文件** |
215
+ | `--reuse` | 云端已有同名歌单时不跳过,只补缺失曲目(顺序不保证) |
216
+ | `--privacy 0\|10` | 默认 `10` 私密 |
217
+ | `--min-score` | 匹配阈值,默认 `0.72` |
218
+ | `--limit N` | 只处理前 N 首(调试用) |
219
+ | `--workdir` | 状态目录,默认 `%USERPROFILE%\netease-import` |
220
+
221
+ **匹配打分**:`标题 0.5 / 艺人 0.34 / 时长 0.16`,命中专辑再 +0.06;候选名里出现
222
+ `remix / live / cover / instrumental / 伴奏 / DJ版 / 降调 / 钢琴版 / 串烧` 等且本地标题没有,每项 −0.22。
223
+ 标题归一化后完全一致 1.0、包含 0.86 / 0.8、否则按词重合;艺人逐段比对(一致 1.0、包含 0.85);时长差 ≤3s 满分、>45s 记 0。
224
+ 低于阈值**宁可不加**,绝不拿翻唱/remix 冒充原版;没命中的都留在 `matches.json` 的 `top3` 里便于人工核对。
225
+
226
+ **状态文件**(全在 `--workdir`):`tracks.json`(曲目+标签)、`search-cache.json`(搜索缓存)、
227
+ `matches.json`(每首匹配结果与候选)、`import-result.json`(歌单 id 映射,**续跑依据**)、`导入报告.md`。
228
+
229
+ **本地歌单改过之后怎么办(`--sync`)**
230
+
231
+ ```bat
232
+ :: 先空跑看差异(新增几首、删掉几首)
233
+ scripts\ne.cmd import-mbp "C:\Users\me\Music\myMusic\Playlists\3dj\2026-11-06 blues舞会.mbp" ^
234
+ --workdir D:\ne-import --sync --dry-run
235
+ :: 确认后正式同步
236
+ scripts\ne.cmd import-mbp "C:\...\2026-11-06 blues舞会.mbp" --workdir D:\ne-import --sync
237
+ ```
238
+
239
+ - 会按**当前** `.mbp` 重新解析、重新匹配,然后把云端歌单改成与之一致;
240
+ - 因为接口只会把新曲目插到最前、且没有重排能力,实现上是**原地清空 → 按目标顺序重加**,
241
+ 歌单 pid、名字、简介、隐私设置全部保留(**不要**改成「只补尾部」,顺序会错,见坑 1);
242
+ - 目标曲目为空(一首都没匹配到)时不动云端,避免把歌单清空;
243
+ - 同步后自动 `verify`:曲目数、隐私、顺序逐项核对,并写进报告。
244
+
245
+ **行为约定**
246
+
247
+ - 建歌单后写简介「来自 MusicBee 歌单 分组/歌单名|本地 N 首,匹配 M 首」;
248
+ - 加歌走倒序提交 + 25 首分批,**歌单内顺序与 MusicBee 完全一致**(`--verify` 逐单核对);
249
+ - 云端已有同名歌单默认跳过(防重复建单);`import-result.json` 里已记录的也跳过;
250
+ - 中途断开直接重跑同一条命令即可续:已建的跳过,只补没做完的;
251
+ - 本地没有可匹配曲目的歌单(如只有一段现场录音)不会建空歌单,会写进报告;
252
+ - 实测规模参考:19 个歌单 / 417 首,匹配 414 首(其中 7 首靠艺人页救援),全程约 6 分钟。
253
+
254
+ **依赖**:这条链路只用 Node——标签读取内置在 `tagread.mjs`(ID3v2.2/2.3/2.4 + FLAC 的 title/artist/album/时长),
255
+ 已用 mutagen 结果对 417 首逐一比对**完全一致**,不需要 Python。
256
+
257
+ ---
258
+
259
+ ## 五、排错
260
+
261
+ | 现象 | 原因 / 处理 |
262
+ |---|---|
263
+ | `找不到网易云客户端目录` | 客户端没装或路径变了;确认 `%LOCALAPPDATA%\Netease\CloudMusic\webapp91x64` 存在 |
264
+ | `解出的 cookie 中没有 MUSIC_U` | 客户端当前未登录 → 打开客户端登录后重试 |
265
+ | `提取客户端凭据失败` | DPAPI 只能在**登录该客户端的同一 Windows 用户**下解;换用户/管理员身份运行会失败 |
266
+ | `未登录(code=301)` | cookie 已失效 → 重启客户端并重新登录 |
267
+ | `加歌失败 code=-460` | 触发风控/频率限制 → 增大间隔(`ne.mjs` 里 `sleep(1100)`)后重试 |
268
+ | `code=404 歌单不存在` 反复失败 | 歌单可能真被删了;先 `ne list` 确认 |
269
+ | `设置隐私后复查未生效` | 确认歌单 id 正确;用 `/api/user/playlist` 复核 `privacy` 字段(0=公开、10=私密) |
270
+ | `下载 403` | 必须用 `download/url/v1` 获取链接;不要用 `player/url` 的流媒体链接(会 403) |
271
+ | `import-mbp` 报「不是可解析的 .mbp」 | 文件不是 MusicBee 播放列表,或格式已变 → 看下文件开头是否为库路径字符串 |
272
+ | `import-mbp` 大面积「未匹配」 | 曲目没有标签且文件名不含「艺人 - 歌名」;先补标签,或放宽 `--min-score` 后人工核对 `matches.json` |
273
+ | `import-mbp` 建出重复歌单 | 同名判定基于云端歌单名;确认没手动改过名字,或先删旧单再跑 |
274
+ | `import-mbp` 空跑却打印「跳过」 | `--dry-run` 下所有动作只报告不执行,属正常 |
275
+
276
+ 调试:设环境变量 `NE_DEBUG=1`,会打印每个 weapi/明文请求的接口与载荷(不含 cookie)。
277
+
278
+ ---
279
+
280
+ ## 六、文件
281
+
282
+ ```
283
+ scripts/
284
+ ├─ ne.cmd CLI 入口(Windows)
285
+ ├─ ne.mjs 主程序:解 cookie、weapi 加密、全部命令(同时导出核心函数供 import-mbp 复用)
286
+ ├─ mbp-import.mjs ne import-mbp 实现:解析→匹配打分→建单加歌→复核→报告
287
+ ├─ mbp.mjs .mbp 二进制解析(前缀长度自适应)
288
+ ├─ tagread.mjs 内置标签读取(ID3v2 / FLAC),零第三方依赖
289
+ ├─ extract-key.ps1 DPAPI 解出 AES 密钥 + 复制 Cookies(纯 ASCII)
290
+ └─ Dpapi.cs ProtectedData 不可用时的 P/Invoke 回退(纯 ASCII)
291
+ ```
292
+
293
+ **边界**:本 skill 只处理「云端歌单」与「MusicBee 歌单 → 云端」的搬运。本地音频剪辑/转码不在这里(那是 ffmpeg 的活);改 `.mbp` 文件本身用 `musicbee` 技能。