forked from wdr1/itunes2spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itunesFunctions.py
38 lines (26 loc) · 915 Bytes
/
itunesFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
import plistlib
import logging
iTunes2spotifyMapping = None
def itunesXML2PythonDict(playlistFile):
root = plistlib.readPlist(playlistFile)
tracks = root["Tracks"]
playlist = root["Playlists"][0]["Playlist Items"]
playlistArr = []
for num, trackDict in enumerate(playlist):
trackID = str(trackDict["Track ID"])
simpleTrackDict = {}
for key, value in iTunes2spotifyMapping.items():
simpleTrackDict[value] = ""
if key in tracks[trackID]:
simpleTrackDict[value] = tracks[trackID][key]
playlistArr.append(simpleTrackDict)
return playlistArr
def iTunesXML2PlaylistName(playlistFile):
root = plistlib.readPlist(playlistFile)
playlistName = root['Playlists'][0]['Name']
return playlistName
def main():
p = iTunesXML2PlaylistName("liveinlondon.xml")
if __name__ == "__main__":
main()