Converting Traktor NML Playlists to M3U with Ruby

There didn’t seem to be a way to do this on OSX / Mac so I thought I’d write a quick script. I have a lot of playlists in Traktor that I’d like to use else where, for instance on my phone and in VLC. The trouble is, NML is a proprietary format to Traktor. Luckily, it’s XML based and the M3U format is incredibly simple (just a list of file paths). So:


#!/usr/bin/env ruby

# Convert Traktor NML playlists to M3U

require "rubygems"
require "nokogiri"

f =[0])
@doc = Nokogiri::XML(f)
m3u =[0]+".m3u", "w+")

@doc.xpath("//LOCATION").each do |location|
volume = location.xpath("@VOLUME").to_s
dir = location.xpath("@DIR").to_s
file = location.xpath("@FILE").to_s
dir.gsub!(//:/, ‘/’)


Voila! Make sure you have the nokogiri gem installed Р we need this to handle the XML. Save the above script somewhere, make it executable with chmod o+x nml_to_m3u.rb then run it with your NML file as an argument:

[bash]./nml_to_m3u.rb ~/my_playlist.nml[/bash]

It’ll write an M3U playlist to a new file in the same folder.

Note: If you’re making these playlists for another device, you may need to alter the paths a bit. M3U can take relative paths, so if you’d exported your Traktor collection to another folder, you could just change the output line to:


and drop the resulting file in with all your exported MP3s. Hope that helps someone somewhere!