Home Page
Projects > Plex Playlist Importer
Search:
Plex Playlist Importer Thumbnail
Plex Playlist Importer v1.1.0.0
Completed
Import playlists into Plex
Rating: 8 (Another quick and small but useful project. For one of my free opensource projects, it probably has the most users.)
Project Time: 2014/11/08-2014/11/09: 8
Languages: Python
Requirements: Command line
Python 3 (compiled against v3.4) or Windows
The Plex database
Downloads: Binary Source (See any updates below for prior versions)
Sections: Information, Content, Updates, Comments
Information
My music directories have been growing for over 2 decades in a folder based hierarchy, often using playlists for organization. Plex’s music organization is counterintuitive to this organizational structure, and Plex currently does not have an easy way to import external playlists. Hence this script was born :-)
Content
GitHub page: https://github.com/dakusan/PlexPlaylistImporter

You can run this by directly dragging playlists onto it.
This script is fully unicode compliant.

Running and Troubleshooting

  • While this script requires Python 3 (compiled against v3.4), a stand-alone Windows binary version is also available on the URL at the top of this file.
  • While running the windows executable, if you get an error of “The program can't start because MSVCR100.dll is missing...”, download the “Microsoft Visual C++ 2010 Redistributable Package (x86)”.
  • If running through the Python source, The Python sqlite3 lib is required, but it should come with Python.
    • If running this mentions something about “no such module : FTS4”, you may need to replace the sqlite3.dll or sqlite3.so for your Python, which can be found at https://www.sqlite.org/download.html .
      • For a Python for Windows install, the DLL location will most likely be located at one of the following locations:
        • C:\Python%PYTHON_VERSION%\DLLs
        • C:\Program Files (x86)\Python%PYTHON_VERSION%-32\DLLs
        • C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python%PYTHON_VERSION%\DLLs

Parameters:

usage:
PlexPlaylistImporter.py [-h] [-p Given_DB_Path] [-e Playlist_Encoding] [-t File_Type_Override] [-f] Playlist_Path Plex_Playlist_Name

positional arguments:

Arguments Explanation
Playlist_Path The path of the playlist file
Plex_Playlist_Name The name of the playlist in Plex to import to.
  • If not given, the program will prompt for it.
  • If the given playlist does not already exist, the program will prompt on whether to create it (unless -f is specified).

optional arguments:

Arguments Explanation
-h OR --help
show this help message and exit
-p OR --sqlitedb-path
Given_DB_Path
The path to the sqlite3 database file
  • The program tries to guess the path for the Plex data directory. If it cannot be found, this path needs to be passed explicitly
    • The default paths are:
      • Windows:
        • %LOCALAPPDATA%/Plex Media Server/
        • C:/Users/%USER%/AppData/Local/Plex Media Server/
      • Linux:
        • %PLEX_HOME%/Library/Application Support/Plex Media Server/
  • If the database is still not found from the given Plex path, the full path to the database is required
    • Defaults: (%PLEX_PATH% is from the path found from above)
      • %PLEX_PATH%/Plug-in Support/Databases/com.plexapp.plugins.library.db
      • %PLEX_PATH%/Plug-Ins/Databases/com.plexapp.plugins.library.db
    • Note: When passing a parameter string, environmental variables are not processed
-e OR --playlist_encoding
Playlist_Encoding
The encoding the playlist file is in. This is generally “utf-8”, but may also likely be “ISO-8859-1”. Default=utf-8
-t OR --override-type
File_Type_Override
The file type to encode as. If the file extension is not recognized, the file is parsed as a Winamp playlist (m3u). This allows overriding the determined file type. Default=NONE
-f OR --force-list
Do not prompt to create the playlist if it does not already exist.

The only playlist type that is currently supported is Winamp playlists (.m3u).
Playlist importers just collect the absolute files names, and others can easily be dropped into the “Importers” directory without any other code changes.
While the M3U importer (Importers/M3U.py) is the most appropriate to use as a template, I included a second example one (PTL.py) which just pulls in absolute file names with no error checks.

PlexPlaylistImporter.sh is just included to force proper Unicode (utf-8) encoding and column widths on the console.

How it works

The songs you want to play have to already exist in the Plex database.
When you add a song to Plex (through Plex), it stores the song’s full file path in the Plex database. What this script does is derive all the full song paths in a playlist file that you give it, checks those paths against Plex’s database, and then adds the matches in the proper order into the Plex playlist you specified.
So for this reason, the script must be ran on the same computer running the Plex server so that it can match the paths. (There are, of course, workarounds to this. However, I highly recommend against it, as I have found that doing this may corrupt the Plex server database).

Creating the executable

python setup.py py2exe

Updates
Plex Playlist Importer v1.1 @ 2016-07-14 23:26:31 - Download
Plex Playlist Importer v1.1 (source). Current updates spanning 2017:
  • Fixed absolute path logic for Linux (partial credit to Matt Spitz)
  • Bypasses UTF8 BOM
  • Program now works off of argument flags.
    • Added parameters: Playlist encoding, override type, force list
    • Created special BulletHelpFormatter class for parameters
  • Playlist names can now conflict with other item/list names in Plex
  • Console column width passthrough in the .sh file
  • Updated READMEs regarding:
    • Unicode compliance
    • The “no such module : FTS4” error
    • Running the script from a computer external to the server running Plex
    • The “The program can’t start because MSVCR100.dll is missing” error
    • All updates
  • Added the ability to compile to a windows executable (via setup.py py2exe)
  • The Playlist Name is now an optional argument which can be entered after the program is ran. This allows directly dragging playlists onto the executable
  • Added shebang to main script
  • M3U files now ignore lines that are empty or have only whitespace
