parent.children.append(self)
class ITunesLibrary(NSObject):
- def init(self):
- return self.initWithFilename_("~/Music/iTunes/iTunes Music Library.xml")
-
- def initWithFilename_(self, filename):
+ def load_(self, filename):
+ if filename is None:
+ filename = "~/Music/iTunes/iTunes Music Library.xml"
filename = os.path.expanduser(filename)
+ yield "Reading library..."
plist = read_plist(os.path.expanduser(filename))
self.folder = self.loc2name(plist["Music Folder"])
pl_tracks = plist["Tracks"]
self.playlists = {}
for pl_playlist in plist["Playlists"]:
playlist = self.make_playlist(pl_playlist, pl_tracks)
+ yield "Read playlist: " + playlist.name
self.playlists[playlist.pid] = playlist
- return self
def loc2name(self, location):
return urllib.splithost(urllib.splittype(urllib.unquote(location))[1])[1]
filename = str(pl_tracks[str(trackID)]["Location"])
filename = self.loc2name(filename)
filename = filename.decode("utf-8")
-### filename = eval(repr(filename).lstrip("u")).decode("utf-8")
if not filename.startswith(self.folder):
logging.warn("Skipping: " + filename)
continue
continue
if filename in files:
- sourcestat = os.stat(join(source, filename))
+ sourcestat = os.stat(join(source, filemap[filename]))
deststat = os.stat(join(dest, filename))
same_time = abs(sourcestat.st_mtime - deststat.st_mtime) < 5
same_size = sourcestat.st_size == deststat.st_size
if same_time and same_size:
files.remove(filename)
- logging.debug("keep: " + filename)
+ yield "Keep: " + filename
else:
- logging.debug("update: " + filename)
+ yield "Update: " + filename
elif not filename.endswith(".m3u"):
- logging.debug("delete: " + filename)
+ yield "Delete: " + filename
if not dry_run:
os.unlink(join(dest, filename))
if len(os.listdir(full_dirpath)) == 0:
- logging.debug("rmdir: " + dirpath)
+ yield "Delete: " + dirpath
if not dry_run:
os.rmdir(full_dirpath)
files = list(files)
files.sort()
for filename in files:
- logging.debug("copy: " + filename)
+ yield "Copy: " + filename
if not dry_run:
mkdirhier(os.path.dirname(join(dest, filename)))
shutil.copy2(join(source, filemap[filename]), join(dest, filename))