Import Itunes Playlist

Hi everyone,

I’ve been using PMS for a while now. I started out on my Windows desktop and later converted to an Ubuntu server. On my desktop I had no issues importing my music playlists as both PMS, iTunes and my music collection were on the same computer.

Due to circumstances I recently had to reinstall my ubuntu server again and didn’t think about my playlists all too well. I simple had in the back of my head I could simply import it from iTunes.
Boy was I wrong!

Searching PMS forums and google gave pretty much similar results, that everyone was struggling with importing iTunes playlists (al be it mostly out-dated, say 2012-2015) and no solution was found. Nonetheless I kept trying.
Now, I do not know if this is already public knowledge as I myself could not (easily) find it, so I am posting this in the hope to contribute to the community.

[PROBLEM]

As this solution worked for me, does not mean it works for everyone else, OS or configuration. So I’ll describe my problem and solution as elaborate as I can.

My setup:

  • NAS with all my music collection
    ** music collection is shared to my PLEX server.
  • PLEX server (running mainly PLEX, separate server).
  • Desktop (which runs iTunes)

Problem 1: PMS does not know where my iTunes Library is saved.
Problem 2: PMS is not very clear when it comes to iTunes Playlists (more below).
Problem 3: iTunes stores information on where your music is located (Windows-location).

[SOLUTION]

Problem 1 & 2
Importing an iTunes playlists without configuring your PMS will result in the following error:


This means, that PMS is looking in either its basic directory (if it has any) or simply does not know where to look. THUS a “problem” occurred.