Plex Playlist Importer M3U Absolute Paths @ 2014-12-01 18:44:55 - Download

M3U files in the Plex Playlist Importer now support absolute paths (smb shares and drive letters). v1.0.0.3 Binary and Source



Other updates include:
  • The readme files and project content have also been updated with clarifications and “how it works”.
  • Fixed bug caused by NULL song duration in Plex database
Plex Playlist Importer v1.0 @ 2014-11-10 15:50:33 - Download

Just released v1.0 (source) (binary) of this project which simply... imports playlists into Plex, via a CLI.

Comments
To add comments, please go to the forum page for this project (guest comments are allowed for the Projects, Posts, and Updates Forums).
Comments are owned by the user who posted them. We accept no responsibility for the contents of these comments.

Re: Plex Playlist Importer on 11/11/14 5:11pm by Dakusan
If running in Cygwin with the Windows install of Python 3, the following could be put into a shell script to automatically convert the cygwin path to the windows path. This helps with tab completion when typing a path

Code: [Select]
./PlexPlaylistImporter.exe "`cygpath -wp "$1"`" "$2"
So this could be called like:

Quote
./SCRIPT_NAME /cygdrive/c/playlist.path "Plex Playlist Name"
Re: Plex Playlist Importer on 11/27/14 8:54am by Dakusan
You just made me realize something very important that [I think] I need to add in to the documentation. The songs you want to play have to already exist in the Plex database.

When you add a song to Plex (through Plex), it stores the song's full file path in the Plex database. What my script does is derive the full paths for files in a playlist file you give it, checks those paths against plex's database, and then adds the matches in the proper order into the Plex playlist you specified.

So for this reason, the script must be ran on the same computer running the Plex server so that it can match the paths.

So to more specifically answer your question, if Plex supports loading files in through smb shares (accessed via "\\" in Windows), then I believe my program should be ok with it too.

I have not specifically tested this, so let me know if you think my program is not handling it correctly and I'll look into it.

Out of curiosity, was that MortScript thing you mentioned previously related to Plex or Python?
Re: Plex Playlist Importer on 11/29/14 1:15am by clowg
I am running the script on the Plex Media Server computer (Windows 7).
The media in question is all in the PMS library, but it is present on a different server.

When I run your script I get:

C:\7MC>plexplaylistimporter "top 501 songs.m3u" "Top500Rock" "D:\Media3\AppData\Local\Plex Media Server"
ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist): ÿþ\ \ D o r i s 4 \ M u s i c \
 R O C K \ D a v i d   B o w i e \ Y o u n g   A m e r i c a n s \ 0 8   -   F a m e . m p 3

Does that command line and subsequent output make sense to you?
Re: Plex Playlist Importer on 11/29/14 1:17am by clowg
Out of curiosity, was that MortScript thing you mentioned previously related to Plex or Python?

Sorry about that.  I mixed up two different sources for Plex Playlist import scripts.  mortscript.exe is used by the other one I am trying to get working at the same time as yours.  But that is failing as well becuase mortscript.exe wont run on my Windows 7 32-bit computer.
Re: Plex Playlist Importer on 11/29/14 4:25am by Dakusan
The new version I just uploaded should fix the problem, thanks for the report
Re: Plex Playlist Importer on 11/29/14 8:56am by clowg
Thanks.  I just tried the new version.  I still get this error:

C:\7MC\PlexPlaylistImporter>PlexPlaylistImporter.exe  c:\7mc\Top501Songs.m3u Top500Songs "D:\Media3\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db"

ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist): ÿþ\ \ D o r i s 4 \ M u s i c \ R O C K \ D a v i d   B o w i e \ Y o u n g  A m e r i c a n s \ 0 8   -   F a m e . m p 3

So I tried re-saving the m3u file as UTF-8 format, and that changed the error to:

ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist): \\Doris4\Music\ROCK\David Bowie\Young Americans\08 - Fame.mp3

See the weird character before the server name?  Is that the problem?  There is no visable character there.  I tried adding a carraige return, but then the program errored with:

ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist): 

Make any sense?
Re: Plex Playlist Importer on 11/29/14 9:13am by clowg
I just tried saving the m3u file as ANSI encoding, and now its getting further.  I get this error at what looks like the end of the process:

C:\7MC\PlexPlaylistImporter>PlexPlaylistImporter.exe  c:\7mc\Top503Songs.m3u Top500Songs "D:\Media3\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db"

Plex playlist is not already created. Would you like to create it now (y/n)? y
DB Error: unsupported operand type(s) for /: 'NoneType' and 'int'
Re: Plex Playlist Importer on 11/29/14 7:06pm by Dakusan
Ugh, I was noticing those non-path characters at the beginning of the songs you pasted on your first post and decided to assume it was a problem with your copying from your console and not the file. If you are actually seeing those extra characters before the error path on your console, those are byte order markers, which are placed at the beginning of text files to specify the text encoding the file is in. All of my m3u files were utf-8 encoded with no BOM, so I thought that was the format's official encoding specification. So if you save as UTF8 without the BOM, there shouldn't be a problem (UTF8 is ANSI/ASCII compatible, so what you did is fine too as long as there are no file paths with characters outside the standard ANSI range) . If this happens to other people I may look into fixing it, but dealing with text encodings can be a pita.

I don't know what text editor you are using (notepad++?), but I personally recommend Editpad Pro. It's list of options is inexhaustible, and it lets you specify options like encodings and BOMs on a per file-extension basis. [Edit: I always forget to mention, its Basic version is free, but is missing some important stuff like syntax highlighting :-\ ]

