[ GUIDE BY 0dx ]

How to setup ALAC downloader (windows).

Installing choco

To make this easier, first we need choco, a package manager for windows.
Create a .ps1 file in your desktop and paste this code, then right click, run it as admin:

# Check if the script is running with administrative privileges
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    # Restart the script with administrative privileges
    Start-Process powershell.exe -Verb RunAs -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"")
    Exit
}

# Set TLS 1.2 as the default protocol for better security
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

# Check if Chocolatey is already installed
$chocoInstallPath = "$env:ALLUSERSPROFILE\chocolatey\bin"
if (-not (Test-Path $chocoInstallPath)) {
    # Download and install Chocolatey
    Set-ExecutionPolicy Bypass -Scope Process -Force
    Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
else {
    Write-Host "Chocolatey is already installed."
}

# Install Go Lang
if (-not (Get-Command -Name "go" -ErrorAction SilentlyContinue)) {
    choco install -y golang
}
else {
    Write-Host "Go is already installed."
}

# Install Python
if (-not (Get-Command -Name "python" -ErrorAction SilentlyContinue)) {
    choco install -y python
}
else {
    Write-Host "Python is already installed."
}

# Install 7-Zip
if (-not (Get-Command -Name "7z" -ErrorAction SilentlyContinue)) {
    choco install -y 7zip.commandline
}
else {
    Write-Host "7-Zip is already installed."
}

# Install adb
if (-not (Get-Command -Name "adb" -ErrorAction SilentlyContinue)) {
    choco install -y adb
}
else {
    Write-Host "adb is already installed."
}

# Install GPAC (mp4box)
choco install gpac

# Install Android Studio
choco install -y androidstudio --package-parameters="/AddToDesktop"

# Install frida-tools
pip install frida-tools

# Install webdriver-manager
pip install webdriver-manager

# Install selenium
pip install selenium

# Pause and wait for user input
Write-Host "TYPE [continue] ONCE YOU FINISHED THE ANDROID STUDIO AVD SETUP AND THE AVD IS ALREADY RUNNING: "
$userInput = Read-Host
while ($userInput.ToLower() -ne "continue") {
    Write-Host "Please type [continue] to proceed."
    $userInput = Read-Host
}

# Start the specified AVD instance
Start-Process -FilePath $emulatorPath -ArgumentList "-avd $avdName" -NoNewWindow

# Check if the script is running with administrative privileges
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    # Restart the script with administrative privileges
    Start-Process powershell.exe -Verb RunAs -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"")
    Exit
}

# Download the APK files
$apkUrl1 = "https://f-droid.org/repo/com.aefyr.sai.fdroid_60.apk"
$apkUrl2 = "https://gitlab.com/0daxelagnia/appleapkm/-/raw/main/apple_music.apkm?ref_type=heads&inline=false"
$apkFile1 = "$env:TEMP\com.aefyr.sai.fdroid_60.apk"
$apkFile2 = "$env:TEMP\app.apkm"

Invoke-WebRequest -Uri $apkUrl1 -OutFile $apkFile1
Invoke-WebRequest -Uri $apkUrl2 -OutFile $apkFile2


# Start adb as root
adb root

# Install the first APK file
adb install $apkFile1

# Push the second APK file to the device's Download folder
adb push $apkFile2 "/storage/emulated/0/Download/app.apkm"

# Download Frida server for Android
$fridaServerUrl = "https://github.com/frida/frida/releases/download/16.2.1/frida-server-16.2.1-android-x86_64.xz"
$fridaServerFile = "$env:TEMP\frida-server.xz"
Invoke-WebRequest -Uri $fridaServerUrl -OutFile $fridaServerFile

# Extract Frida server
$extractPath = "$env:TEMP\frida-server"
New-Item -ItemType Directory -Path $extractPath -Force | Out-Null
7z.exe x $fridaServerFile -o"$extractPath" | Out-Null

# Find the extracted Frida server file
$fridaServerExtracted = Get-ChildItem -Path $extractPath -Filter "frida-server*" -File | Select-Object -First 1

# Rename Frida server file
$fridaServerRenamedPath = Join-Path $extractPath "frida"
Move-Item -Path $fridaServerExtracted.FullName -Destination $fridaServerRenamedPath -Force

# Push Frida server to the device
adb push $fridaServerRenamedPath "/data/local/tmp/frida"

# Clean up downloaded files and extracted directory
Remove-Item $apkFile1, $fridaServerFile, $extractPath -Recurse

Once android studio is installed, open it and follow these steps:

  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag

Wait till it is done downloading!

  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag

Wait till it is done downloading!

  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag

Type continue in the powershell console.

Now in the Android window, follow these steps:

  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag
  • Alt Tag

Here you have to sign in with your account

  • Alt Tag
  • Alt Tag