So we need to specify where to look.

  1. Go to your PMS website (i.e. http://localhost:32400/web/index.html)
  2. go to Settings (top right corner)
  3. select the Server tab
  4. click “Show advanced” (right below the server tab)
  5. click on “channels”
  6. check the “Enable iTunes channel” option.
  7. Next we need to provide a “PATH” to the XML file location.
    NOTE, PMS says “iTunes library XML path” but it actually means the file itself. normally when you are asked to provide a PATH you will give something like “C:/users/<username>/my documents” but in PMS’ case, it means the following: “C:/<foldername>/itunesplaylist.xml”. As seen below:
  8. we have now specified the location of our iTunes playlist XML file and can restart PMS

If we try to import the playlist now, it would just return an empty screen. PMS says that it is successful but most likely you wont see any playlists.

Problem 3
This has nothing to do with PMS, but rather with the information that iTunes stores. in order to import the playlist to PMS, PMS needs to know where all the files are located as stated in the playlist.
2. export your iTunes libary/playlist
3. edit it with your favorite editor (i.e.: Notepad)
4. all we need to look for is the following text:

NOTE the text will most likely be different for everyone, as the location, folders and songs will be different for everyone.
As you can see, the location of the file is located on the localhost (the computer which iTunes is installed on), the “D:” -drive, folder “music” etc.
5. in order for PMS to know where the file is located for PMS, we need to alter the following: file://localhost/D:/music/ TO file://localhost/<location_of_music_collection_on_PMS/
Here is a example:
FROM:

TO:

In my case, to PMS, my music collection is in /mnt/music.
6. Do this for the whole document by using the replace function (in Notepad or Word this is CTRL+H)
7. Be mindful of your directory structure. it is easy to just replace everything, but different directories might require different replace-text.
8. Save the edited playlist to the location specified in PMS
9. now import your playlist in PMS

That is all I needed to do to import my iTunes playlist in PMS. It requires some work but luckily you can use the replace function which speeds things up.

TO DO (maybe)

  • will this work on every kind of setup? i.e. Windows, Debian, Mac OS X etc.
1 Like

Excellent post.

Hi. This is very useful but I’ve got to point 3 and I’m now stuck !

I don’t have a iTunes Library Playlist.xml just a iTunes Library.xml (I’m using the latest version of iTunes). Should I…
a - complete Point 3 against that ? (and essentially create a new copy everytime I edit/add something into iTunes Playlist).
b - export each of my playlists (I have many) and make the edit ? but then I’d have multiple playlist.xml files.

Sorry if this is a dumb question and I’ve missed something !

@Sebnev47 said:

Hi Sebnev47,

the names i used are basically placeholders. so it doesn’t matter what name your .xml file is. It could be playlist.xml, or mymomscookingisthebest.xml. Just remember that the filename is the same both as XML file on your computer, and the file you specify in PLEX (else it won’t work obviously).

In my case, i simply export my entire iTunes library. which means all the playlists that it contains are exported as well.
Each time you alter songs in your playlists and want the new playlist in PLEX as well, then you can do 2 things:

  1. if you only want to edit a few songs, I suggest you alter your PLEX playlists manually (it takes less time).
  2. if you want to edit a lot of songs (i.e. 10-100 songs overall) I suggest to export your new library again and repeat the above steps.

This seems quite a bit of work if you alter your playlists often, but currently this is the only option to update your PLEX playlists from iTunes. (probably still quicker then editing the PLEX playlists song by song depending on the amount).

Got it - thanks !

So I’ve tried it but not quite got it working…
If it use the path file://localhost/volume1/music/ then I get all the playlists - however when i go into a playlist and try and play a song it fails.
If I use the path file://volume1/music/ then only a couple of playlists come up (it looks like the standard ones from iTunes) but songs in these playlists play.

Any ideas on what I’m doing wrong here ?

its hard to help without knowing your configuration and all or what you’re specifically trying to do. my guess is that you haven’t edited your xml file that the location in the XML file is still something PLEX has no access to.

Hello, A quick question…

I have got the database pointing in the right direction and PMS has imported some playlists. The problem is the content of the lists is completely wrong. I thought the .XML might be corrupt, so i deleted it and had it regenerated by iTunes again and tried a re-import. The music in the playlist plays fine, it is just completely wrong.

For example in a test playlist I set up, I added 146 items in iTunes to the playlist (ordinary playlist, not a smart playlist). After importing to PMS the playlist shows with the correct name and it says that there are 146 items in the list. However when you open it up there is only one item in the list and it is a song that isn’t even in the list on iTunes. It does play okay however…so I think pathing is okay.

I think I may have to go .XML diving…

The music and database all exist on a NAS share to an ubuntu PMS server. I’ve run the procedure a few times and keep coming up with he same result.

Any ideas? Does PMS just read the XML? or does it read in in conjunction with something else? Just trying to get a handle on how it works so I can trouble shoot.

Okay, having spent a fair amount of time wading knee deep through XML’s and looking at combinations of pathing etc, I still can’t get playlists to import correctly.

Even rebuilt the iTunes DB from scratch, just in case. Nup, no go.

I’m thinking that iTunes playlist import as been broken in someway in the latest PMS version. Nothing I did could provoke the import to vary, it just kept importing the list and putting the incorrect information in it.

Could someone have a look at it…not a big deal…just would be very nice.

First of all, I am not a developer of plex nor an export at plex/itunes/playlist. I am just a regular user like everyone else here who happens to have found a solution for himself :slight_smile:

with that said, the more we can figure out the better!

It definitely sounds strange that your import says its fine and yet it only contains one song.

Lets see what we can do:

  1. there are 2 kinds of exports in iTunes
  • playlists
  • library

The playlist option is only 1 playlist. whereas the library will export all playlists in total. In my first post, i talk about the entire library so it might not work correctly for a playlist-only. i have not tested this.

  1. PLEX needs a file location, not a path.
    this is explained in my first post as well. as you say, you’re XML files is read and imported so it seems to work correctly. not to be a nuisance or anything, but are you 100% you have specified the correct file? (in my experience, people sometimes say so but in fact haven’t checked it).

  2. PLEX needs to know the file location of your music
    This is the part that gets tricky and where the XML needs to be edited.
    By importing this XML file into PLEX, PLEX tries to read out certain information.
    3a) i do not know exactly which data PLEX reads. 1 thing i am sure of is that it reads the filelocation-string.
    that means that when the XML file is imported, PLEX will look at the following line of code:
    <key>Music Folder</key><string>file://localhost/C:/Users/myname/Music/iTunes/iTunes%20Media/</string>
    or
    <key>Location</key><string>file://localhost/C:/%23albums/Phil%20Collins/Face%20Value/01%20-%20Phil%20Collins%20-%20In%20the%20Air%20Tonight.mp3</string>

The first line of code specifies the iTunes music folder. I am not sure what this means but it is not a line of code that PLEX looks at. In my own XML file i have left it untouched and my playlists are imported.

