m3u playlist file creation before importing into Plex

What I did in order to create m3u files I could import into Plex

Creating the playlist files in Plex is tedious. It is better to import them. This cannot be done simply through the Plex web interface, you need to use the API.

This is not as difficult as it sounds. I am not a programmer/developer by profession but I am tech savvy.

Some things to consider:

  • the m3u content file path for each mp3 file has to match your Plex media path
  • characters in the folder and file names that can be supported, accented characters from French, Spanish and other languages may be difficult to import in code

The steps I took:

  1. created m3u files using VBScript
  2. captured a list of the m3u files generated
  3. converted the m3u file list into a batch file for import. I cover this in another post

VBScript to generate m3u files

I found a VBScript which someone has developed to create m3u files trawling through folders and subfolders looking for specific files types (mp3, wma, m4a). I modified it to create the m3u file with the content for each mp3 file with a prefix that matches my Plex media path AND using the artist and album name in the m3u file name title.

Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Parse command-line arguments
delete = false
set args = WScript.Arguments
if args.Count > 0 then
if LCase(args(0)) = "-d" then
delete = true
end if
end if

' Write m3u files for current directory tree
set fso = CreateObject("Scripting.FileSystemObject")
wscript.echo WriteM3u(fso.GetAbsolutePathName("."), delete) & " files written"

' Recursive function to write m3u files for a given path
function WriteM3u(path, delete)
count = 0
set fso = CreateObject("Scripting.FileSystemObject")
set fdr = fso.GetFolder(path)

' Write m3u file for each subfolder
if fdr.SubFolders.Count > 0 then
for each subFolder in fdr.SubFolders
count = count + WriteM3u(subFolder.path, delete)
next
end if

' If no files found in subfolders, write m3u file for this folder
if count = 0 then
rem wscript.echo "Scanning """ & fdr.Path & """"
' Build list of mp3/wma files
mp3List = ""
m3uName = fdr.ParentFolder.Name
for each f in fdr.Files
if right(f.Name, 3) = "mp3" or right(f.Name, 3) = "wma" or right(f.Name, 3) = "m4a" then
mp3List = mp3List & "/media/music/artists/" & fdr.ParentFolder.Name & "/" & fdr.Name & "/" & f.Name & VBCrLf
end if
next

' If any files found, write m3u file
if mp3List <> "" then
' Multi-disc folder handling
if len(fdr.Name) = 6 and left(fdr.Name, 5) = "Disc " then
m3uName = fdr.ParentFolder.Name & " - " & " (" & fdr.Name & ").m3u"
else
m3uName = fdr.ParentFolder.Name & " - " & fdr.Name & ".m3u"
end if

' Existing m3u file handling
m3u = path & "\" & m3uName
if fso.FileExists(m3u) then
'fso.DeleteFile m3u
end if

' Write new m3u file
rem wscript.echo "... writing """ & m3uName & """"
set m3uFile = fso.OpenTextFile(m3u, ForWriting, True)
m3uFile.Write(mp3List)
m3uFile.Close
count = 1
else
rem wscript.echo "... no mp3/wma files found"
end if
end if

' Return m3u file count
WriteM3u = count
end function

The lines that need to be modified for you configuration are:

  • Path in the m3u for your Plex media – mp3List = mp3List & “/media/music/artists/”
  • m3u file name – m3uName = fdr.ParentFolder.Name & ” – ” & ” (” & fdr.Name & “).m3u”

List of m3u files on your system

In CMD you can dir > txt in order to find all the m3u files. To get the minimum information you need then use this command:

  • dir /s /b *.m3u > my-m3u-files.txt

Create batch file to import into Plex

Using Excel and a notepad editor like notepad++ you can create a batch file.

In notepad you need to replace the spaces with %20 and other characters with URL codes, see my other post which details this.

You have to modify the server address, sectionID and Token value. Insert your modified m3u list in column B.

Importing m3u files to Plex music

There are a number of ways to do this which I’ll address, I’ve done this with a Windows client and Plex on TrueNAS.

  1. Using PLEX Import Playlist app maintained on github. https://github.com/gregchak/plex-playlist-import
  2. Command line using CURL
  3. Batch files using CURL (and what is different to #2)

Using PLEX Import Playlist

The instructions on the github page explain how to identify your section ID and the token needed for this and the other options below.

If the certificate has expired then just post an issue and the developer will update to a new version with a new certificate.


Command line using CURL

You will need the section ID and token as above which you can find the instructions for on many websites so I won’t repeat them here.

Recreate this command replacing your path, token and section ID as well as all the spaces and characters with the URL code for these:

curl -v -k -X POST “https://192.168.0.100:32400/playlists/upload?sectionID=X&path=/your/media/music/artist-name/album-name/artist-name-plus-album-name.m3u&X-Plex-Token=xxxxxxxxxxxxxx” –ssl-no-revoke

Please note you have to replace lots of characters as they are not allowed in URL paths, here is an example of some:

Reserved characters after percent-encoding (https://www.iplocation.net/url-encodes)
!#$&()*+,/:;=?@[]รท
%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D%C3%B7

If you get any CURL errors it will be due to an unacceptable characters in your path so it is a case of trial and error.


Batch files using CURL

….and what is different to the command line? The main difference is you have to double all the quotes and % symbols. Then you have to escape the & with ^ so a batch file command line looks like this:

curl -v -k -X POST “”https://192.168.0.100:32400/playlists/upload?sectionID=X^&path=/your/media/music/artist-name/album-name/artist-name-plus-album-name.m3u^&X-Plex-Token=xxxxxxxxxxxxxxxxxxx“” –ssl-no-revoke

  • “”https…..
  • ^&path
  • ^&X-Plex-
  • “” –ssl-no-revoke

Errors

You should see some codes in the CURL output

  • 200 = has worked
  • 404 = something wrong in your code, probably a typo or the wrong characters
  • 500 = the path to folder or file doesn’t exist on the server. Scan your library and check filenames and path against the one in your m3u file

New and old kits

Now that I’m getting back into modelling I thought I’d try out a few old with the new.

I’ve dug out some old ESCI kits such as the ESCI 8038 U.S. Armored Scout Car m3 a1 and the ESCI 8006 ‘Elefant’ both of which I could never find in my youth but have acquired more recently. I always wanted the scout car and they did it a couple of variants including the ESCI 8068 French and Russian ‘White’ m3.

The ‘new’ kits are 3D printed from Badger 3D Creations and I’ve included the pictures (without consent, happy to remove if contacted). I’m very impressed with the M8 Greyhound and the level of detail. The Italian SPA-Viberti AS.42 seems a little more bulky and less detailed but both are well printed, smooth and without any obvious 3D printing hangovers.

In the past I only ever used enamel paints (Airfix, Humbrol, Revell) but I’ve just got some Vallejo acrylics and they are very good.

Just trying out some options for a sand base colour.

Washing seems to be the new craze, in the old days we painted them ‘factory finish’ where as now they have to look battlefield used.

Old habits

It has been almost 40 years since I started this hobby and I’ve mostly been a collector and not a builder for the last 35 years.

This is something I’d like to get back in to now so hopefully I can find the time.