How do you import an iTunes Playlist?

OK, tired of no solutions I just went ahead and coded one on top of the Python plex API. It isn’t perfect, but it works well enough: I can import my playlists from Apple and play them in various Plex clients including on Alexa using the Plex skill.

https://github.com/jasmith79/apple_playlist_plex_importer

Most of the following is in the README, so if you are technically inclined just read that. I would really appreciate someone from the Plex team looking at this to help diagnose the few remaining annoyances detailed at the bottom.

It should work on older iTunes XML files, but I haven’t tested it (only on Catalina). It should work on XML files created by the Windows version of iTunes, but again, haven’t tested it. It should work on just about any host OS for PMS, but I’ve only tested on a Synology NAS (i.e. Linux).

To work at all a few things are required:

  1. An Apple music library XML file (File -> Library -> Export library in the Music app or iTunes).
  2. Credentials for your Plex Account (your plex.tv account, NOT your account on the server).
  3. The name of your Plex Server.

Additionally, some steps while not strictly required will make it work much more reliably:

  1. In your Plex Server settings under Agents move “Local Media Assets” to the top of the list for both Artists and Albums. This will reduce the amount of renaming of your media files that Plex does, making it easier to match to the Apple playlist tracks. Be sure to refresh the metadata after doing this.
  2. Double-check the output in the terminal when running the importer. If it can’t match a track, then the problem is almost certainly that the plex name is different than the Apple name, and you should rename the track(s)/album(s)/artist(s). This is more true the more non-English non-ASCII your collection is. I have a lot of Japanese, Scandanavian, and Latin character-having artists/tracks in my collection but ended up only having to manually rename one artist after doing step 1.

You can clone this repository, install the plexapi package dependency, and run app.py in the importer package but I recommend installing through pip:

python3 -m pip install --user git+https://github.com/jasmith79/apple_playlist_plex_importer.git

Open up a terminal and (assuming you installed via pip) run the command:

pleximport path/to/library.xml --user myplexuser --password myplexpassword --server myplexserver

For those of you worried about having passwords in your shell history, you can omit anything except the file path and it will interactively prompt you for them. See --help as well.

Some known issues:

  1. It can take a significant amount of time for PMS to optimize all of those playlists. Don’t be too concerned if you try to access them right away and get some sort of “failed to load” error message.
  2. If you don’t have any existing music playlists you will have to reload the page/restart the client app to get the playlists menu option to show in the Plex client.
  3. As I said the name matching is not perfect and was shockingly difficult to implement with even decent reliability. Probably the reason the Plex team didn’t do it.
  4. Playlist items will always fail to load if you try to view the playlist in either the web or desktop clients (although they play just fine). I would really love some help fixing this.
  5. It doesn’t delete or update existing playlists in PMS, if you run it more than once you will get multiple copies of playlists. If you need to update a list from your Apple data then you’ll need to delete them and re-run it.

Can anyone from the Plex team take a look at this and help iron out the remaining annoyances?

3 Likes