Is the format/schema of the Apple Music “Library.musicdb” used in macOS Catalina documented anywhere?

1

As folks know, Apple abandoned iTunes with macOS Catalina. I use Logitech Music Server to drive my Transporter (a networked music player) for my home music system.

Logitech Music Server has a Python script that parses iTunes' music library into its internal SQL database. Apple Music no longer uses an XML file, but it does have an enticing file named Library.musicdb — within the /Users/[username]/Music/Music/Music Library.musiclibrary file/package — which is entirely binary, except for the header, which is hfma.

I'd like to write a replacement tool that takes the .musicdb file and populates the Logitech Media Server's database, but to do that, I need more information about this file. Is this documented anywhere? Better yet, are there tools for accessing it?

Dylan McNamee

Posted 2019-10-12T01:20:16.703

Reputation: 332

1@JakeGould - thanks for fixing the question - it's much clearer. – Dylan McNamee – 2019-10-12T01:28:06.293

Answers

1

There's a framework called iTunesLibrary that can read Music.app's database - just tested this on macOS Catalina - but it's an Objective-C one.

You may be able to use it via PyObjC, but it will only work if the application is code signed (see the warning there in yellow, at the bottom of the page).

You'd write something like this in Objective-C to access the library:

objective-c
#import <iTunesLibrary/ITLibrary.h>

NSError *error = nil;
ITLibrary *library = [ITLibrary libraryWithAPIVersion:@"1.1" error:&error];
if (library)
{
        NSArray *playlists = library.allPlaylists; //  <- NSArray of ITLibPlaylist
        NSArray *tracks = library.allMediaItems; //  <- NSArray of ITLibMediaItem
}

API version 1.1 seems to be for Music.app, whilst 1.0 should be for iTunes.

Matteo Pacini

Posted 2019-10-12T01:20:16.703

Reputation: 126

1Thanks - this is the info I was looking for. Sad to see it's Obj-C only, but there you go. – Dylan McNamee – 2019-10-12T19:15:33.203

-1

While Apple Music does not automatically generate an library XML file, this can be done manually in the app itself.

I realize this question is about the format of the actual Music Library.musiclibrary database — which would be cool to know about — you can manually export an XML file which — I will assume — is in the same exact format as the old iTunes XML file by following these steps.

First, open up the Music app, go to the “File” menu and choose the “Library” option.

Music app file menu.

Then, in that list there are two options: “Export Library” and “Export Playlist.” I’m choosing “Export Playlist” for this example.

The “Library” sub menu.

After doing that you will be presented with a fairly standard Apple file save/load interface to save the “Library.xml” file and there you go!

The file save interface.

While definitely not as convenient as the old way it was constantly generated in iTunes, I believe this should work well for apps that require the XML file.

Slightly snarky note/criticism from a programer: Why isn’t there a JSON formatting option for export? Let users choose XML or JSON based on needs since — honestly — nobody really likes dealing with XML in 2019. But I digress…

JakeGould

Posted 2019-10-12T01:20:16.703

Reputation: 38 217

1I tried doing this, but no file was produced. My library is Huge (45,000+ songs), and that has broken iTunes in the past, so maybe that's the cause here too. – Dylan McNamee – 2019-10-12T02:31:04.520

@DylanMcNamee Wow! That seems weird. I would actually report that to Apple as a bug since I have 17,000+ songs and it worked fairly quickly. I would recommend creating a playlist of maybe 10,000 to 20,000 songs and exporting that as an individual playlist from that same menu and see what happens.

– JakeGould – 2019-10-12T02:38:03.930

1I have filed the bug. A playlist export of 10,000 items works, but exporting the whole library silently, immediately does nothing. – Dylan McNamee – 2019-10-12T04:21:52.607

It would appear the musicdb format might be this one: https://developer.apple.com/documentation/ituneslibrary?language=objc

– Dylan McNamee – 2019-10-12T04:22:15.907

@DylanMcNamee Cool find! If you feel like posting that link as an answer, feel free to do that. I would also mention that export bug as well. I know a lot of people who need those XML files for third party use are not happy with the iTunes shift so that info is useful. – JakeGould – 2019-10-12T04:23:48.383