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?

  • 1
    @JakeGould - thanks for fixing the question - it's much clearer. – Dylan McNamee Oct 12 '19 at 1:28

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:

#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.

  • 1
    Thanks - this is the info I was looking for. Sad to see it's Obj-C only, but there you go. – Dylan McNamee Oct 12 '19 at 19:15
  • 1
    (Regarding Obj-C only.) This is not accurate. These APIs work in Swift, as of April 24, 2020. I just tried it in Xcode 11.4.1 on macOS Catalina. – Jared Updike Apr 24 '20 at 21:42
  • @JaredUpdike they do work through Swift (natively), but the idea here is to invoke it via Python, and PyObjC seems to be to most logic solution. – Matteo Pacini Apr 26 '20 at 19:28

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…

  • 1
    I 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 Oct 12 '19 at 2:31
  • @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. – Giacomo1968 Oct 12 '19 at 2:38
  • 1
    I have filed the bug. A playlist export of 10,000 items works, but exporting the whole library silently, immediately does nothing. – Dylan McNamee Oct 12 '19 at 4:21
  • It would appear the musicdb format might be this one: developer.apple.com/documentation/ituneslibrary?language=objc – Dylan McNamee Oct 12 '19 at 4:22
  • @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. – Giacomo1968 Oct 12 '19 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.