How to use (iTunes) Music Library xml file generateed on mac on a server for a NAS library from macOs Catalina onwards

  • 22 August 2021
  • 1 reply
  • 1117 views

Badge

Okay, the title is quite a handful, but I couldn’t come up with a simpler one (suggestions welcome) so bear with me.

This is a summary of what I learnt to fix my problem based on these other topics which are quite a mess to read through:

and many more...

In this post I hope to help out all the people that were using an iTunes network library, either from a computer or on a server to play music on their sonos systems. Specifically I’ll focus on the usability, since I was used to just copying their iTunes folder on to my NAS and have it work perfectly as a NAS music Library with Sonos and how to get it to work with the new updated Music App, that replaced iTunes. This might also be helpful for people with playlist issues or general issues on getting their new OSX Music Library to work with Sonos.

General Information: Since Apple decided to replace iTunes with Music, it no longer creates an XML file for the library. This is an issue because it’s exactly that file that we need to have your NAS (or computer) work flawlessly with Sonos, specifically, so that the playlists work.

So, let’s begin: On your MacBook that you are moving or automatically updating your NAS music library from (My system works that way: I have a Task set up which copies the music files and library files to a server which hosts the iTunes network Music library. It used to work perfectly with playlists and everything on Sonos while iTunes was still a thing, but stopped working with the update that replaced iTunes with Music.) So the first thing we need to do is to download the Sonos Controler App on the Apple device and run an update on our network library so it is reindexed. This will update the old “iTunes Music Library.xml” file in the iTunes folder (if you don’t have an iTunes folder, create one, without it the Sonos Controller won’t create the XML file) based on the new Music Library file located in the Music folder next to the iTunes folder.

The media is still located in the iTunes folder for me and only the new library file is in the new Music folder. It’s an absolute mess if you ask me… Note the date on the iTunes Music Library File. It’s up to date because I used the sonos controler to update the library as seen in the first image. Furthermore you see which folders I am syncing to the server in this image. The music folder under iTunes Media is the one that contains all the song files. I also sync the album artwork as it will show up in the Sonos player. While it does show as being synced, all the files apart from the iTunes Music Library are not needed afaik.

 

Having used the Sonos controller to update the iTunes Music Library.xml file the date of the last edit should change on that file. I have a task set up on my computer that uploads the Album Artwork folder, the Music folder containing the actual songs, which is located in the iTunes Media folder and the iTunes Music Library.xml file to my server.

This used to work flawlessly with the old iTunes set up and no further steps were required because the library file used relative directories. However, the Sonos controller that updates our old iTunes Music Library files uses absolute directories which will not work on any other systems automatically.

So we need to update that. You can either go and open your xml file with an editor and replace the old path with the path you have on your server or if you have a system that continuously updates like I do, you can use the bellow script and set an automated task on your server to run it.

#!/bin/bash

sed -i 's#/User/Username/Music/iTunes#/Folder/iTunes%20Library#g' "/volume1/music/iTunes Library/iTunes Music Library.xml"

Configure this to your system:
“/User/Username/Music/iTunes”, replace Username with your username as seen in the xml file. This is the directory we want to replace.

“/iTunes%20Library”, this is what we are replacing the above with. It’s the folder in which your iTunes folders are located.

“/volume1/music/iTunes Library/iTunes Music Library.xml" is the location of the XML file on my server. Since I sync the complete folder it’s at the same relative location as on my computer.

Example: I have my sonos pointed at //NAS/Music and my "iTunes Media/Music" is located at "//NAS/Music/Username/iTunes%20Media/Music/...", so I need the xml to say "file:///iTunes%20Library/iTunes%20Media/Music/…

Sonos, however, uses the directory of your OSX device like this: "/Users/Username/Music/iTunes/iTunes%20Media/Music/..."
So we replace "/Users/Username/Music/iTunes" with "/iTunes%20Library" in the file "iTunes Music Library.xml"

If the XML file hasn’t been updated, the the script won’t do anything since there is nothing matching the string that it wants to change.

 

How you get the script to run on your server depends on the server. On my synology server I set a task in task scheduler with the following command: “bash '/volume1/musics/iTunes Library/upxml.sh'

upxml.sh is the shell script containing the code above. You can theoretically put that script wherever you want, but I put it in the same spot as the xml file it is editing just for easier navigation.

 

I hope I could help out some people with this. :D

 

Cheers


This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

1 reply

Userlevel 7
Badge +18

Hi @Nick Art 

Welcome to the Sonos Community, and thanks for taking the time to combine all this into one post!