Sometimes I’ve found myself trying to share some iTunes playlists with friends, or even with myself but found no easy solution for it. iTunes exports XML files with the information about the songs, so I figured there would be a way to use the path of the songs to copy them into a folder that could be shared either to friends, or to my android phone.
First thing was to explore the XML that iTunes exports. After some looking around, we can see that the bottom part of the file contains the information of the playlist and the ordering of the songs by Track ID:
On the top of the XML, we see that the information of the songs is laid down in dict entries:
With this information we can start doing some coding. First, we parse our tree and lay down the general actions we need to take the tree and extract the information about the songs, particularly, we want to get their ID, their paths, and filenames.
After doing so, we want to obtain the ordering of the songs in the playlist.
With these pieces in place, we sort the songs dictionaries according to the sorting provided by the playlist info. Which takes us to the final wrapper:
Once we have our final wrapper, we simply put it all together by adding a copyfile call from shutil: