Exporting m3u playlist with Plex

By thomas, 31 October, 2017

I wanted to export my playlists with Plex, I installed Export Tools and ended up with CSV files.

I looked around and couldn't find something to convert those to m3u. I did get a m3u8 file but it didn't work with my devices...

I made a quick python script to convert the csv to m3u...it's possibly useful to someone else...maybe.


#!/usr/bin/env python

import csv
import getopt
import sys

options,remainder = getopt.getopt(sys.argv[1:], 'f:r:', ['filename=','root='])

root=''
for opt,arg in options:
if opt in ('-f', '--filename'):
filename = arg
elif opt in ('-r', '--root'):
root = arg

# convert time to seconds
def get_s(t):
try:
return sum(int(x) * 60 ** i for i,x in enumerate(reversed(t.split(":"))))
except:
return 0

try:
with open(filename,'r') as csvfile:
# skip header
next(csvfile)
playlist = csv.reader(csvfile)
print "#EXTM3U"
for song in playlist:
print "#EXTINF: %s,%s - %s" % (get_s(song[9]),song[3],song[5])
print song[-1][len(root):]
except:
print "Error opening CSV file"
sys.exit(1)