Skip to content

Download Apple Music tracks in ALAC (Apple Lossless) format using Python and Frida. For personal use only.

License

Notifications You must be signed in to change notification settings

w3Abhishek/AppleMusicDL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apple Music ALAC Downloader

Download Apple Music tracks in ALAC (Apple Lossless Audio Codec) format with complete metadata.

⚠️ Disclaimer

This tool is for personal use only. Downloading copyrighted content may violate Apple's Terms of Service and local laws. Use responsibly and only for music you have the right to download.

Features

  • ✅ Downloads in ALAC (Apple Lossless) format
  • ✅ Preserves full quality audio
  • ✅ Embeds complete iTunes metadata (title, artist, album, year, composer, ISRC, UPC, etc.)
  • ✅ Downloads album artwork
  • ✅ Supports full album downloads
  • ✅ Automatic file organization
  • ✅ FairPlay DRM decryption via Frida

Requirements

System Requirements

  • Python 3.8 or higher
  • Android Studio with Android Emulator
  • ADB (Android Debug Bridge)
  • Frida and frida-tools
  • Active Apple Music subscription

Python Dependencies

  • httpx >= 0.27.0
  • m3u8 >= 3.5.0
  • construct >= 2.10.68
  • frida >= 16.0.0
  • frida-tools >= 12.0.0

Installation

1. Clone the Repository

git clone https://github.com/w3Abhishek/AppleMusicDL.git
cd AppleMusicDL

2. Install Python Dependencies

pip install -r requirements.txt

Or install in development mode:

pip install -e .

3. Set Up Android Emulator

  1. Create a virtual device in Android Studio

    • Use an image without Google APIs (important for Frida compatibility)
    • Recommended: Android 10 (API 29) or Android 11 (API 30)
  2. Install Apple Music APK

  3. Sign in to Apple Music

    • Launch Apple Music on the emulator
    • Sign in with your Apple Music account (subscription required)

4. Set Up Frida

  1. Download Frida Server
# Get Frida version
frida --version

# Download matching frida-server for Android
# Visit: https://github.com/frida/frida/releases
# Example for x86_64 emulator:
wget https://github.com/frida/frida/releases/download/16.0.0/frida-server-16.0.0-android-x86_64.xz
unxz frida-server-16.0.0-android-x86_64.xz
  1. Push Frida Server to Emulator
adb root
adb push frida-server-16.0.0-android-x86_64 /data/local/tmp/frida-server
adb shell "chmod 755 /data/local/tmp/frida-server"
  1. Start Frida Server
adb shell "/data/local/tmp/frida-server &"
  1. Verify Frida is Running
frida-ps -U

5. Port Forwarding

Forward the Frida agent port:

adb forward tcp:10020 tcp:10020

Usage

1. Start Frida Agent

In a separate terminal, run:

frida -U -l agent.js -f com.apple.android.music

Keep this running while downloading.

2. Download Albums

python main.py <album_url> [<album_url> ...]

Example:

python main.py https://music.apple.com/us/album/whenever-you-need-somebody-2022-remaster/1624945511

Multiple albums:

python main.py \
  https://music.apple.com/us/album/album1/123456 \
  https://music.apple.com/us/album/album2/789012

Output

Downloaded files are organized in the AM-DL downloads directory:

AM-DL downloads/
└── Artist Name - Album Name/
    ├── cover.jpg
    ├── 01. Track Name.m4a
    ├── 02. Track Name.m4a
    └── ...

Architecture

Project Structure

AppleMusicDL/
├── apple_music_dl/          # Main package
│   ├── __init__.py          # Package initialization
│   ├── api.py               # Apple Music API client
│   ├── m3u8_parser.py       # M3U8 playlist parser
│   ├── mp4_handler.py       # MP4 container handler
│   ├── decryptor.py         # Frida-based decryptor
│   ├── metadata.py          # MP4 metadata writer
│   ├── models.py            # Data models
│   └── utils.py             # Utility functions
├── agent.js                 # Frida agent (JavaScript)
├── main.py                  # Main entry point
├── requirements.txt         # Python dependencies
├── pyproject.toml           # Project metadata
└── README.md                # Documentation

Component Overview

  1. API Client (api.py): Handles authentication and metadata retrieval from Apple Music API
  2. M3U8 Parser (m3u8_parser.py): Extracts stream URLs and encryption keys from playlists
  3. MP4 Handler (mp4_handler.py): Parses fragmented MP4 containers and extracts ALAC parameters
  4. Decryptor (decryptor.py): Communicates with Frida agent via socket for FairPlay decryption
  5. Metadata Writer (metadata.py): Constructs MP4/M4A files with complete iTunes metadata
  6. Frida Agent (agent.js): JavaScript agent running on Android for DRM decryption

How It Works

  1. Authentication: Extracts bearer token from Apple Music web interface
  2. Metadata Retrieval: Fetches album and track metadata via API
  3. Stream Discovery: Parses M3U8 playlists to find ALAC streams
  4. Download: Downloads encrypted fragmented MP4 files
  5. Parsing: Extracts ALAC codec parameters and encrypted samples
  6. Decryption: Sends samples to Frida agent for FairPlay decryption
  7. Reconstruction: Builds complete M4A file with decrypted audio and metadata

Troubleshooting

"Failed to connect to Frida agent"

  • Ensure Frida server is running on the emulator: adb shell ps | grep frida
  • Check port forwarding: adb forward tcp:10020 tcp:10020
  • Verify Frida agent is loaded: frida -U -l agent.js -f com.apple.android.music

"Unavailable in ALAC"

  • Some tracks may not be available in lossless format
  • Ensure you have an active Apple Music subscription
  • Try a different region/storefront

"Failed to get token"

  • Check your internet connection
  • Apple may have changed their web interface structure
  • Try clearing browser cache or use a VPN

"Decryption size mismatch"

  • The encryption key list doesn't match the sample count
  • Try re-downloading the track
  • Check Frida agent logs for errors

Development

Running Tests

python -m pytest tests/

Code Style

This project follows PEP 8 guidelines. Format code with:

black apple_music_dl/
isort apple_music_dl/

Building Distribution

python -m build

Credits

  • Uses Frida for dynamic instrumentation

License

Mozilla Public License 2.0 (MPL-2.0)

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

Support

For issues and questions:

  • Open an issue on GitHub
  • Provide detailed error messages and logs
  • Include your Python version and OS

Remember: This tool is for personal use only. Respect copyright laws and Apple's Terms of Service.

About

Download Apple Music tracks in ALAC (Apple Lossless) format using Python and Frida. For personal use only.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published