@chenhao6682108/dsh-skill-netease-playlist 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenhao6682108/dsh-skill-netease-playlist",
|
|
3
|
-
"version": "0.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",
|
|
@@ -52,6 +52,12 @@ CLI 入口:`scripts/ne.cmd`(Windows,内部调用 `node scripts/ne.mjs`,
|
|
|
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
|
## 一、命令一览
|
|
@@ -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
|
-
$
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
$
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
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 });
|