Once you signed in, delete all the other powershell files in your desktop and create this one for future use (downloading)

# Check if the script is running with administrative privileges
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    # Restart the script with administrative privileges
    Start-Process powershell.exe -Verb RunAs -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"")
    Exit
}

# Set the path to the Android SDK emulator
$emulatorPath = "$env:LOCALAPPDATA\\Android\\Sdk\\emulator\\emulator.exe"

# Set the name of the AVD (Android Virtual Device)
$avdName = "Pixel_3_XL_API_24"

# Start the emulator in a separate PowerShell instance
$emulatorProcess = Start-Process powershell.exe -ArgumentList "-Command `"& {$emulatorPath -avd $avdName}`"" -PassThru

# Wait for the emulator to be fully connected
$emulatorConnected = $false
$timeout = 300 # 5 minutes
$startTime = Get-Date
while (-not $emulatorConnected -and ((Get-Date) - $startTime).TotalSeconds -lt $timeout) {
    if (adb.exe devices | Select-String -Pattern "emulator-5554") {
        $emulatorConnected = $true
        Write-Host "Emulator is connected."
    }
    else {
        Start-Sleep -Seconds 10
    }
}
if (-not $emulatorConnected) {
    Write-Host "Emulator did not connect within the timeout period."
    $emulatorProcess.Kill()
    Exit
}

# Set the path for the extracted folder
$extractPath = "$env:USERPROFILE\\Documents\\apple-music-alac-atmos-downloader-main"

# Check if the folder exists
if (-not (Test-Path $extractPath)) {
    # Download and extract the ZIP file
    $zipUrl = "https://github.com/zhaarey/apple-music-alac-atmos-downloader/archive/refs/heads/main.zip"
    $zipFile = "$env:USERPROFILE\\Downloads\\apple-music-downloader.zip"
    Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile
    Expand-Archive -Path $zipFile -DestinationPath "$env:USERPROFILE\\Documents" -Force
    Remove-Item -Path $zipFile
}

# Change the current directory to the extracted folder
Push-Location $extractPath

# Create a batch script file for Android shell commands
$batchScriptPath = "android_shell_commands.sh"
@"
#!/bin/bash
cd /data/local/tmp/
chmod 777 frida
./frida
"@ | Out-File -FilePath $batchScriptPath -Encoding ASCII

# Run Android shell commands in a separate PowerShell instance
$shellProcess = Start-Process cmd.exe -ArgumentList "/C adb forward tcp:10020 tcp:10020 & adb shell < $batchScriptPath" -NoNewWindow -PassThru

# Open Command Prompt window 1 in the extracted folder
$cmdWindow1Args = "/C frida -U -l agent.js -f com.apple.android.music & pause"
Start-Process cmd.exe -ArgumentList $cmdWindow1Args

$cmdWindow2Args = "/K"
Start-Process cmd.exe -ArgumentList $cmdWindow2Args

# Wait for the background process to complete
$shellProcess.WaitForExit()

# Clean up the batch script file
Remove-Item $batchScriptPath

# Restore the original location
Pop-Location

# Wait for the emulator process to complete
$emulatorProcess.WaitForExit()

# Close all open Command Prompt windows
Get-Process cmd -ErrorAction SilentlyContinue | ForEach-Object { $_.CloseMainWindow() | Out-Null }

Now the powershell console contains the frida server (must be running so dont close it.)
The other CMD console is running the frida agent.js, theres also one for the emulator and lastly one with the path with the script

Now type in the CMD containing the path for apple music atmos downlader the following command to start downloading songs:

go run main.go [URL HERE]

example:

  • Alt Tag

Enjoy your ALAC music!

  • Alt Tag

IF YOU GET THIS ERROR

  • Alt Tag

MAKE SURE THE FRIDA SERVER AND AGENT.JS ARE RUNNING, ALSO MAKE SURE YOUR AUDIO QUALITY IN THE APPLE MUSIC APP IS SET TO LOSSLESS

  • Alt Tag

AND ALSO CHECK THE COUNTRY CODE IN THE URL TO MATCH YOURS (FOR EXAMPLE IF YOU ARE IN THE US IT SHOULD LOOK LIKE THIS)

https://music.apple.com/us/

UPDATE

If you already tried this guide before, do this:

We have to install a couple things if you already followed this guide. First update your https://rentry.co/YWxhYyBkbCBndWlkZSAxMzM3#once-you-signed-in-delete-all-the-other-powershell-files-in-your-desktop-and-create-this-one-for-future-use-downloading and replace the old one.

Press WIN + R in your keyboard, now type cmd. Now in your console type the following commands:

choco install GPAC -y
pip install selenium
pip install webdriver-manager

Now follow the guide under this ↓

If it's your first time following this guide, do this:

Now you need your media-user-token cookie to retrieve lyrics, also MP4Box (GPAC).
First, make a python file (main.py) inside the apple-music-alac-atmos-downloader-main folder and paste this code inside.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from datetime import datetime
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType
import yaml
from pathlib import Path as _Path
from os import environ

# Create a ChromeDriver instance using the Chromium browser
driver = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))

# # Navigate to the Apple Music login page
driver.get("https://music.apple.com/us/login")

yaml_path = _Path(environ.get('USERPROFILE')) / 'Documents' / 'apple-music-alac-atmos-downloader-main' / 'config.yaml'
print(yaml_path)

# # Wait for the user to log in and the URL to change
# # The WebDriverWait class provides a way to wait for a specific condition
# # to be met before proceeding with the execution of the script
login_wait = WebDriverWait(driver, 300)  # Adjust the timeout (in seconds) as needed
login_wait.until(lambda d: d.current_url == "https://music.apple.com/browse")

# Get the user's login timestamp
login_timestamp = datetime.now()

# Get the media-user-token cookie
cookies = driver.get_cookies()
media_user_token = next((cookie["value"] for cookie in cookies if cookie["name"] == "media-user-token"), None)

# Save the media-user-token to a file
if media_user_token:
    with open(yaml_path, 'r') as file:
        data = yaml.safe_load(file)

    # Modify the data
    data['media-user-token'] = media_user_token

    # Write the modified data back to the file
    with open(yaml_path, 'w') as file:
        yaml.safe_dump(data, file)

# Print the user's login timestamp
print(f"User logged in at: {login_timestamp}")

# Close the browser
driver.quit()

Then run it.
It should open a new chrome window, here you have to log in.

  • Alt Tag

Once logged in, verify it with your OTP message.

  • Alt Tag

Then click Trust to successfully logging in.

  • Alt Tag

Lastly, it will modify a config.yaml file containing your media-user-token where the script is installed

  • Alt Tag

It should look like this.

  • Alt Tag

And we are done!

  • Alt Tag

If everything worked fine, ill kindly ask you to donate to my Paypal! this guide took some time and research to create, i will updating it in the future to make it more user-friendly.

Credits:

@zhaarey (github) for creating the atmos version for the script.
Sorrow for creating the original script.
and everyone at https://t.me/apple_music_alac

Extra

Uninstall script

# Check if the script is running with administrative privileges
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    # Restart the script with administrative privileges
    Start-Process powershell.exe -Verb RunAs -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"")
    Exit
}

# Uninstall Go Lang
if (Get-Command -Name "go" -ErrorAction SilentlyContinue) {
    choco uninstall -y golang
}
else {
    Write-Host "Go is not installed."
}

# Uninstall Python packages first, if Python is installed
if (Get-Command -Name "python" -ErrorAction SilentlyContinue) {
    pip uninstall frida-tools -y
    pip uninstall webdriver-manager -y 
    pip uninstall selenium -y
}

# Uninstall Python
if (Get-Command -Name "python" -ErrorAction SilentlyContinue) {
    choco uninstall -y python
}
else {
    Write-Host "Python is not installed."
}

# Uninstall 7-Zip
if (Get-Command -Name "7z" -ErrorAction SilentlyContinue) {
    choco uninstall -y 7zip.commandline
}
else {
    Write-Host "7-Zip is not installed."
}

# Uninstall adb
if (Get-Command -Name "adb" -ErrorAction SilentlyContinue) {
    choco uninstall -y adb
}
else {
    Write-Host "adb is not installed."
}

# Uninstall GPAC (mp4box)
choco uninstall gpac

# Uninstall Android Studio
choco uninstall -y androidstudio

# Remove downloaded APK files
Remove-Item "$env:TEMP\com.aefyr.sai.fdroid_60.apk" -ErrorAction SilentlyContinue
Remove-Item "$env:TEMP\app.apkm" -ErrorAction SilentlyContinue

# Remove the downloaded and extracted Frida server
Remove-Item "$env:TEMP\frida-server.xz" -ErrorAction SilentlyContinue
Remove-Item "$env:TEMP\frida-server" -Recurse -ErrorAction SilentlyContinue

# Remove the downloaded ZIP file and extracted folder
Remove-Item "$env:USERPROFILE\Downloads\apple-music-downloader.zip" -ErrorAction SilentlyContinue
Remove-Item "$env:USERPROFILE\Documents\apple-music-downloader" -Recurse -ErrorAction SilentlyContinue

# Remove the media-user-token.txt file
Remove-Item "$env:USERPROFILE\\Documents\\apple-music-alac-atmos-downloader-main\\media-user-token.txt" -ErrorAction SilentlyContinue

Write-Host "Uninstallation completed successfully."
Edit
Pub: 30 Mar 2024 05:47 UTC
Edit: 06 May 2024 19:09 UTC
Views: 5566