From 9b9d4091c893e58ee0f3a39b243fac098f11a4d6 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 2 Jan 2011 19:16:51 +1100 Subject: [PATCH] It works! :) --- English.lproj/NotiPod.xib | 254 +++++++++++++++++++++++++++----------- NotiPod.py | 30 ++++- libsyncitunes.py | 12 +- syncitunes.py | 2 +- 4 files changed, 218 insertions(+), 80 deletions(-) diff --git a/English.lproj/NotiPod.xib b/English.lproj/NotiPod.xib index b1b20bf..7e0f0f3 100644 --- a/English.lproj/NotiPod.xib +++ b/English.lproj/NotiPod.xib @@ -8,8 +8,10 @@ 461.00 YES - + + + YES @@ -343,21 +345,21 @@ - + 268 YES - - + + 2304 YES - - + + 256 {327, 338} - + YES @@ -366,7 +368,7 @@ YES - + selected 4.000000e+01 1.600000e+01 @@ -384,19 +386,19 @@ 3 MC4zMzMzMzI5ODU2AA - + 6 System headerTextColor - + 67239424 131072 - + 1211912703 130 @@ -414,9 +416,9 @@ 1 YES YES - + - + playlist 2.810000e+02 1.000000e+01 @@ -435,14 +437,14 @@ MQA - + - + 337772096 2048 - + 6 System @@ -453,7 +455,7 @@ 1 YES - + 3.000000e+00 @@ -478,39 +480,39 @@ {{1, 1}, {327, 338}} - - - + + + 4 - - + + -2147483392 {{313, 1}, {15, 323}} - - + + _doScroller: 9.970502e-01 - - + + -2147483392 {{1, 324}, {327, 15}} - + 1 - + _doScroller: 9.969512e-01 {{32, 160}, {329, 340}} - + 562 - - - + + + QSAAAEEgAABBmAAAQZgAAA @@ -533,7 +535,7 @@ {3.40282e+38, 3.40282e+38} - + 256 YES @@ -565,16 +567,63 @@ {204, 74} + {{0, 0}, {1024, 746}} {3.40282e+38, 3.40282e+38} - + PlaylistModel - + FolderModel + + 15 + 2 + {{196, 429}, {279, 81}} + 603979776 + Synchronising + NSWindow + + + + 256 + + YES + + + 268 + {{17, 44}, {245, 17}} + + YES + + 68288064 + 272630784 + Synchronising.. This may take a while. + + + + + + + + + 1292 + + {{18, 16}, {243, 20}} + + 16394 + 2.000000e+01 + 1.000000e+02 + + + {279, 81} + + + {{0, 0}, {1280, 778}} + {3.40282e+38, 3.40282e+38} + @@ -638,15 +687,15 @@ outlineView - - + + 478 folderPopup - + 493 @@ -654,7 +703,7 @@ doSelectFolder: - + 495 @@ -662,7 +711,7 @@ window - + 496 @@ -679,7 +728,7 @@ playlistModel - + 498 @@ -687,7 +736,7 @@ folderModel - + 499 @@ -707,6 +756,14 @@ 501 + + + synchronizingSheet + + + + 508 + @@ -870,7 +927,7 @@ - + @@ -965,7 +1022,7 @@ - NotiPodLoading + LoadingSheet 429 @@ -1017,72 +1074,111 @@ 467 - + YES - - - + + + 468 - - + + 469 - - + + 470 - + YES - - + + - + 472 - + YES - + - + 477 - + 484 - - + + 485 - + YES - + - + 486 - - + + 490 - + + + + + 503 + + + YES + + + SynchronizingSheet + + + 504 + + + YES + + + + + + + 505 + + + YES + + + + + + 506 + + + + + 507 + + @@ -1095,6 +1191,7 @@ -3.IBPluginDependency 103.IBPluginDependency 103.ImportedFromIB2 + 106.IBEditorWindowLastContentRect 106.IBPluginDependency 106.ImportedFromIB2 106.editorWindowContentRectSynchronizationRect @@ -1160,6 +1257,14 @@ 477.IBPluginDependency 484.IBPluginDependency 490.IBPluginDependency + 503.IBEditorWindowLastContentRect + 503.IBPluginDependency + 503.IBWindowTemplateEditedContentRect + 503.NSWindowTemplate.visibleAtLaunch + 504.IBPluginDependency + 505.IBPluginDependency + 506.IBPluginDependency + 507.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -1175,6 +1280,7 @@ com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin + {{87, 691}, {163, 23}} com.apple.InterfaceBuilder.CocoaPlugin {{98, 681}, {163, 23}} @@ -1240,6 +1346,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{42, 607}, {279, 81}} + com.apple.InterfaceBuilder.CocoaPlugin + {{42, 607}, {279, 81}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1265,7 +1379,7 @@ - 502 + 508 @@ -1309,6 +1423,7 @@ folderModel loadingSheet playlistModel + synchronizingSheet window @@ -1317,6 +1432,7 @@ id id id + id diff --git a/NotiPod.py b/NotiPod.py index 610d405..df65459 100644 --- a/NotiPod.py +++ b/NotiPod.py @@ -71,10 +71,13 @@ class FolderModel(NSObject): def awakeFromNib(self): self.folderPopup.addItemsWithTitles_(NSApp.delegate().folders()) self.folderPopup.selectItemAtIndex_(2) + self.lastIndex = 2 @objc.IBAction def doSelectFolder_(self, sender): - if self.folderPopup.indexOfSelectedItem() >= 2: + currentIndex = self.folderPopup.indexOfSelectedItem() + if currentIndex >= 2: + self.lastIndex = currentIndex NSApp.delegate().addFolder_(self.folderPopup.titleOfSelectedItem()) return panel = NSOpenPanel.openPanel() @@ -92,6 +95,8 @@ class FolderModel(NSObject): NSApp.delegate().addFolder_(folder) self.folderPopup.insertItemWithTitle_atIndex_(folder, 2) self.folderPopup.selectItemAtIndex_(2) + else: + self.folderPopup.selectItemAtIndex_(self.lastIndex) class NotiPodAppDelegate(NSObject): @@ -99,6 +104,7 @@ class NotiPodAppDelegate(NSObject): playlistModel = objc.IBOutlet() folderModel = objc.IBOutlet() loadingSheet = objc.IBOutlet() + synchronizingSheet = objc.IBOutlet() # Delegate methods @@ -129,19 +135,31 @@ class NotiPodAppDelegate(NSObject): @objc.IBAction def doSync_(self, sender): + NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(self.synchronizingSheet, self.window, None, None, None) + self.performSelectorInBackground_withObject_(self.syncFromThread, None) + + def syncFromThread(self): + pool = NSAutoreleasePool.alloc().init() + folder = self.folders()[0] playlists = [self.library.get_playlist_pid(pid) for pid in self.playlists()] all_tracks = [] for playlist in playlists: - print playlist.name, playlist.tracks all_tracks.extend(playlist.tracks) - libsyncitunes.export_m3u(dry_run=True, dest=folder, path_prefix="", + libsyncitunes.export_m3u(dry_run=False, dest=folder, path_prefix="", playlist_name=playlist.name, files=playlist.tracks) - libsyncitunes.sync(dry_run=True, + libsyncitunes.sync(dry_run=False, source=self.library.folder, dest=folder, files=all_tracks) + self.performSelectorOnMainThread_withObject_waitUntilDone_(self.finishSync, None, True) + del pool + + def finishSync(self): + NSApp.endSheet_(self.synchronizingSheet) + self.synchronizingSheet.close() + # Public accessors @@ -180,8 +198,8 @@ class NotiPodAppDelegate(NSObject): def main(): - logging.basicConfig(format="%(levelname)s: %(message)s") - logging.getLogger().setLevel(logging.DEBUG) +### logging.basicConfig(format="%(levelname)s: %(message)s") +### logging.getLogger().setLevel(logging.DEBUG) AppHelper.runEventLoop() if __name__ == "__main__": diff --git a/libsyncitunes.py b/libsyncitunes.py index e9ed9cd..3bccfec 100644 --- a/libsyncitunes.py +++ b/libsyncitunes.py @@ -120,10 +120,14 @@ class ITunesLibrary(NSObject): def export_m3u(dry_run, dest, path_prefix, playlist_name, files): if dry_run: return - f = open(os.path.join(dest, playlist_name) + ".m3u", "w") + playlist_file = os.path.join(dest, playlist_name) + ".m3u" + logging.info("Writing: " + playlist_file) + f = open(playlist_file, "w") for filename in files: - filename = filename.replace("/", "\\").encode("utf-8") - f.write("%s\\%s\\%s\n" % (path_prefix, filename)) + if path_prefix.find("\\") > 0: + filename = filename.replace("/", "\\") + filename = filename.encode("utf-8") + f.write("%s%s\n" % (path_prefix, filename)) f.close() def strip_prefix(s, prefix): @@ -173,7 +177,7 @@ def sync(dry_run, source, dest, files): else: logging.debug("update: " + filename) - elif not filename.startswith("Playlists/"): + elif not filename.endswith(".m3u"): logging.debug("delete: " + filename) if not dry_run: os.unlink(join(dest, filename)) diff --git a/syncitunes.py b/syncitunes.py index 16c64bf..1de4fae 100755 --- a/syncitunes.py +++ b/syncitunes.py @@ -24,7 +24,7 @@ def parse_options(): parser.add_option("--itunes-library", action="store", dest="itunes_library", default=None) parser.add_option("--path-prefix", - action="store", dest="path_prefix", default="E:") + action="store", dest="path_prefix", default="E:\\") opts, args = parser.parse_args(sys.argv[1:]) if len(args) < 2: -- 2.39.2