7

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
  • 1
    @JakeGould - thanks for fixing the question - it's much clearer. Commented Oct 12, 2019 at 1:28

2 Answers 2

5

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.

5
  • 1
    Thanks - this is the info I was looking for. Sad to see it's Obj-C only, but there you go. Commented Oct 12, 2019 at 19:15
  • 2
    (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. Commented Apr 24, 2020 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. Commented Apr 26, 2020 at 19:28
  • Just know, for anyone finding this answer, the framework provides read-only access to the library. I wish they would allow read/write access to the library with a plethora of warnings of doom and destruction when modifying the library... Commented Dec 25, 2021 at 0:51
  • I did some digging and it seems ITLibrary is now a wrapper around AMPLibrary that uses XPC to communicate with the AMPLibraryAgent process. It controls what library is open so we can't use ITLibrary libraryWithFilePath anymore, the path is ignored.
    – malhal
    Commented Mar 2, 2023 at 15:40
4

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…

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

Not the answer you're looking for? Browse other questions tagged .