Building AppleMusic2FreshRSS
I got tired of missing new releases from artists I follow on Apple Music. The built-in notifications are inconsistent, and I wanted something more reliable that would integrate with my existing RSS workflow.
The Problem
Apple Music’s notification system for new releases is hit-or-miss. Sometimes you get notified, sometimes you don’t. I wanted a way to automatically track all my followed artists through RSS feeds since I already use FreshRSS for everything else.
Part 1: Apple Music API Integration
Getting the Data I Needed
The main challenge was figuring out how to access Apple Music’s internal API. The public MusicKit API doesn’t give you access to your personal library, so I had to reverse-engineer the web app’s requests:
# music.py - Core API interaction
BASE_URL = "https://amp-api.music.apple.com/v1"
def get_artists():
"""Fetch all artists from the Apple Music library."""
print("Fetching artists", end="", flush=True)
artists = []
offset = 0
while True:
params = {
'art[url]': 'f',
'format[resources]': 'map',
'include': 'catalog',
'limit': '100',
'meta': 'sorts',
'offset': offset,
'platform': 'web',
'sort': 'name',
}
response = requests.get(
f'{BASE_URL}/me/library/artists',
headers=HEADERS,
params=params
)
What It Looks Like Running
Here’s what happens when I run the script:
$ python music.py
Fetching artists........
Got 127 artists
Fetching number of albums for each artist
100%|████████████████| 127/127 [00:42<00:00, 3.01it/s]
Saving artists to artists.json
Number of artists per album count:
23 artists have 1 albums
18 artists have 2 albums
12 artists have 3 albums
8 artists have 4 albums
...
Cumulative statistics:
127 artists have >= 1 albums
104 artists have >= 2 albums
86 artists have >= 3 albums
The script caches everything in artists.json
so I don’t have to hit the API every time. It also gives me some interesting stats about my music taste.
Authentication Headaches
Getting the auth working was annoying. I had to inspect my browser’s network requests to Apple Music and extract the session cookies:
# headers.py
headers_applemusic = {
'Cookie': 'your_apple_music_session_cookies_here',
# Additional headers for authentication
}
Part 2: Adding Everything to FreshRSS
Using RSS-Bridge
Instead of trying to scrape Apple Music pages myself, I found that RSS-Bridge already has an Apple Music bridge. Much easier to just use that:
# add.py - FreshRSS integration
class FreshRSSClient:
def __init__(self):
self.api_key = os.getenv("API_KEY")
self.bridge_url = "https://rss-bridge.noh.am"
self.base_url = "https://rss.noh.am"
self.csrf_token = self._get_csrf()
def add_feed(self, artist_id, group_id, limit=50):
"""Add a new feed for an artist to a group."""
print(f"Adding artist {artist_id} to Group ID {group_id}...")
feed_url = f'{self.bridge_url}/?action=display&bridge=AppleMusicBridge&artist={artist_id}&limit={limit}&format=Atom'
data = {
'_csrf': self.csrf_token,
'url_rss': feed_url,
'category': group_id,
'feed_kind': '0',
# ... feed configuration
}
Running the Feed Addition
The script lets me filter by album count since I don’t want feeds for artists I only have one song from:
$ python add.py
Enter the minimum number of albums: 3
Got 86 artists with at least 3 albums
Available groups:
1 - News
2 - Tech
3 - Music
Group ID: 3
Adding artist 1653145983 to Group ID 3...
Adding artist 1503438664 to Group ID 3...
Adding artist 159260351 to Group ID 3...
...
Checking new feeds...
Updating feed: Taylor Swift - Topic...
Updating feed: Arctic Monkeys - Topic...
Automatic Configuration
I set it up to automatically configure the feeds with sensible defaults:
- Configures update intervals (daily by default)
- Sets retention policies (keeping 200 articles, 3 months)
- Handles CSRF tokens for secure API calls
- Manages feed categories and metadata
def edit_feed(self, feed_data, group_id, refresh_rate=86400):
"""Edit an existing feed's settings."""
data = {
'ttl': refresh_rate, # 24 hours
'keep_max': '200', # Keep max 200 articles
'keep_period_count': '3',
'keep_period_unit': 'P1M', # 3 months
'priority': '10',
# ... other settings
}
How It All Works
Pretty simple setup:
music.py
: Fetches and caches artist data from Apple Musicadd.py
: Adds artists as RSS feeds to FreshRSS
Both scripts use the same auth headers and environment variables. Nothing fancy.
What I Ended Up With
Now I have:
- RSS feeds for all artists I actually care about
- Feeds that update daily
- Everything organized in my existing RSS reader
- No more missed releases
It’s a simple solution that works well for my workflow. The Apple Music API gives good data, and FreshRSS handles the feed management nicely.
If You Want to Try It
The code is on GitHub if you’re interested:
- Set up authentication in
headers.py
- Add FreshRSS API key to
.env
- Run
python music.py
to get your artists - Run
python add.py
to add feeds
It’s mainly built for my specific setup (RSS-Bridge instance, FreshRSS), but the core idea could work with other RSS readers too.