]> code.delx.au - notipod/blobdiff - libnotipod.py
Added icons
[notipod] / libnotipod.py
index 80f6a0d02ab65695b2410af833b9a24293313c57..02f7c30a19d72743fbc400c23beb07fd680f678a 100644 (file)
@@ -27,9 +27,10 @@ class Playlist(NSObject):
        def init(self):
                return self
 
-       def set(self, name, pid, tracks, parent):
+       def set(self, name, pid, ptype, tracks, parent):
                self.name = name
                self.pid = pid
+               self.ptype = ptype
                self.children = []
                self.tracks = tracks
                self.parent = parent
@@ -48,15 +49,42 @@ class ITunesLibrary(NSObject):
                self.playlists = {}
                for pl_playlist in plist["Playlists"]:
                        playlist = self.make_playlist(pl_playlist, pl_tracks)
+                       if not playlist:
+                               continue
                        yield "Read playlist: " + playlist.name
                        self.playlists[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):
+               if int(pl_playlist.get("Master", 0)):
+                       return
+               kind = int(pl_playlist.get("Distinguished Kind", -1))
+               if kind == 26:
+                       # Don't do genius
+                       return
+
                name = pl_playlist["Name"]
                pid = pl_playlist["Playlist Persistent ID"]
+               if kind > 0:
+                       ptype = {
+                               2: "movies",
+                               3: "tv-shows",
+                               4: "music",
+                               5: "books",
+                               10: "podcasts",
+                               19: "purchased",
+                               22: "itunes-dj",
+                               31: "itunes-u",
+                       }.get(kind, "playlist")
+               elif pl_playlist.has_key("Smart Info"):
+                       ptype = "smart-playlist"
+               elif int(pl_playlist.get("Folder", 0)):
+                       ptype = "folder"
+               else:
+                       ptype = "playlist"
+
                parent = None
                try:
                        parent_pid = pl_playlist["Parent Persistent ID"]
@@ -75,7 +103,7 @@ class ITunesLibrary(NSObject):
                        filename = strip_prefix(filename, self.folder)
                        tracks.append(filename)
                playlist = Playlist.alloc().init()
-               playlist.set(name, pid, tracks, parent)
+               playlist.set(name, pid, ptype, tracks, parent)
                return playlist
 
        def has_playlist_name(self, name):
@@ -88,7 +116,7 @@ class ITunesLibrary(NSObject):
                for playlist in self.get_playlists():
                        if playlist.name == name:
                                return playlist
-       
+
        def get_playlist_pid(self, pid):
                for playlist in self.get_playlists():
                        if playlist.pid == pid:
@@ -224,10 +252,9 @@ def sync(dry_run, source, dest, files_to_copy):
        for filename in files_to_copy:
                yield "Copy: " + filemap[filename].orig_filename
                if not dry_run:
-                       mkdirhier(os.path.dirname(join(dest, filename)))
-                       shutil.copy2(
-                               join(source, filemap[filename].orig_filename),
-                               join(dest, filemap[filename].encoded_filename)
-                       )
+                       source_file = join(source, filemap[filename].orig_filename)
+                       dest_file = join(dest, filemap[filename].encoded_filename)
+                       mkdirhier(os.path.dirname(dest_file))
+                       shutil.copy2(source_file, dest_file)