def savePlaylists(sep='\t'): for playlist in iTunes.playlists(smart=False, basic=True): print 'Writing playlist', playlist with open('Playlist-%s.tsv' % playlist, 'w') as fp: for track in playlist.track_iter: cells = [unicode(getattr(track, col)) for col in playlist_cols] write_n(fp, sep.join(cells))
def findDuplicates(): duplicates = (p for p in iTunes.playlists(smart=False, basic=True) if p.name == 'Duplicates').next() lookup = defaultdict(list) # track_key -> api.Track for track in iTunes.library.track_iter: track_key = '\t'.join([track.artist, track.album, track.name]) lookup[track_key].append(track) for track_key, tracks in lookup.iteritems(): if len(tracks) > 1: print len(tracks), track_key for track in tracks: duplicates.add_track(track)