Files
2026-06-08 22:33:23 +08:00

137 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ncmdump-go
基于 [ncmdump](https://github.com/taurusxin/ncmdump) 的 Golang 移植版,支持网易云音乐 `.ncm` 文件解密为 MP3 / FLAC。
提供两种使用方式:**Web 图形界面** 和 **命令行工具**
## Web 界面(WASM,推荐)
所有加解密在浏览器本地完成,**不会上传你的文件到任何服务器**。解密引擎使用 Go 编译为 WebAssembly,性能接近原生。
### 使用
1. 打开网页
2. 选择包含 `.ncm` 文件的**输入文件夹**
3. 选择**输出文件夹**
4. 点击「开始转换」
歌曲名、歌手、专辑信息以及封面图片会自动写入转换后的文件中。
> 要求:Chrome / Edge 浏览器,通过 `localhost` 或 HTTPS 访问。
### 直接运行
从 [Releases](https://git.taurusxin.com/taurusxin/ncmdump-go/releases/latest) 下载对应平台的 `ncmdump-web` 二进制,或自行编译:
```shell
./build-wasm.sh
# 单机使用
./ncmdump-web --port 8080
# 浏览器访问 http://localhost:8080
```
### 局域网使用
`localhost` 下浏览器要求 HTTPS 才能启用文件夹选择功能。用 [mkcert](https://github.com/FiloSottile/mkcert) 生成自签名证书:
```shell
# 在运行服务器的机器上,替换为实际 IP
mkcert -install
mkcert 192.168.1.100 localhost
# 启动
./ncmdump-web --port 8080 --cert 192.168.1.100+1.pem --key 192.168.1.100+1-key.pem
```
然后局域网内其他设备访问 `https://192.168.1.100:8080` 即可正常使用。
### 交叉编译
纯 Go,无 CGO 依赖,可交叉编译到任意平台:
```shell
# Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o ncmdump-web.exe ./cmd/server
# macOS (Intel)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server
# macOS (Apple Silicon)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server
# Linux (arm64)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server
```
编译出的二进制约 15MB,前端和 WASM 运行时全部内嵌,拷贝到目标机器直接运行。
### Docker 部署
```shell
docker compose up -d --build
# 访问 http://localhost:8080
```
如需提取二进制单独部署:
```shell
docker cp $(docker create ncmdump-web):/usr/local/bin/ncmdump-server ./ncmdump-web
```
## 命令行
### 安装
```shell
go install git.taurusxin.com/taurusxin/ncmdump-go@latest
```
### 使用
```shell
# 单文件
ncmdump-go song.ncm
# 批量处理目录(不递归子目录)
ncmdump-go -d source_dir
# 递归处理 + 指定输出目录
ncmdump-go -d source_dir -r -o output_dir
```
### 作为库使用
```
go get -u git.taurusxin.com/taurusxin/ncmdump-go
```
```go
import "git.taurusxin.com/taurusxin/ncmdump-go/ncmcrypt"
ncm, _ := ncmcrypt.NewNeteaseCloudMusic("song.ncm")
ncm.Dump("/path/to/output")
ncm.FixMetadata(true)
fmt.Println(ncm.GetDumpFilePath())
```
## 项目结构
```
├── main.go # CLI 命令行入口
├── ncmcrypt/ # 核心加解密库
│ ├── ncmcrypt.go # NCM 格式解析 / RC4 解密
│ ├── metadata.go # 元数据解析(歌名/歌手/封面URL)
│ └── embed.go # 内存写入 ID3 / FLAC 标签
├── utils/ # AES / 文件工具
├── cmd/
│ ├── wasm/main.go # WASM 编译入口(浏览器端)
│ └── server/main.go # 静态文件服务器
├── web/ # 前端(React + Tailwind
└── Dockerfile # 多阶段构建
```
## License
MIT