Exporting m3u playlist with Plex

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)

About the Author...

Slides from LISA 2019 Linux systems troubleshooting #LISA2019 https://t.co/D4dMKflK6R Tue Oct 29 05:59:30 +0000 2019

https://t.co/AGeihMALAv configuring grub2 with EFI Fri Sep 13 05:20:01 +0000 2019

I published a Thing on @thingiverse! https://t.co/IYpRyEb7Hz #thingalert Tue Jul 23 19:27:57 +0000 2019

Nokogiri install on MacOSX https://t.co/v3An0miW9L Fri Jul 12 15:06:49 +0000 2019

HTML email with plain mailer plugin on Jenkins https://t.co/Z6FSDMDjy8 Thu Jul 11 21:07:25 +0000 2019