The second line of code however, is what PLEX will look for. If PLEX can access that location, than nothing needs to be changed. But if you are running a NAS and PLEX server, that’s an entirely different story. in my case, my NAS hosts my music and PLEX has access to it via network shares.
So i have to alter the second line of code to the following, so that PLEX knows where my music is stored (when i import the XML file).
<key>Location</key><string>file://localhost/mnt/music/%23albums/Phil%20Collins/Face%20Value/01%20-%20Phil%20Collins%20-%20In%20the%20Air%20Tonight.mp3</string>
Save the file, import in PLEX and in my case it works.

Now, there are a few things that might be causing problems.
a) wrong playlist
b) didn’t edit the XML file
c) made a typo while editing
d) PLEX is still importing the library

You say that you only have 1 song and it plays correctly. This will rule out A and B by a fair margin. Meaning, your song is specified correctly. That could mean that either everything else is incorrect (option C), or PLEX might still be importing all the music into its playlist (with that i mean the PLEX playlist).
Remember, LINUX/UNIX is case sensitive. So if you have a folder with a capital letter, you must also specify that. In the example-code above, you see the words music/%23albums. these are all lower cases. the subfolders however, are not (Phil%20Collins/)
If i were to make that lowercase, there is a high chance the playlist will import, but wont be able to play. Nor will it probably show in the PLEX playlist (as it cannot find the file).
you could check the logs to see what happens when you import. i believe it is located here: /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log but it would be wise to check all log files.
How long have you waited for the playlist to be imported? it could take a while because, similar to PLEX scanning for new media.

Perhaps 1 last note, and probably a very important one: i am running Version 1.0.0.2261. It could well be a version difference that is causing this problem.

Hello again Keitocorp, thanks for taking the time out to provide advice.

Well I have made it work. It was c) Made a typo while editing (missed a backslash, only had two instead of three). As you can see from my signature I have a standalone server with two NAS’s connected.

I guess the think that threw me out was that the list was being added with the correct name and amount of tracks at the top of the list was indicating the correct amount. The tracks however inside the playlist after opening it were wrong.

So I guess what happens is that when a playlist is imported the items in the list are counted and name added, but then the corresponding tracks on the NAS get checked to see if they exist…

<dict> <key>Playlist ID</key><integer>22053</integer> <key>Playlist Persistent ID</key><string>DE9C655FA2064D6D</string> <key>All Items</key><true/> <key>Name</key><string>Test List 2</string> <key>Playlist Items</key> <array> <dict> <key>Track ID</key><integer>6118</integer> </dict> <dict> <key>Track ID</key><integer>10274</integer> </dict> <dict> <key>Track ID</key><integer>10340</integer> </dict> <dict> <key>Track ID</key><integer>8096</integer> </dict> <dict> <key>Track ID</key><integer>8092</integer> </dict> <dict> <key>Track ID</key><integer>8090</integer> </dict> </array> </dict>
Obviously the track ID Integer is checked and then the path is checked to see if the track exists. If it doesn’t I’m surprised the list import doesn’t stop and report some sort of error. But it appears it doesn’t. It just keeps importing until it runs out of lists.

Anyway, problem solved. Thanks again for your time.

@keitocorp said:
Problem 3
This has nothing to do with PMS, but rather with the information that iTunes stores. in order to import the playlist to PMS, PMS needs to know where all the files are located as stated in the playlist.

Your tutorial and effort is very much appreciated. It helped quite a bit. Sorry to bump an old thread, I think would be the right thing to say so that the interwebs don’t look at you funny.

It occurred to me as I was reading your post that Plex could do 2 SIMPLE things to make importing iTunes playlists less of an issue. (And this wouldn’t solve the problem 100% of the time, but it’s OK to implement solutions that fix things say 58% of the time…I think some folks have trouble and focus on the all or nothing concept.)

  1. During initial music library setup, a simple note could be displayed (also on the Media/Folder structure help pages…) advising the user to ensure that they’ve pointed the Music Library to the default location of the iTunes folder itself.

On a Mac being used as PMS (example): /users/username/Music/iTunes/
Nvidia Shield PMS pulling media from a Mac (my setup): /storage/SHARE/iTunes/

(In other words, don’t have your share point to /storage/SHARE/iTunes/Music/ … because you’ve gone too deep.) Same concept for some Linux path variation or Windows /storage/SHARE/C:/Program Files/iTunes/… you get the idea.

