AppleMusic Downloader
AppleMusic Downloader 是一个功能强大的 Apple Music 下载工具,支持下载歌曲、音乐视频、歌词和封面。
项目提供三种使用方式:
| 方式 | 适用场景 |
|---|---|
| CLI 命令行 | 终端用户,通过pip install applemusic-dl 安装即可使用 |
| API 服务 | 开发者,将下载能力集成到自己的应用中 |
| 桌面应用 | 普通用户,下载打包好的安装程序直接使用 |
致谢
本项目使用了 gamdl (Glomatico's Apple Music Downloader) 和 yt-dlp 的代码。衷心感谢 gamdl 和 yt-dlp 的所有贡献者在开源社区做出的杰出贡献。
目录
安装方式
方式一:pip 安装(推荐)
pip install applemusic-dl
安装后可直接使用 amdl 命令:
amdl --help
如果需要桌面 GUI 模式,请安装带桌面依赖的版本:
pip install applemusic-dl[desktop]
方式二:桌面安装程序(仅限 Windows)
- 从 Releases 页面下载最新安装程序
- 运行
AppleMusicDownloader_Setup.exe按提示完成安装 - 在开始菜单中找到 "Apple Music Downloader"
方式三:从源码运行
git clone https://github.com/wenfeng110402/AppleMusic-Downloader.git
cd AppleMusic-Downloader
pip install -r requirements.txt
pip install -e .
CLI 命令行使用
# 查看帮助
amdl --help
# 下载单曲
amdl -c /path/to/cookies.txt "https://music.apple.com/cn/album/left-and-right/1630451412?i=1630451413"
# 下载整张专辑
amdl -c /path/to/cookies.txt "https://music.apple.com/cn/album/left-and-right/1630451412"
# 指定输出目录
amdl -c /path/to/cookies.txt -o "./My Music" "https://music.apple.com/..."
# 指定音频编码和格式
amdl -c /path/to/cookies.txt --codec-song aac-256k --audio-format mp3 "https://music.apple.com/..."
API 服务部署
项目内置了 FastAPI 后端,可独立部署为 API 服务,供其他应用调用。
启动 API 服务
# 安装后直接启动
python -m amdl --server
# 自定义端口
python -m amdl --server --port 8080
# 允许外部访问(生产环境请配置反向代理)
python -m amdl --server --host 0.0.0.0 --port 8000
服务启动后访问 http://127.0.0.1:8000 可查看 API 文档(Swagger UI)。
API 端点概览
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /api/health |
健康检查 |
| GET | /api/info |
获取支持的编码、格式等选项 |
| GET | /api/dependencies |
检查外部依赖(ffmpeg, N_m3u8DL-RE) |
| POST | /api/tasks |
提交下载任务 |
| GET | /api/tasks |
获取所有任务列表 |
| GET | /api/tasks/{task_id} |
获取单个任务详情 |
| DELETE | /api/tasks/{task_id} |
取消任务 |
| WebSocket | /api/ws/{task_id} |
实时下载进度推送 |
| GET | /api/settings |
读取用户偏好设置 |
| POST | /api/settings |
保存用户偏好设置 |
| DELETE | /api/temp |
清理临时目录 |
详细 API 文档请参见 docs/api.md。
API 客户端示例
Python 调用:
import requests
# 提交下载任务
resp = requests.post("http://127.0.0.1:8000/api/tasks", json={
"urls": ["https://music.apple.com/cn/album/left-and-right/1630451412?i=1630451413"],
"cookies_path": "/path/to/cookies.txt",
"output_path": "./Apple Music"
})
task = resp.json()
print(f"Task ID: {task['task_id']}")
# 查询任务状态
import time
while True:
status = requests.get(f"http://127.0.0.1:8000/api/tasks/{task['task_id']}").json()
print(f"Status: {status['status']}, Progress: {status['progress']}")
if status["status"] in ("completed", "failed", "cancelled"):
break
time.sleep(3)
curl 调用:
# 提交任务
curl -X POST http://127.0.0.1:8000/api/tasks \
-H "Content-Type: application/json" \
-d '{
"urls": ["https://music.apple.com/cn/album/left-and-right/1630451412"],
"cookies_path": "/path/to/cookies.txt"
}'
# 查询任务
curl http://127.0.0.1:8000/api/tasks/<task_id>
WebSocket 实时进度(Python):
import asyncio
import websockets
import json
async def listen_progress(task_id: str):
uri = f"ws://127.0.0.1:8000/api/ws/{task_id}"
async with websockets.connect(uri) as ws:
# 发送 ping 保持连接
await ws.send(json.dumps({"type": "ping"}))
async for msg in ws:
data = json.loads(msg)
print(f"进度: {data}")
if data.get("type") == "completed":
break
asyncio.run(listen_progress("your-task-id"))
前端部署
项目包含一个基于 Next.js 的 Web 前端,可直接部署供用户使用。
前端功能特性
Web 前端提供了一套完整的图形界面,包括:
- 中/英双语界面(i18n) — 一键切换语言
- 深色/浅色主题 — CSS 变量驱动,支持明暗切换
- 后端在线状态指示 — 侧边栏红绿点实时反馈后端状态
- 下载表单 — 支持多 URL 输入、文件浏览选择器(桌面端调用系统对话框)
- 音频格式选择 — 支持 MP3/FLAC/WAV/AAC 等格式转换
- 设置持久化 — 每次修改自动保存至后端,刷新不丢失
- 下载队列 — 实时任务列表、进度条、自动刷新(3 秒间隔)
- 任务日志 — 可展开查看每个任务的详细运行日志
- 依赖检测 — 一键检查 FFmpeg / N_m3u8DL-RE 等外部工具是否就绪
- 深色风格 UI — 磨砂玻璃质感、沉浸式暗黑设计
开发模式
cd src/fronted
npm install
npm run dev
开发模式下前端运行在 http://localhost:3000,API 请求自动代理到 http://127.0.0.1:8000。
需要同时启动后端:
python -m amdl --server
生产模式
cd src/fronted
npm install
npm run build
构建产物在 src/fronted/out/ 目录,可直接部署到任意静态文件服务器(Nginx、Caddy 等)。
Nginx 配置示例:
server {
listen 80;
server_name your-domain.com;
# 前端静态文件
root /path/to/src/fronted/out;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# API 反向代理到后端
location /api/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Docker 部署:
# 后端
docker run -d --name amdl-api \
-p 8000:8000 \
-v /path/to/cookies.txt:/cookies.txt \
-v /path/to/output:/output \
--restart unless-stopped \
python:3.10-slim \
sh -c "pip install applemusic-dl && python -m amdl --server --host 0.0.0.0"
# 前端(使用 Nginx 提供静态文件)
docker run -d --name amdl-frontend \
-p 80:80 \
-v /path/to/src/fronted/out:/usr/share/nginx/html \
--restart unless-stopped \
nginx:alpine
桌面应用
在桌面模式下,后端服务和前端 Web UI 集成在同一个窗口中:
# 启动桌面应用
python -m amdl --desktop
# 或直接启动(自动检测)
python -m amdl
桌面应用基于 pywebview,在 Windows、macOS、Linux 上均可用。
🐧 Linux 用户请注意:pywebview 在 Linux 上依赖 Qt WebEngine,启动桌面模式前需要先安装系统依赖:
sudo apt update && sudo apt install -y python3-pyqt5 python3-pyqt5.qtwebengine libqt5webkit5-dev pip install pywebview[qt]
环境要求
必需
- Python 3.10 或更高版本
- 有效的 Apple Music 订阅
- Netscape 格式的 Cookies 文件
- FFmpeg
获取 Cookies 文件:
- Firefox 用户:使用 Export Cookies 扩展
- Chromium 用户:使用 Open Cookies.txt 扩展
安装 FFmpeg:
- macOS:
brew install ffmpeg - Linux:
apt install ffmpeg/pacman -S ffmpeg - Windows: 从 ffmpeg.org 下载
可选
- mp4decrypt:用于音乐视频下载和实验性音频编码
- MP4Box:替代混流模式
- N_m3u8DL-RE:替代下载模式
支持的链接类型
- 单曲
- 专辑
- 播放列表
- 音乐视频
- 艺术家主页
- 帖子视频
项目结构
AppleMusic-Downloader/
├── src/
│ ├── amdl/ # Python 后端包
│ │ ├── server.py # FastAPI 服务入口
│ │ ├── cli.py # CLI 命令行入口
│ │ ├── core_downloader.py # 下载核心逻辑
│ │ ├── task_manager.py # 任务队列管理
│ │ ├── converter.py # 格式转换
│ │ └── ...
│ └── fronted/ # Next.js 前端
│ ├── app/
│ │ ├── components/ # 前端组件
│ │ ├── service.tsx # API 调用封装
│ │ └── i18n.tsx # 国际化
│ └── next.config.ts
├── docs/
│ └── api.md # API 文档
├── pyproject.toml # 包配置
├── requirements.txt
└── README.md
免责声明
本工具仅供学习与研究使用,严禁将其用于任何违反法律法规或侵犯他人权益的用途。
- 本项目不直接提供或存储任何受版权保护的内容,用户需自行提供合法的凭证(如有效的 Apple Music 订阅和 Cookies 文件)以使用相关功能。
- 本人不对用户如何使用本工具承担任何责任,因使用本工具产生的任何法律或版权争议,均由用户自行承担。
- 本项目基于 gamdl 和 yt-dlp 提供的代码实现,与原项目的作者无直接关联。如有任何异议,请联系本人以便协助处理。
- 用户在使用本工具时,应自行确保符合当地相关法律法规。
By using this tool, you agree to comply with all applicable laws and assume full responsibility for your actions.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file applemusic_dl-2.4.7.tar.gz.
File metadata
- Download URL: applemusic_dl-2.4.7.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e93d5ae8b24e57208e98e58d71f12facf365bc47bc28a4812e89ed15336d4acd
|
|
| MD5 |
ab841be5ffdef2678ca8ff971b060caa
|
|
| BLAKE2b-256 |
38988d1fd8aba94fbe56275286f5a94421337d24fda61f4ce4e143cd39c9f8d6
|
File details
Details for the file applemusic_dl-2.4.7-py3-none-any.whl.
File metadata
- Download URL: applemusic_dl-2.4.7-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
561a2b23997bb61b8af33f64b4ecda73895bd228ce3010368d1cc89cf6944700
|
|
| MD5 |
851f4dc7555be7757d9c4bd564e970de
|
|
| BLAKE2b-256 |
2060b16d00adc545536ae0256a3b802a29df12e5b1d2d49ee62a2e2377cd30e9
|