There is a way to import your music playlists to Plex, hosted on a Synology NAS. It requires some technical skills though.
This guide -with a few tweaks- should also apply to other environments if you follow the logic/idea of it.
Step 1: Get some vital library information from Plex
- First of all, go to your Plex installation directly on your NAS. The url should look something like: http://nas:32400/web/index.html#!/
- Go to your music library and play a song. Now, in the ‘play’now playing’-bar in the bottom, press the 3 dots and select ‘get info‘
- You can now see the full path to your music directory and this specific song /volume1/Plex/Library/Music/iTunes Media/Music/(artist/album/)song.mp3. Copy the path to your music root directory and write it down somewhere.
I’ll call this [ROOT] from now on. - Now click “View XML”. In this XML there is one thing you need to find and write down the number X: librarySectionID=”X“ (that X should be a number, e.g. 5)
I’ll call this [ID] from now on. - You can see that the url in your browser has also changed to something quite complex.
– Save the first part of this url:
https://212-71-14-205.079b54zed68d656d46zb6d5462989a9ec0.plex.direct:32400/library/metadata/115…
II’ll call this [HOST] from now on.
– Also at the very end of this URL, you will find your unique and temporary Token: …&Plex-Token=97g4cDJqi4APq8aUmvyh
II’ll call this [TOKEN] from now on.
- You can now see the full path to your music directory and this specific song /volume1/Plex/Library/Music/iTunes Media/Music/(artist/album/)song.mp3. Copy the path to your music root directory and write it down somewhere.
Step 2: Prepare your playlists to import them to your Plex library
There are a few prerequisites to allow the proper import:
- Your playlists must be .m3u files and should preferably be localized in the [ROOT] directory of your Plex music library
- If you open/edit them with a text editor, it’s content should look something like this:
EXTINF:520,Prince - Purple Rain
[ROOT]Prince/Unknown Album/Purple Rain.Mp3
EXTINF:230,Aha - Take On me
[ROOT]V.A_/Unknown Album/Take On me.mp3
...
Important! All the directory slashes must be forward slashes in this file(!) because your NAS is a unix system.
TIP: You can always use ‘find and replace’ to change force the [ROOT] directory in front of all tracks. Also,
Step 3: Import .m3u Playlists to plex with Postman
First, carefully prepare/compile the following url:
[HOST]playlists/upload?sectionID=[ID]&path=[ROOT]Playlist.m3u&X-Plex-Token=[TOKEN]
So, as an example, it should end up looking something like:
https://232-49-13-205.089b422c68dzf4z6e5a9ec0.plex.direct:32400/playlists/upload?sectionID=5&path=/volume1/Plex/Library/Music/iTunes Media/Music/playlist.m3u&X-Plex-Token=97g4cDJq7dzJz8aUmvyh
- Run “Postman” (Download, or run online). You will need to create a free account first.
- Click ‘New’, select “http”, and Change the ‘GET’ to ‘POST’ in the left panel, paste the url, and click the blue ‘Send’ button.
If all went well, you should see a green “200 OK” text appear below in the ‘response’ box, and your playlist should be added to PLEX!
If it didn’t work, there is a chance [TOKEN] has expired, see if you can start a new song and check if it’s still the right one.
Now, in the “Query Params” area, you can just change ‘playlist.m3u’ to ‘playlist2.m3u’ and press send again… and again… to import all your playlists.
I know it’s tricky but I hope this works for you!
Big thanks to Reddit user u/KarmicCamel who figured it out first for a local Plex installation, and for u/jetrolorko/ for pointing us in the right direction for a remote Plex installation. Also a big thanks to user Technobrat for elaborating in the comments below how to automate step 2, with a custom Bash script which processes the .m3u files.
7 thoughts on “Import .m3u music playlists to PLEX on a Synology NAS”
Thanks for this mate, I honestly had read previously the reddit thread you mentioned a while ago. It wasn’t clear on all the steps and despite being familiar with POSTMAN I hadn’t found time/will to figure it out. Yesterday I came to realization that I needed to tackle the problem and searched for the keywords to try and find the reddit post to refresh my memory and begin filling the gaps I had the previous attempt. That was when I came across your page that basically made it extremely easy to follow the instructions with great examples and screen shots. You sir are a Champion, thank you.
Hi Technobrat
Thank you so much for this comment!!
Glad I could help you out and that the instructions were clear. It took me a while to figure it out myself as well, so I write these guides also as a reminder to myself.
Cheers and enjoy your music in Plex!
Hi POWERUSR and others,
Here is my contribution addressing the above tutorial’s Step 2. I wrote a small bash script for those who aren’t necessarily programming savvy and would like an automated solution that processes .m3u files, automating Step 2 entirely.
Please be careful and follow the instructions accordingly, nonetheless running bash scripts you don’t understand is NEVER recommended for security reasons which can result in security breaches or even full data loss. Use at your own risk, my intent and script aren’t ill intended but I do need to make this disclaimer before someone accidently clears their drive and blame me. If you can put 2+2 together and was able to follow the above, you should not have problem’s.
On your synology NAS UI, if you go to Control Panel > Task Scheduler > Create > User Defined Script, which should open a pop-up window called Create Task.
General Tab:
Task is where you give this any desired identifying name for this task.
User is a tricky one, depends on how you setup the users permissions… I have one user with admin rights, so I used that.
Enable needs to be ticket on for the script to be “active” or enabled.
Schedule Tab:
This is where you set how often you want this script to run. This varies between different people, I have it run every day because I update my playlists often and export them from my music app where I actually manage my entire music library. So having it run daily makes sense to me because I export the m3u files to a specific folder and forget about it, when ever I decide I need the updated playlists in plex (every other month) I can just run the POSTMAN calls and the latest m3u files already formatted are in place ready to be used by POSTMAN.
Task Settings:
Notifications – this part is pretty self explanatory.
Run command – bash cmd + file path for YOUR edited version of the script, it needs to be on your synology NAS. What you paste in that box should look something like the below, including the quotations marks.
/bin/bash “/volume1/Plex/MyScriptVersion.bash”
And that should be all.
Before doing the above you will need to copy the below and save it as a BASH file, that can be done using any text editor (not word) like Window’s and Mac’s native ones or a very popular and powerful one called Notepad++ (which I highly recommend). Before closing the text editor, look for “YOUR INPUT IS REQUIRED” lines which require your attention and input.
The script is pretty self explanatory and I’ve limited what you need to copy and paste everything BETWEEN the lines full of question marks (?????????) to create your own bash file, don’t forget to edit the file and then save. (Pasting the below in the run command will not work, you need to create a bash script file)
??????????????????????????????????????????????????????????
#!/bin/bash
# Source folder where .m3u files are located. Edit here, YOUR INPUT IS REQUIRED:
source_folder=”/Source/Directory/Use/Forward/Slashes”
# Destination folder after changes. Edit here, YOUR INPUT IS REQUIRED:
destination_folder=”/Destination/Directory/Use/Forward/Slashes”
# Ensure the destination folder exists; create it if it doesn’t
mkdir -p “$destination_folder”
# Create or overwrite the “m3uNameList” file in the destination folder
touch “${destination_folder}/m3uNameList.txt”
# Iterate through .m3u files in the source folder
find “$source_folder” -type f -name “*.m3u” -print0 | while IFS= read -r -d ” file; do
# Get the filename without path
filename=$(basename “$file”)
# Replace all single backslashes with single forward slashes and replace for [ROOT] directory from Step 2 (form POWRUSR above)
# To avoid using regular expressions, I took a simple approach. My m3u is initially exported with the songs directories
# in a format like below (where DS1621 is my Synology Nas network name):
# \\DS1621\Music\iTunes 2\iTunes Music\The Kooks\Inside in Inside Out\05 Ooh La.mp3
# \\DS1621\Music\iTunes 2\iTunes Music\The Kooks\Inside in Inside Out\02 See the World.mp3
# \\DS1621\Music\iTunes 2\iTunes Music\The Kooks\Inside in Inside Out\07 She Moves in Her Own Way.mp3
# \\DS1621\Music\iTunes 2\iTunes Music\Scissor Sisters\Ta-Dah [2CD Deluxe Edition]\10 The Other Side.mp3
#
# Given plex expects something in this “/volume1/Music/iTunes 2/iTunes Music/” format
# we need to set below what is your [UN-EDITED] for the [EDITED] path.
# If [UN-EDITED] = //DS1621/Music/iTunes 2/iTunes Music/
# then
# [EDITED] = /volume1/Music/iTunes 2/iTunes Music/
# based on the above examples the command should look like:
# sed ‘s#\\#/#g; s#//DS1621/Music/iTunes 2/iTunes Music/#/volume1/Music/iTunes 2/iTunes Music/#’ “$file” > “${destination_folder}/${filename}”
# Edit here, YOUR INPUT IS REQUIRED:
sed ‘s#\\#/#g; s#[UN-EDITED]#[UN-EDITED]#’ “$file” > “${destination_folder}/${filename}”
# Log the filename (including file extension) to m3uNameList.txt
echo “$filename” >> “${destination_folder}/m3uNameList.txt”
# Remove the original .m3u file
rm “$file”
echo “Processed and moved ${filename} to ${destination_folder}”
done
echo “All .m3u files processed and moved to ${destination_folder}”
???????????????????????????????????????????????????????????
Hope this helps.
POWRUSR feel free to edit or incorporate this in a friendlier format to your above tutorial if you are so inclined. Once again thanks for your initial input.
Hi Technobrat
Fantastic idea and execution, and thank you -on behalf of myself and all visitors as well- for sharing this with us!
Can’t wait to implement this on my own setup as well!
Thank you very much for the automation, although for more hours that I try to solve, it keeps giving me error.
I have my file like this (for the moment just modifying the sign \ until it works):
#!/bin/bash
source_folder=”/volume2/Music/Listas/Original”
destination_folder=”/volume2/Music/Listas/Plex”
mkdir -p “$destination_folder”
touch “${destination_folder}/m3uNameList.txt”
find “$source_folder” -type f -name “*.m3u” -print0 | while IFS= read -r -d ” file; do
filename=$(basename “$file”)
sed ‘s#\\#/#g; s#UN-EDITED#EDITED#’ “$file” > “${destination_folder}/${filename}”
echo “$filename” >> “${destination_folder}/m3uNameList.txt”
echo “Processed and moved ${filename} to ${destination_folder}”
done
echo “All .m3u files processed and moved to ${destination_folder}”
but I get an error:
touch: cannot touch ”$’\342\200\234\342\200\235”/volume2/Music/Listas/Plex’$’\342\200\235\r”/m3uNameList.txt’$’\342\200\235\r’: No such file or directory
/volume2/Music/MyScriptVersion.sh: line 13: syntax error: unexpected end of file
If I delete the ‘touch’ line I still get the error: unexpected end of file.
Thank you very much
I had seen this function in other sites, but this site is the easiest one for me to learn how to do it.
Thank you.
Thank you so much for posting this, so I have followed all the steps.
I was initially coming across an error in postman “Cloud Agent Error: Can not send requests to reserved address. Make sure address is publicly accessible or select a different agent.”
This was happening via the web version, so decided to use the desktop version of Postman to check and I get the “200 OK” result however nothing is appearing in my plex playlists?
I am using a synology so all slashes within the m3u are /. I have checked the file paths in the m3u against the synology path and they match
Any tips?