The standard folder structure (again - maybe this won’t work for custom setups) is:
/iTunes/iTunes Music Library.xml
/iTunes/iTunes Media/Music/

  1. Even with your music on your NAS, with your iTunes installation on your desktop PC, all of those tracks are going to have the path to the NAS in the XML file…so with a little dynamic “common sense” programming - Plex is being told WHERE iTunes is, AND where the music is RELATIVE to iTunes.

Perhaps I’m wrong, but I feel like some automation and expansion on that concept could solve that problem in maybe half or more scenarios. I’m probably talking out of my butt - who knows.

Question: I’m storing my entire iTunes library (including playlists, music storage and the .itl file) on a QNAP shared folder. I have configured the proper iTunes setting to share and to create an .xml file that the PMS needs to import playlists.

To get to that directory from Windows it would be \SarSpotNAS\Music\iTunes\ and I have the iTunes library XML path set at “\SarSpotNAS\Music\iTunes\iTunes Library.xml”. From what I’ve seen in the prior posts, I am assuming I have the path spelled out incorrectly. Given the path I have that I can get to from a standard Windows directory, what is the proper version of that path that should be placed in that PMS path?

I’m sure it is a proper Linux version as the QNAP is Linux based.

I’m somewhat lost here…

Are you running the PMS on the QNAP or a different box?

Stephen, same box. And I did get further.

Since my music files are on the same drive as the PMS (the QNAP), all I needed to do was put this in the iTunes library XML path in the Settings area:

/share/Music/iTunes/iTunes Library.xml

No quotes were needed and when I went back to Playlists and clicked the gear icon to ‘Import from iTunes’, I didn’t get an error message. It took its own sweet time to get the playlists and I saw the four on the screen that I had in my iTunes setup.

The description of the Playlists include the correct number of songs but they also include a photo icon that I never set up in iTunes (all four playlists include the same photo example). If I go to play the list from its icon (with the play symbol), it ‘plays’ the photo on to the screen. That’s it. If I click on the Playlist to see the songs on that list, it thinks for a few seconds and then it briefly gives me the drop down red box stating ‘There was a problem loading these items’ and it then states ‘Failed to load items for this playlist’.

One of the playlists does actually show a list but that list is one item that is the picture - no songs are part of the list.

I’m going to review the thread here to see if something needs to be manually changed on the .xml file to make it point correctly to the music data but if something I’ve stated triggers an answer, I’m all ears.

OK, I was able to get the playlists loaded by making a change to the directory in the .xml file.

Because I use Windows to run iTunes, the localhost that is created in the .xml file is:

//localhost//SARSPOTNAS/Music/iTunes/Music/* - where * is the name of the song file

I simply changed that to:

//localhost/share/Music/iTunes/Music/*

Since the Plex software and the song files are on the same device (QNAP - mine is named SarSpotNAS) but on different shares, I only had to define back to the share level (Music) and then burrow into the sub directories that held the song files.

After importing and - waiting - for a time for all of the data to sync up, I was able to click on the playlists, see the songs and album posters and play the music. This is true when Plex is accessed from a webpage - such as one that is created when the Plex icon in the QNAP webpage is clicked.

However, when I attempted to play music from those playlists from the Plex app on the iPhone that accesses my Plex server, it gets stuck in acquiring the album poster and the wait wheel simply spins and the music never plays. Funny thing though, if I have the music casted say through a Chromecast device from my iPhone, it does play but the wheel still spins and the album poster never comes up on the Plex app on the iPhone. If casting to a Chomecast on a TV from that iPhone, the album does show up on the cast-to device (TV in this instance).

Kind of strange…

Great post keitocorp, and useful followup posts from all.

I’m running Plex on a Synology and followed the general guidelines. Once I got the naming of the file changes right, things started working - sort of. I checked the databases and they seemed to be okay. I tried restoring them and things stopped working. I went back to the original databases did a Synology restart/reboot and things came back to the ‘sort of working’ state - home page in plex experiencing an error and also not showing the items within a music playlist.

I looked around and the fix was very simple - just do an optimize of your libraries!

Again thanks keitocorp!

hello!
i dont know what happened after i reinstalled plex due to a crash.
I got everything perfect, and it even gets my “automatic” playlists such as the 25 more listened songs and so forth, but none of the playlists created by me in itunes. this used to work perfect before. I am running Plex in a mac. one only hd. My itunes is located in users\myname\music\iTunes… this should work no?
thanks!!