As for the next error, I received that for the first time last night too when adding the absolute paths code. However, when rerunning the script a second time, I was unable to reproduce the error, so I don't know what caused it. Can you try running the same command again and see if it works the second (or third? :-) ) time? If not, I'll try and see if I can reproduce, and if still not, we may want to exchange instant message information to get it figured out. My current first-thought guess is that it's having an issue getting the Playlist's ID after creating it, so since it is already created on the second run, it cannot run into that problem.
Re: Plex Playlist Importer on 11/30/14 7:49am by clowg
Hi.

Ive tried the same command 2 more times and it produced the same error each time.
Re: Plex Playlist Importer on 11/30/14 8:19am by clowg
I'm happy to arrange a time to IM and see if we can sort it.
What time zone are you in?
Re: Plex Playlist Importer on 12/01/14 6:49pm by Dakusan
I think I found the problem. The plex database can apparently have NULL values for a song's duration. If you are running from code, replace line 109:
Code: [Select]
DBFileDurations.append(Val[1])with:
Code: [Select]
DBFileDurations.append(Val[1] if Val[1] is not None else 0)
If that doesn't work, or you aren't running from code, I'll shoot you an email with my IM info (I see you provided it to the forum). I am in CST, but I have very odd hours so that doesn't necessarily mean much ^_^.

If that DOES work, let me know so I can make a final code commit.
Re: Plex Playlist Importer on 12/01/14 8:08pm by clowg
I am running from the binary. I'm not a coder  :(

Email me yr contact info - Skype OK?
Re: Plex Playlist Importer on 12/04/14 7:59pm by clowg
Hi there,I have given Plex a couple of days to run background refresh tasks etc, and it hasn’t helped. 

The two Playlists that I have imported cannot display the track listing - either in Web or PHT views. 
PHT tries to load the view for about 30 seconds and then comes up with an error - which I can't remember the exact wording of at the moment. 

It gave me a black screen a couple of times, which I could 'exit' back to the main Playlist list after it timed out on trying to load the track list. 

It can play the Playlist though.  Just select the Playlist with the arrow keys and then press play and it plays in the order in the original playlist file. 

Of course without being able to enter into the Playlist track listing I can't select Random Play.
Is there anything else I can do to track down what has gone wrong with the imported Playlist? There is obviously something different about it compared to the manually created ones which work fine.

Cheers,
Re: Plex Playlist Importer on 12/04/14 8:04pm by Dakusan
I've only tested this on my 2 home servers, both of  which are running the latest Plex software. I've imported dozens of  playlists just fine, but all the ones I use have the songs stored  locally.
 
My personal guess at the moment from the variables I have been given  (just as likely to be wrong as right): Plex is trying to verify the  existence of all files in the playlist as part of the startup process  before it displays anything, or wanting to pull something  small out of the files for some reason. Each networked file is probably  taking like half a second to verify, so the list ends up timing out.
 
The background stuff you are talking about should only run once the  first time you add new content to plex (e.x. import a directory into  your plex database). You can see when that start and finished on the  plex web server interface, so that shouldn't be the  problem. Once it's loaded, it's in the database for instant lookup.
 
Things I would personally try to debug the problem to start narrowing down problems:
  • Make sure your plex server is up to date
  • Try manually creating a playlist with a few local songs to see what happens (Not using my script)
  • If that works, make a .m3u with the same songs, and see if it imports ok into a new playlist
  • Try doing the same thing with remote songs
  • Do incrementally larger imports into different playlists (50 songs, 100 songs, 200 songs...)
If it fails during one of those steps, that can give a clue to the problem.
 
Oh, it would also help to Google the error you get. That is always the best starting point to debugging a problem.
Re: Plex Playlist Importer on 12/05/14 3:04am by clowg
You guessed it right.  A playlist with 150 remote songs works.  A playlist with 160 remote songs doesn't.

G.
Re: Plex Playlist Importer on 12/05/14 8:34pm by Dakusan
Weird. You should report that as a bug to Plex. Best way you can help open source software as a non coder ^_^
Re: Plex Playlist Importer on 12/05/14 11:12pm by clowg
I will do it now.
Re: Plex Playlist Importer on 02/12/15 5:33am by Dakusan
OK. This is really weird, somehow your message was deleted sometime in the last few weeks, but fortunately the monthly SQL backup caught it and I was able to restore it.

Sorry for taking so long to get back to you on this, but since you were able to take care of everything yourself, I wasn't considering it too urgent :-)

All of your suggestions are really great and I'll most likely add most of them to my next version when I get the chance. Thanks for all the great suggestions!

As for the Python version... yeah... I had to make an active choice when starting this project which one I wanted to use, and I forget why, but I decided to go with the latest version of Python, even though I knew it wasn't as well supported/deployed. If it's not too much work, I'll see if I can't get it compiling in v2.7.x also.
Re: Plex Playlist Importer on 05/09/16 7:37pm by Dakusan
@Pierre: Are you sure you are running Python3 and not Python2?

@ulle: I'm not exactly sure what you are trying to ask. Any user could potentially use the software as long as they meet 3 conditions:
  • They have python 3 installed (and any dependent libraries)
  • They have access to the playlist and the files inside the playlist
  • They have access to write to the plex database file
Re: Plex Playlist Importer on 06/07/16 4:29am by Skipper42
Background: running PlexPlaylistImporter.exe on the PMS host (Win 7 x64 SP1 fully patched, PMS 0.9.16.6.1993 - latest version).

Testing import of an m3u music playlist; edited to ensure full paths to all mp3 files including drive letter are in the m3u.

