]> code.delx.au - notipod/blobdiff - libnotipod.py
Version 1.7
[notipod] / libnotipod.py
index 02f7c30a19d72743fbc400c23beb07fd680f678a..76b7fb002a361cddd5fa27134c9d69c30c4ca15d 100644 (file)
@@ -44,20 +44,24 @@ class ITunesLibrary(NSObject):
                filename = os.path.expanduser(filename)
                yield "Reading library..."
                plist = read_plist(os.path.expanduser(filename))
+               if plist is None:
+                       raise Exception("Could not find music library: " + filename)
                self.folder = self.loc2name(plist["Music Folder"])
                pl_tracks = plist["Tracks"]
-               self.playlists = {}
+               pl_lookup = {}
+               self.playlists = []
                for pl_playlist in plist["Playlists"]:
-                       playlist = self.make_playlist(pl_playlist, pl_tracks)
+                       playlist = self.make_playlist(pl_playlist, pl_tracks, pl_lookup)
                        if not playlist:
                                continue
                        yield "Read playlist: " + playlist.name
-                       self.playlists[playlist.pid] = playlist
+                       self.playlists.append(playlist)
+                       pl_lookup[playlist.pid] = playlist
 
        def loc2name(self, location):
                return urllib.splithost(urllib.splittype(urllib.unquote(location))[1])[1]
 
-       def make_playlist(self, pl_playlist, pl_tracks):
+       def make_playlist(self, pl_playlist, pl_tracks, pl_lookup):
                if int(pl_playlist.get("Master", 0)):
                        return
                kind = int(pl_playlist.get("Distinguished Kind", -1))
@@ -88,7 +92,7 @@ class ITunesLibrary(NSObject):
                parent = None
                try:
                        parent_pid = pl_playlist["Parent Persistent ID"]
-                       parent = self.playlists.get(parent_pid)
+                       parent = pl_lookup[parent_pid]
                except KeyError:
                        pass
                tracks = []
@@ -123,25 +127,7 @@ class ITunesLibrary(NSObject):
                                return playlist
 
        def get_playlists(self):
-               return self.playlists.values()
-
-       def outlineView_numberOfChildrenOfItem_(self, view, item):
-               if item == None:
-                       return len(self.playlists)
-               else:
-                       return 0
-
-       def outlineView_isItemExpandable_(self, view, item):
-               return False
-
-       def outlineView_child_ofItem_(self, view, index, item):
-               if item == None:
-                       return self.playlists[index]
-               else:
-                       return None
-
-       def outlineView_objectValueForTableColumn_byItem_(self, view, column, item):
-               return item.name
+               return self.playlists
 
 
 encoded_names = {}
@@ -187,6 +173,7 @@ def export_m3u(dry_run, dest, path_prefix, playlist_name, files):
        if not path_prefix:
                path_prefix = "../"
        playlist_file = os.path.join(dest, "-Playlists-", playlist_name) + ".m3u"
+       playlist_file = encode_filename(playlist_file)
        mkdirhier(os.path.dirname(playlist_file))
        logging.info("Writing: " + playlist_file)
        f = open(playlist_file, "w")