{"id":2263,"date":"2009-01-02T20:50:04","date_gmt":"2009-01-03T02:50:04","guid":{"rendered":"http:\/\/granades.com\/?p=2263"},"modified":"2009-06-15T10:01:46","modified_gmt":"2009-06-15T15:01:46","slug":"converting-itunes-playlists-to-m3u-playlists","status":"publish","type":"post","link":"https:\/\/granades.com\/?p=2263","title":{"rendered":"Converting iTunes Playlists to M3U Playlists"},"content":{"rendered":"<p>Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts <a href=\"http:\/\/en.wikipedia.org\/wiki\/M3U\">M3U playlists<\/a>. iTunes, however, will only export playlists as plain text files or in their plist XML format. Why? Because Apple. So I&#8217;m left needing to convert the XML files to M3U format.<\/p>\n<p>Luckily, I know Python. Even more luckily, so do a lot of better programmers than I.<\/p>\n<p>Digging through some mailing lists turned up a <a href=\"http:\/\/online.effbot.org\/2005_03_01_archive.htm\">plist XML format parser<\/a> that Frederik Lundh wrote. Sadly, that link I just gave no longer works. Thank goodness for the Wayback Machine! To keep you from having to re-create his code, I stuck it into a <a href=\"\/downloads\/plistloader.py\">Python module called &#8220;plistloader&#8221;<\/a>.<\/p>\n<pre><code>\r\ntry:\r\n    from xml.etree.cElementTree import iterparse\r\nexcept ImportError:\r\n    from xml.etree import iterparse\r\nimport base64, datetime, re, os\r\n\r\nunmarshallers = {\r\n\r\n    # collections                                                                \r\n    \"array\": lambda x: [v.text for v in x],\r\n    \"dict\": lambda x:\r\n        dict((x[i].text, x[i+1].text) for i in range(0, len(x), 2)),\r\n    \"key\": lambda x: x.text or \"\",\r\n\r\n    # simple types                                                               \r\n    \"string\": lambda x: x.text or \"\",\r\n    \"data\": lambda x: base64.decodestring(x.text or \"\"),\r\n    \"date\": lambda x:\r\n        datetime.datetime(*map(int, re.findall(\"\\d+\", x.text))),\r\n    \"true\": lambda x: True,\r\n    \"false\": lambda x: False,\r\n    \"real\": lambda x: float(x.text),\r\n    \"integer\": lambda x: int(x.text),\r\n\r\n}\r\n\r\ndef load(file):\r\n    parser = iterparse(file)\r\n    for action, elem in parser:\r\n        unmarshal = unmarshallers.get(elem.tag)\r\n        if unmarshal:\r\n            data = unmarshal(elem)\r\n            elem.clear()\r\n            elem.text = data\r\n        elif elem.tag != \"plist\":\r\n           raise IOError(\"unknown plist type: %r\" % elem.tag)\r\n    return parser.root[0].text\r\n<\/code><\/pre>\n<p>Do you see what he did there? Frederik used a dictionary filled with anonymous functions that convert each kind of XML data the plist might contain. Sexy!<\/p>\n<p><a href=\"\/downloads\/xmltom3u.py\">My code that uses plistloader is far more prosaic<\/a>.<\/p>\n<pre><code>\r\nimport sys, plistloader, os\r\n\r\n# Search-and-replace strings to adjust the mp3's locations if necessary.         \r\nsandrStrs = { \"file:\/\/localhost\/Volumes\": \"smb:\/\/sargent\" }\r\nm3uHeader = \"#EXTM3U\\n\"\r\n\r\ntry:\r\n       xmlFile = sys.argv[1]\r\nexcept IndexError:\r\n       print \"No xml file passed on the command line.\"\r\n       sys.exit()\r\n\r\nif not os.path.isfile(xmlFile):\r\n       print \"File %s doesn't exist.\"\r\n       sys.exit()\r\n\r\n# Load the playlist using the plistloader module                                 \r\nplaylist = plistloader.load(xmlFile)\r\n\r\n# Base the output filename on the input one, stripping off any '.xml'            \r\n# or similar from the right and adding in .m3u                                   \r\noutfn = xmlFile.rsplit('.',1)[0]+'.m3u'\r\n\r\noutf = open(outfn, 'w')\r\n\r\n# Write the M3U header                                                           \r\noutf.write(m3uHeader)\r\n\r\n# Iterate through the tracks to get each one's location and name                 \r\nfor k, v in playlist['Tracks'].iteritems():\r\n       # The key in this case is the track ID number. The value is               \r\n       # a dict of all information associated with the track                     \r\n       fileloc = v['Location']\r\n       for old, new in sandrStrs.iteritems():\r\n              fileloc = fileloc.replace(old, new)\r\n       outf.write(fileloc+\"\\n\")\r\n\r\noutf.close()\r\n<\/code><\/pre>\n<p>To use the script, export your iTunes playlist as an XML file. Pass the XML filename to the script. If you&#8217;re on a Mac, take a look at <a href=\"http:\/\/svn.pythonmac.org\/py2app\/py2app\/trunk\/doc\/index.html\">py2app<\/a>. It&#8217;ll let you turn the script into an application, which means you can then drop the XML file on the script and it&#8217;ll auto-process it.<\/p>\n<p>Note that the script includes a dict of search-and-replace strings in case you need to fiddle with the mp3 files&#8217; locations as reported by iTunes. As you can see in the example above, I needed to change iTunes&#8217;s &#8220;localhost&#8221; reference to match my SMB share.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export &hellip; <a href=\"https:\/\/granades.com\/?p=2263\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Converting iTunes Playlists to M3U Playlists<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2263","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/granades.com\/?p=2263\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Live Granades - Just another WordPress site\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Converting iTunes Playlists to M3U Playlists - Live Granades\" \/>\n\t\t<meta property=\"og:description\" content=\"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/granades.com\/?p=2263\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2009-01-03T02:50:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-06-15T15:01:46+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Converting iTunes Playlists to M3U Playlists - Live Granades\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#blogposting\",\"name\":\"Converting iTunes Playlists to M3U Playlists - Live Granades\",\"headline\":\"Converting iTunes Playlists to M3U Playlists\",\"author\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\"},\"datePublished\":\"2009-01-02T20:50:04+00:00\",\"dateModified\":\"2009-06-15T10:01:46+00:00\",\"inLanguage\":\"en-US\",\"commentCount\":15,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#webpage\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/granades.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#listItem\",\"name\":\"Converting iTunes Playlists to M3U Playlists\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#listItem\",\"position\":2,\"name\":\"Converting iTunes Playlists to M3U Playlists\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com#listItem\",\"name\":\"Home\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\",\"name\":\"Live Granades\",\"description\":\"Just another WordPress site\",\"url\":\"https:\\\/\\\/granades.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\",\"url\":\"https:\\\/\\\/granades.com\\\/?author=3\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#webpage\",\"url\":\"https:\\\/\\\/granades.com\\\/?p=2263\",\"name\":\"Converting iTunes Playlists to M3U Playlists - Live Granades\",\"description\":\"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2263#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"datePublished\":\"2009-01-02T20:50:04+00:00\",\"dateModified\":\"2009-06-15T10:01:46+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/granades.com\\\/#website\",\"url\":\"https:\\\/\\\/granades.com\\\/\",\"name\":\"Live Granades\",\"description\":\"Just another WordPress site\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Converting iTunes Playlists to M3U Playlists - Live Granades","description":"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export","canonical_url":"https:\/\/granades.com\/?p=2263","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/granades.com\/?p=2263#blogposting","name":"Converting iTunes Playlists to M3U Playlists - Live Granades","headline":"Converting iTunes Playlists to M3U Playlists","author":{"@id":"https:\/\/granades.com\/?author=3#author"},"publisher":{"@id":"https:\/\/granades.com\/#organization"},"datePublished":"2009-01-02T20:50:04+00:00","dateModified":"2009-06-15T10:01:46+00:00","inLanguage":"en-US","commentCount":15,"mainEntityOfPage":{"@id":"https:\/\/granades.com\/?p=2263#webpage"},"isPartOf":{"@id":"https:\/\/granades.com\/?p=2263#webpage"}},{"@type":"BreadcrumbList","@id":"https:\/\/granades.com\/?p=2263#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/granades.com#listItem","position":1,"name":"Home","item":"https:\/\/granades.com","nextItem":{"@type":"ListItem","@id":"https:\/\/granades.com\/?p=2263#listItem","name":"Converting iTunes Playlists to M3U Playlists"}},{"@type":"ListItem","@id":"https:\/\/granades.com\/?p=2263#listItem","position":2,"name":"Converting iTunes Playlists to M3U Playlists","previousItem":{"@type":"ListItem","@id":"https:\/\/granades.com#listItem","name":"Home"}}]},{"@type":"Organization","@id":"https:\/\/granades.com\/#organization","name":"Live Granades","description":"Just another WordPress site","url":"https:\/\/granades.com\/"},{"@type":"Person","@id":"https:\/\/granades.com\/?author=3#author","url":"https:\/\/granades.com\/?author=3"},{"@type":"WebPage","@id":"https:\/\/granades.com\/?p=2263#webpage","url":"https:\/\/granades.com\/?p=2263","name":"Converting iTunes Playlists to M3U Playlists - Live Granades","description":"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/granades.com\/#website"},"breadcrumb":{"@id":"https:\/\/granades.com\/?p=2263#breadcrumblist"},"author":{"@id":"https:\/\/granades.com\/?author=3#author"},"creator":{"@id":"https:\/\/granades.com\/?author=3#author"},"datePublished":"2009-01-02T20:50:04+00:00","dateModified":"2009-06-15T10:01:46+00:00"},{"@type":"WebSite","@id":"https:\/\/granades.com\/#website","url":"https:\/\/granades.com\/","name":"Live Granades","description":"Just another WordPress site","inLanguage":"en-US","publisher":{"@id":"https:\/\/granades.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"Live Granades - Just another WordPress site","og:type":"article","og:title":"Converting iTunes Playlists to M3U Playlists - Live Granades","og:description":"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export","og:url":"https:\/\/granades.com\/?p=2263","article:published_time":"2009-01-03T02:50:04+00:00","article:modified_time":"2009-06-15T15:01:46+00:00","twitter:card":"summary","twitter:title":"Converting iTunes Playlists to M3U Playlists - Live Granades","twitter:description":"Because I have a crazy byzantine digital music setup, there are times when I want to take an iTunes playlist and move it to our Xbox running XBMC, because the Xbox has nice speakers whereas none of our iTunes-running laptops do. XBMC, like all sane media players, accepts M3U playlists. iTunes, however, will only export"},"aioseo_meta_data":{"post_id":"2263","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-06-26 00:23:19","updated":"2025-11-03 06:17:17","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/granades.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tConverting iTunes Playlists to M3U Playlists\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/granades.com"},{"label":"Converting iTunes Playlists to M3U Playlists","link":"https:\/\/granades.com\/?p=2263"}],"_links":{"self":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2263"}],"version-history":[{"count":7,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":3025,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2263\/revisions\/3025"}],"wp:attachment":[{"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}