I get the prompt to create the new PMS playlist (it doesn't already exist), and after answering 'y' to the prompt, I get the following:
DB Error: no such module: fts4

Explicitly identifying the PMS database path and filename in the command line made no difference.

Do I separately need to install and run Python 3, or is the one on the (running) PMS sufficient?

TIA,
S
Re: Plex Playlist Importer on 06/07/16 11:42am by Dakusan
From an internet search "This error is happening because of [your] build of SQLite does not include the FTS modules." So I'd guess that either your sqlite3 libs, or python sqlite3 libs need to be updated. I really need to get a windows executable compiled for it...

You might want to try using the provided executable instead. It is at the top of the project page under "Downloads: Binary".

[Edit] After rereading your message... are you already using the executable I provided?
Re: Plex Playlist Importer on 06/07/16 4:22pm by Skipper42
You're correct - I'm using your binary from here.

I copied all the content from the downloaded Zip archive to a corresponding folder: C:\Program Files (x86)\PlexPlaylistImporter\.

I don't have SQL Lite installed per se; I only have PMS (latest version) installed and running. Do I need to do anything else to ensure the correct DLLs get used?

Thanks!
Re: Plex Playlist Importer on 06/07/16 6:33pm by Dakusan
Just to make sure... you do have the sqlite3.dll in the same directory as the PlexPlaylistImporter.exe, right?

Yeah, my next guess was going to be that it was choosing the wrong dll.

The article I linked says:
  • If a DLL with the same module name is already loaded in memory, the  system uses the loaded DLL, no matter which directory it is in. The  system does not search for the DLL.
  • If the  DLL is on the list of known DLLs for the version of Windows  on which the application is running, the system uses its copy of the  known DLL (and the known DLL's dependent DLLs, if any). The system does  not search for the DLL. For a list of known DLLs on the current system,  see the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs.     
So it is most likely the first one. Is it possible for you to temporarily unload the program that is using it? You can also search for DLL usage handles by using Process Explorer. In the find menu there is a "Find Handle or DLL... (Ctrl+F)" option.
If you are unable to stop the other process, you can try manually replacing the .dll in its folder, but that is risky
Re: Plex Playlist Importer on 06/07/16 8:16pm by Skipper42
Yes, the sqlite3.dll is in the same folder as the executable.
A quick check in Process Explorer shows three other active instances of two separate sqlite3.dll copies: - Backup software infrastructure component; I may be able to stop this service, reboot, and proceed without having the service restart, so it's at least something I can try. - PlexDLNAServer.exe - PMS
If I don't need PMS running when doing the import, this should be manageable. Both PMS and the DLNA server use the same copy in the PMS directory.
I'll note that a Win Explorer search found 9 separate copies of sqlite3.dll, all with different dates and sizes, including some not currently active: - PlexPlaylistImporter - PMS - MediaMonkey (which I'm using til I get music playlist imports to work in PMS) - Kodi (ditto; horse race for which gets there first) - Backup software - Security software
Thanks!
Re: Plex Playlist Importer on 06/08/16 7:12pm by Skipper42
I've disabled the services using sqllite3.dll, rebooted, and confirmed those services are not running. I've also not started PMS.
When I run the batch file that launches PlexPlaylistImporter.exe, however, after answering 'y' to create the new PMS playlist, I get the same error:   Plex playlist is not already created. Would you like to create it now (y/n)? y   DB Error: no such module: fts4
I've verified in the Registry (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs) and in Process Explorer that the sqllite3.dll in the PlexPlaylistImporter.exe folder – C:\Program Files (x86)\PlexPlaylistImporter – is not known to the system. The same is true of the python34.dll in the same PPI folder. It looks to me like the program is failing to find and load the DLLs.
Any suggestions?
Thanks!
Re: Plex Playlist Importer on 06/09/16 5:01pm by Skipper42
Googled the problem and found this:
https://www.sqlite.org/fts3.html#section_2
  • If a build of SQLite does not include the FTS modules, then any attempt to prepare an SQL statement to create an FTS3 or FTS4 table or to drop or access an existing FTS table in any way will fail. The error message returned will be similar to "no such module: ftsN" (where N is either 3 or 4).
Since that seemed to suggest the sqlite3.dll in your executable binary distro was built without FTS4, I hunted down an x86 version that did (the x64 version didn't work, since your app is x86, apparently). After putting the DLLs, the executable, and the importing .m3u all in the same directory...
IT WORKED! I now have the test .m3u successfully imported into the Plex Playlists, and it plays!
I can't believe the Plex folks cannot figure out how to do this on their own.  You're my hero for the day!
Many thanks for your patience, advice and hard work on this.
Re: Plex Playlist Importer on 06/09/16 7:00pm by Dakusan
Awesome! Glad you got it working! Sorry I couldn't have been more help on fixing it. Busy busy.

Very interesting @ the proc architecture. I had never even thought about seeing what arch the files compiled as. Though x86 makes sense for the extended compatibility, which for a project like this, is appropriate. Will definitely keep it in mind for the future
Re: Plex Playlist Importer on 06/11/16 10:56pm by Skipper42
For some reason, I'm unable to reproduce the working import function with other m3u playlists.
I'm getting the same gibberish characters as the earlier poster (Clowg) at the front of the first line; switching to relative paths from absolute paths doesn't help. Doesn't matter whether the line is blank or an actual reference to an mp3 file. The references are correct; I've verified that with Explorer.
I've used mp3Tag, Notepad, and Wordpad all. Saving as UTF-8, Unicode, Unicode Big Endian... none of that changes the outcome. I'm also not getting the prompt to create the new playlist.
Here's what I get:ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist): E:\Users\Public\Music\Music Library\<artist>\<album>\<song>.mp3
Also doesn't matter whether I'm running from the command line, from a batch file, or where the playlist file is relative to PlexPlaylistImporter.exe. I'm specifying in the command line the filename of the playlist, the playlist name, and the file path and name of the PMS database. Doesn't matter whether or not PMS is running.
Finally, mp3Tag has no problem finding the associated mp3's from the playlist when opening the playlist .m3u in mp3Tag.
Hope this helps you diagnose the fault.
Thanks!
Re: Plex Playlist Importer on 06/12/16 1:58am by Dakusan
Whatever program you used to save the playlist file as UTF8 is adding a BOM (byte order marker) to the beginning of the file, specifically, the utf8 BOM " ". It needs to not be in the file. You can generally set a setting in your text editor to not include it. I'll see if I can't make an update soon to bypass this problem.
Re: Plex Playlist Importer on 06/13/16 8:53pm by Skipper42
Well, I solved (kindasorta) the basic problem of BOM inclusion by installing EditPad Lite (freeware, unlike the Pro version), which permits me to create (Options menu) an M3U file type and specify UTF-8 and no BOM, and to replace the existing BOM with none if found. I can then open an .m3u created in another app (e.g., MediaMonkey, mp3tag, Notepad) and resave it with no BOM.
Unless there are character codes beyond the basic alphabet (see below for a description of this newly discovered problem), the .m3u will then import successfully...
...kindasorta. After the first two successful playlist imports, PMS stopped displaying the total duration (length) of the playlist, reporting only 'x Items' where x is the track count. Further, when the playlist is opened in Plex, all the track lengths are shown as 0:00. A quick check with mp3tag showed the metadata for length as indeed being included in the .mp3 file, and when one browses to the album in Plex, it, too, has the track length correctly shown. In both cases -- playlist or music browse -- Plex plays the track correctly. Interestingly, once a track has been played from the playlist, suddenly PMS finds its brain and correctly displays the track length on the Playlist page. There's no Refresh opportunity in the Playlist dialogue to force this otherwise. After the track lengths are displayed correctly once, they're displayed correctly henceforth, along with the overall playlist length on the main Playlist browse page. I noticed that it took a while for the data to propagate there, however. Even after playing all tracks in a 1:46 duration playlist (duration doesn't matter, simply starting each track is sufficient to update the track length display after a few seconds), the initial value shown for playlist length upon return to the main Playlist page was 20 minutes. Returning to the track listing for the playlist showed that indeed all the track lengths were still there, and on return up to the main Playlist page, suddenly the duration was the correct 1:46 value.
I'm unable from where I sit to determine whether this is a PMS bug or a PPI problem; perhaps there's a missing commit in the PPI SQL update query for the track metadata records, and absent some refresh mechanism, takes PMS a while to update itself?
Now on to the character set/codespace problem.
If the path (artist, album) or track filename contain other than basic alphanumeric characters thru ~ (code < 128 or 007F), then you run into problems like the following, where PPI can't find the track .mp3 to get its metadata:
Actual mp3 file record in m3u playlist:<path>\Music Library\Saint-Saëns\Violin Concerto No. 3\02 Romance for violin & orchestra in C major, Op 48.mp3
PPI import error:ListImporter 'Winamp playlist': Cannot find file listed in playlist (must be relative to the playlist):<path>\Music Library\Saint-Sa\xc3«ns\Violin Concerto No. 3\02 Romance for violin & orchestra in C major, Op 48.mp3
In this case, the e-umlaut (ë) has a decimal character code of 235 (+00EB).
Doesn't matter whether <path> in this example is relative ("dot notation") or absolute (<drive letter>:<folder path>). Just FYI - the error message always says "relative" even if absolute path addressing is used (likely an artifact of your absolute addressing quick fix).
Since PMS correctly renders the special characters and correctly finds and plays the track, and since other apps (MediaMonkey, mp3tag, Notepad, EditPad Lite) correctly find/render/play the .mp3 file, this flaw appears to be inside PPI.
I checked and it also doesn't matter whether the character set used is UTF-8 or Western European.
This would seem thus that PPI's character set issues are larger than just ignoring the UTF-8 BOM in an .m3u file.
I know that's not good news, but do hope there's enough info here for you to diagnose and correct the bug; I've made enough progress with a handful of successful playlist imports to be excited about the prospect of overall success!
Thanks again for all you've done on this.
Re: Plex Playlist Importer on 06/16/16 10:13pm by Dakusan
Sorry for taking so long on this, should be able to look into this and update the software tomorrow or the day after.
Re: Plex Playlist Importer on 06/18/16 1:03am by Dakusan
OK, my forum has been randomly deleting posts  >:( I just recovered this from the trashbin.

Pierre: it requires python3. I will be making a minor change soon to verify it uses that.

ulle: Playlists are not user based, they are library based. If you mean you want to use a non-admin user to import a playlist, it is possible as long as they have access to the plex sqllite3 file.
Re: Plex Playlist Importer on 06/18/16 1:05am by Dakusan
OK, my forum is acting super crazy right now and not showing your last post >.<; here it is again, and I am working on the stuff now.

Skipper42:
Quote
Well, I solved (kindasorta) the basic problem of BOM inclusion by  installing EditPad Lite (freeware, unlike the Pro version), which  permits me to create (Options menu) an M3U file type and specify UTF-8  and no BOM, and to replace the existing BOM with none if found. I can  then open an .m3u created in another app (e.g., MediaMonkey, mp3tag,  Notepad) and resave it with no BOM.
Unless there are character codes  beyond the basic alphabet (see below for a description of this newly  discovered problem), the .m3u will then import successfully...
...kindasorta.  After the first two successful playlist imports, PMS stopped displaying  the total duration (length) of the playlist, reporting only 'x Items'  where x is the track count. Further, when the playlist is opened in  Plex, all the track lengths are shown as 0:00. A quick check with mp3tag  showed the metadata for length as indeed being included in the .mp3  file, and when one browses to the album in Plex, it, too, has the track  length correctly shown. In both cases -- playlist or music browse --  Plex plays the track correctly. Interestingly, once a track has been  played from the playlist, suddenly PMS finds its brain and correctly  displays the track length on the Playlist page. There's no Refresh  opportunity in the Playlist dialogue to force this otherwise. After the  track lengths are displayed correctly once, they're displayed correctly  henceforth, along with the overall playlist length on the main Playlist  browse page. I noticed that it took a while for the data to propagate  there, however. Even after playing all tracks in a 1:46 duration  playlist (duration doesn't matter, simply starting each track is  sufficient to update the track length display after a few seconds), the  initial value shown for playlist length upon return to the main Playlist  page was 20 minutes. Returning to the track listing for the playlist  showed that indeed all the track lengths were still there, and on return  up to the main Playlist page, suddenly the duration was the correct  1:46 value.
I'm unable from where I sit to determine whether this is a  PMS bug or a PPI problem; perhaps there's a missing commit in the PPI  SQL update query for the track metadata records, and absent some refresh  mechanism, takes PMS a while to update itself?
Now on to the character set/codespace problem.
If  the path (artist, album) or track filename contain other than basic  alphanumeric characters thru ~ (code < 128 or 007F), then you run  into problems like the following, where PPI can't find the track .mp3 to  get its metadata:
Actual mp3 file record in m3u  playlist:<path>\Music Library\Saint-Saëns\Violin Concerto No. 3\02  Romance for violin & orchestra in C major, Op 48.mp3
PPI import  error:ListImporter 'Winamp playlist': Cannot find file listed in  playlist (must be relative to the playlist):<path>\Music  Library\Saint-Sa\xc3«ns\Violin Concerto No. 3\02 Romance for violin  & orchestra in C major, Op 48.mp3
In this case, the e-umlaut (ë) has a decimal character code of 235 (+00EB).
Doesn't  matter whether <path> in this example is relative ("dot  notation") or absolute (<drive letter>:<folder path>). Just  FYI - the error message always says "relative" even if absolute path  addressing is used (likely an artifact of your absolute addressing quick  fix).
Since PMS correctly renders the special characters and  correctly finds and plays the track, and since other apps (MediaMonkey,  mp3tag, Notepad, EditPad Lite) correctly find/render/play the .mp3 file,  this flaw appears to be inside PPI.
I checked and it also doesn't matter whether the character set used is UTF-8 or Western European.
This would seem thus that PPI's character set issues are larger than just ignoring the UTF-8 BOM in an .m3u file.
I  know that's not good news, but do hope there's enough info here for you  to diagnose and correct the bug; I've made enough progress with a  handful of successful playlist imports to be excited about the prospect  of overall success!
Re: Plex Playlist Importer on 06/18/16 3:17am by Dakusan
OK, I merged in another authors branch to fix the linux absolute path problems. I fixed the UTF8 bom problem, so you don't have to worry about that anymore either. I also added cygwin compatibility.

I just tested with a utf8 m3u file and file names with Japanese characters and it imported fine (had to set up special test cases). Are you absolutely sure your file is utf8? Assuming your command line is in utf8, when the error is shown it should have the proper filename at the end of the error.

I also just tried to save a list from an older version of winamp and it just put question marks for any of the japanese characters ~.~

I also just did a massive import of all my music into plex (have been rebuilding my library). And interestingly enough, 0 of my 100+ files that had japanese characters even imported into plex!  >:( So are you also sure those files are actually in Plex?

There have been weird errors in the past regarding playlist and file lengths in plex. One example is that if your playlist has more than 150 entries, plex no longer recognizes it. The person on my forum that discovered it submitted a bug report to plex. Not sure if it was ever resolved.

But anywho, the playtimes are grabbed from what is already in the plex database, so it is possible it had not recorded them yet at the time you did your playlist import. Or perhaps they are storing additional information about the tracks elsewhere and not updating the main table. I didn't try very hard on that part, as I knew it would auto correct. Once the file is in the plex server playlist, my program no longer has any control over its values.

The error that you are showing regarding the charset looks like it might be b/c you are not in utf8 mode in your tty console. Also, the character you mentioned, c3, is "Ã", which is interesting.  I think I see that one a lot when there are encoding problems. If the board lets you, any chance you can post your playlist file with just that one song for me to inspect. And western european character set would definitely not work with the importer. UTF8 is essential.

Also, have you been running via the executable, or the python scripts? If the latter, I have the newest source up on github @ https://github.com/dakusan/PlexPlaylistImporter/ . If you are unable to run from source, I'll get an executable compiled for you (its a minor PITA). Not wanting to release a new version on the site until your problem is resolved
Re: Plex Playlist Importer on 06/20/16 11:52pm by Skipper42

A. I'm as sure as I can be with the tools at my disposal that these .m3u's are UTF-8:
1. They're exports from Mp3tag, which allows me to establish the output character set in the .mte export spec (attached). It's set to UTF-8.
2. Notepad reports they're UTF-8.
3. I used EditPad Lite to force the text file to be no-BOM, UTF-8.

B. I'm certain the underlying .mp3 files are present in both the library at the location found and are individually playable in Plex (and thus in the Plex Library). The .mp3 files appear in all Plex Library listings irrespective of filtering (Album, Artist...).

C. I'm using your Windows .exe only; I do not have Python running separately. I'm running in a Win 7 x64 environment, in case that matters; machine resources should not be an issue (quad-core i7, 32GB RAM).

D. The longest playlist I've tried to import (5.5hr running time) has only 73 tracks, but I appreciate the heads-up on the 150 track limit.

E. Also attached per your request is a fragment of the playlist with the problematic character set entry described above.

Hope this helps. Thanks again very much for your efforts.
Re: Plex Playlist Importer on 06/25/16 6:24am by Dakusan
I'm working on updating the software this weekend.
Re: Plex Playlist Importer on 07/01/16 7:16am by Dakusan
I have made multiple updates to the software and recompiled it. I have attached it to this post if you want to check it out. I confirmed that it worked fine in command prompt with your m3u file. Update log is on github.

P.S. If possible, please let me know within the next few days if all is well now. Would like to get the confirmed updates and compilation up on my website.
Re: Plex Playlist Importer on 07/04/16 6:15pm by Skipper42
The latest ListImporter version for Windows works like a champ - thanks!I've successfully tested with:
  • Both relative and absolute paths to track files in the m3u
  • With m3u's exported from MediaMonkey (aka MM; ver 4.1.12.1798; I'll let you know if this changes with the latest version, 4.1.13.1801)
  • With m3u's exported from Mp3tag, and
  • With m3u's exported from my iBasso DX90.
I confirmed that byte order no longer matters; I no longer have to go thru the extra pass through EditPad Lite to drop the BOM.If an actual file cannot be found from its m3u reference, I've confirmed that ListImporter correctly notifies the user of the path and filename of the file it cannot find (with one exception; please see below).If errors are encountered, ListImporter correctly sets Errorlevel so it can be checked in a batch file. Thus, I can use this to avoid prematurely archiving failed import playlists until the issues are resolved.I've not found a good way to execute ListImporter from a folder not containing both the .exe and all its .dll files. This would be useful but is not essential. I do have to manage Acronis' insistence on restarting one of its supposedly unneeded services that uses a different sqlite3.dll. The sqlite3.dll used by the latest version of PMS no longer conflicts.I did find a couple of small residual issues plus a couple of what you're free to view as extremely minor quibbles.The first of two small issues is that ListImporter is intolerant of blank lines in the m3u (e.g., at the end). This leads to the mysterious error message that the track file must be located relative to the playlist, but since the reference line is a blank, there's no file reported. Took some lengthy trial and error to find what was causing the glitch. I'll note that part of my confusion was that the same error message ("relative to") appeared irrespective of whether I was using dot notation relative paths or absolute paths for the track references (I suspect this is a holdover from versions prior to those permitting absolute path references).The second small issue is that any error in one track reference causes the entire import to abort with Errorlevel set to 1. That meant the original m3u with one or more blank lines would abort, while trying to identify the problem track reference by successive runs each with a new reference added from the original always was successful. That's actually how I tumbled to the blank line intolerance.My benchmark for whether the m3u had valid references has been Florian Heidenreich's excellent freeware Mp3tag (http://www.mp3tag.de/en/). In sum, if Mp3tag can import all the rows successfully, then I can safely assume the m3u is valid; it reports any track files it cannot find. That means anyone should be able to debug issues with ListImporter using Mp3tag to test the m3u's track file references for validity (plus verifying that the track files can be played independently in Plex).I also use Mp3tag to convert relative paths in m3u's to absolute or relative paths matching the location of the m3u file to be imported to Plex. MM's relative paths are relative to where the m3u is originally stored). MM is a far richer playlist editor/maker than Plex, so combining your tool with my methods gives me the best of both worlds.The .mte export configuration file I use in Mp3tag is:$filename(<path>\to_import\Plex.m3u,utf-8)$loop(%_counter%)%_folderpath%%_filename_ext%$loopend()...with care to have the file end after the $loopend() statement so as not to generate the blank line that ListImporter thinks is an invalid track reference. In my case, E:\Users\Public\Music\My Playlists\! Plex Playlists\ is the folder also containing the ListImporter .exe, .dll's and ppibatch.bat file.Once exported, I rename Plex.m3u to whatever I want the playlist name to be. Note: to export with relative vs. absolute paths, change %_folderpath% to %_folderpath_rel%, tho ListImporter always worked irrespective of which was used.The two minor quibbles are (a) execution message output appears to go to stderr vs. stdout, which can interfere with batch file output piping for logging/analysis purposes, and (b) delays/problems updating the track length once the playlist has been imported into Plex (an issue I noted in a previous post).The batch file I use (ppibatch.bat, attached) presumes the m3u playlists to be imported are in a particular 'to_import' folder, and if the import of each is successful, the m3u file is moved to an 'imported' folder in the same hierarchy.In the batch file, I used UTF-8 encoding, but set it explicitly in the command line vs. relying on the default. Ditto the file type setting (explicitly 'mp3' vs. default). These were more for self-documentation than any requirement to do so; worked fine with the defaults. Ditto the location of the Plex database.When piped to a log file, each execution in my batch file generates an entry of the following form:Sat 07/02/2016 14:38:28.48PlexPlaylistImporter.exe -f -e utf-8 -t m3u "<path>\to_import\5hr Playlist.m3u" "5hr Playlist"73 items imported        1 file(s) moved....showing there could be value in having error messages, etc. in the consolidated app+OS output also.The track length update problem seems to be avoidable if one turns on frequent Library updating and updating of the Library with any change to the Library, prior to importing the m3u. If that's not done, the track lengths of some tracks remain at 0:00 after import. This also means the overall playlist length will be misreported until each of the 0:00 tracks is launched and another track launched afterward, at which point Plex updates the playlist track length entry and overall playlist length. Even forcing Library updates failed to update the track and playlist lengths.I cannot tell from info available to me here whether the track length update problem is a Plex bug/feature (they clearly have yet to envision importing m3u playlists, and thus without your tool would have no way to test for this bug!) or whether there's some other additional Plex database field references that need updating in your update query SQL (e.g., possibley a field in a different table from the main Playlist records). Regardless, once I turned on frequent Library updating/updating after every change, the problem seemed to disappear.With all that in mind, and given the general end-to-end utility now available, I recommend you post an update to the Plex Forum that details these working methods. Please feel free to share my Mp3tag export .mte above and batch import method's .bat file attached in your post.Thanks again very much for all your efforts here. This has now made Plex finally usable for me!
Re: Plex Playlist Importer on 07/05/16 4:53am by Dakusan
Yikes. It feels like on a lot of this you are going to way more trouble than should be needed :-\

Quote
I've not found a good way to execute ListImporter from a folder not containing both the .exe and all its .dll files. This would be useful but is not essential. I do have to manage Acronis' insistence on restarting one of its supposedly unneeded services that uses a different sqlite3.dll. The sqlite3.dll used by the latest version of PMS no longer conflicts.
I think I might actually have been providing a bad sqlite3.dll with my previous releases, which could have been the problem. That is fixed in the new archive I had sent you. I don't really see an easier way to do distribute this without the dlls as separate files in the archive. I'm not big on installers.
Quote
The first of two small issues is that ListImporter is intolerant of blank lines in the m3u (e.g., at the end).
I have updated the code to ignore lines that are blank or only have whitespace. It is up on github and I will included it on my next executable install.
Quote
The second small issue is that any error in one track reference causes the entire import to abort with Errorlevel set to 1.  [...]
This is always something I haven't really been sure how to handle. Do you have any suggestions? I guess I could include a batch error mode that would be the default...
Quote
(a) execution message output appears to go to stderr vs. stdout, which can interfere with batch file output piping for logging/analysis purposes
I believe throwing errors to stderr is the proper behavior. Would it help if I included a parameter flag that instead pushed everything through stdout? In bash shell environments, it's as simple as adding "2>&1" after your command. Not sure about windows.
I think that covers everything you mentioned, minus track length. I just looked in the DB, and from a quick glance, I'm not actually sure where the track durations are stored for items on a playlist. I think I skipped that since I wanted to make a minimum number of modifications to the database and knew it would auto correct.

[Edit] P.S. The latest version (have not compiled into exe yet) allows dragging playlists onto the executable.
Re: Plex Playlist Importer on 07/26/16 11:12pm by Dakusan
You mean a separate Plex pass user, correct? One in which you would have had to of shared your libraries with via Libraries->...->Share ? (Or shares visible via plex.tv->launch->settings->users->friends)
Re: Plex Playlist Importer on 02/14/17 2:23pm by Dakusan
In PlexPlaylistImporter.py, below line 177
Code: [Select]
#Insert the items into the playlistAdd the following line
Code: [Select]
Cur.execute('DELETE FROM play_queue_generators WHERE playlist_id=?', (PlexPlaylistID,))
I have not tested this code, so make sure to backup your database before attempting it.
Re: Plex Playlist Importer on 02/17/17 6:47am by Dakusan
Same disclaimer. Guess I gotta add command line flags for this and update on github. Already have 1 pull request on github. PITA cause I don't release code without thoroughly testing.

Line 137. Change
Code: [Select]
sys.exit("File not found in DB: "+FilePath)to
Code: [Select]
continueWhen I update on github it will throw a warning instead.
Re: Plex Playlist Importer on 06/19/17 7:09pm by Dakusan
"DB Error: no such module: fts4" indicates an outdated or incomplete sqlite3 version. Google also points out that this happens when trying to compile for iOS, or possibly osx.
Re: Plex Playlist Importer on 06/24/17 2:47pm by Dakusan
First, "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" needs to be quoted, since it has spaces, or your command line interpreter will think those are separate parameters.

I'm surprised it decided to import at all with what you gave it, since you gave an unquoted (and therefore bogus) path to the database. I'm guessing it found the path on its own so it didn't error out.

Second, you only gave the "Playlist_Path" parameter and not a "Plex_Playlist_Name" parameter.
Re: Plex Playlist Importer on 06/26/17 5:35am by Dakusan
Ahah. Should have thought of that. The latest version on github has options for plex user accounts, but I don't think I've put it on my site yet.
Re: Plex Playlist Importer on 07/07/17 7:52pm by Dakusan
Most likely a database update :-\ I'll take a look at it as soon as I have a chance. (Should be sometime in the next week)
Re: Plex Playlist Importer on 07/24/17 3:00pm by Dakusan
I'm very sorry to everyone who has been waiting for me to get some updates done. I've just been super busy lately and getting to spend time on this project has just been impossible. I will be getting to it as soon as I can.
Re: Plex Playlist Importer on 01/30/19 4:38am by clowg
Hi @Dakusan

I have come back to your script/.exe because Plex threw away one of my previously imported m3u Playlists.Im getting this error:
PlexPlaylistImporter.exe -p "D:\PlexServer\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db" "D:\7mc\plexplaylistimporter\top 550 songs.m3u" Top550SongsPlex playlist is not already created. Would you like to create it now (y/n)? y
DB Error: no such collation sequence: naturalsort

This is on Windows 10 x64, on the Plex Server console.  The exe worked really hard for about 10 minutes before coming up with the playlist creation question, and then immediately failed with the error.Any ideas on that one?
G.
Re: Plex Playlist Importer on 01/30/19 4:52am by clowg
PS:  There is a new API available for Playlist importing:https://forums.plex.tv/t/can-plexamp-read-and-use-m3u-playlists/234179/32
G.