Skip to content

Instantly share code, notes, and snippets.

@jachin
Created December 12, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jachin/b9398cc4c0fa8f4eb973a7aeddf0b407 to your computer and use it in GitHub Desktop.
Save jachin/b9398cc4c0fa8f4eb973a7aeddf0b407 to your computer and use it in GitHub Desktop.
This little script takes a XML iTunes playlist file and makes an reStructuredText list out of the playlist. There's more features to add, but this is a start.
#! /usr/bin/env python3
import argparse
import plistlib
if (__name__ == "__main__"):
parser = argparse.ArgumentParser()
parser.add_argument("playlist_file")
args = parser.parse_args()
with open(args.playlist_file, 'rb') as fp:
pl = plistlib.load(fp)
tracks = pl['Tracks']
albums = []
for item in pl['Playlists'][0]['Playlist Items']:
track_id = str(item['Track ID'])
track = tracks[track_id]
print("#. *{}* - **{}** - `{}`_\n".format(
track['Name'],
track['Artist'],
track['Album'])
)
if track['Album'] not in albums:
albums.append(track['Album'])
for album in albums:
# TODO Look uplink to the album.
print(".. _{}: https://blablabla.com\n".format(album))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment