Commit Diff


commit - 4a4666f3455d27e8b08c14304b05c66b2020e72a
commit + 0668f766842478d85663358f1563d3d70c3ed31b
blob - c606e4a53cebd309daeb3104a897d2b44e66bd44
blob + 7d3813f9453e1e49915dd0c3b8375d14f5d7e1d8
--- src/PhotosCreateFolders.js
+++ src/PhotosCreateFolders.js
@@ -16,9 +16,9 @@ function findAlbum(folder, path, albumName) {
     //console.log(`== findAlbum({${folder.name()}}, [${path}], "${albumName}")`);
 
     // we arrived at the lowest folder level, check if the album exists
-    if(path.length === 0) {
+    if (path.length === 0) {
         const album = folder.albums.whose({name: albumName});
-        if(album.length === 0) {
+        if (album.length === 0) {
             console.log(`> creating new album: ${albumName} at ${folder.name()}`);
             return app.make({new: "album", named: albumName, at: folder});
         } else {
@@ -31,9 +31,9 @@ function findAlbum(folder, path, albumName) {
     const foundFolder = folder.folders.whose({name: path[0]});
     if (foundFolder.length === 0) {
         console.log(`> creating new folder: ${path[0]} at ${folder.name()}`);
-        createFolder = {new: "folder", named: path[0], at: folder };
+        createFolder = {new: "folder", named: path[0], at: folder};
         // we can't use 'at' when we are at the top level
-        if(folder instanceof Application) delete createFolder.at;
+        if (folder instanceof Application) delete createFolder.at;
         const subFolder = app.make(createFolder);
         return findAlbum(subFolder, path.slice(1), albumName);
     } else {
@@ -44,13 +44,19 @@ function findAlbum(folder, path, albumName) {
 // keep a cache of existing albums at their path (no need to traverse again)
 var albums = new Map();
 
+Progress.totalUnitCount = app.mediaItems.length
+Progress.completedUnitCount = 0
+Progress.description = "Processing keywords..."
+Progress.additionalDescription = "Preparing to process."
+
 // check all media items with a keyword prefixed by 'P:'
-app.mediaItems().forEach(m => {
+app.mediaItems().forEach((m, i) => {
+    Progress.additionalDescription = "Processing ... (" + i + "/" + Progress.totalUnitCount + ")"
     const keywords = m.keywords();
     if (keywords) {
         keywords.filter(k => k.startsWith(TAGPREFIX)).forEach(p => {
             var album = albums.get(p);
-            if(!album) {
+            if (!album) {
                 //console.log(`>> analyzing ${p} for ${m.filename()}`);
                 const pathElements = p.substring(2).split("/");
                 const albumName = pathElements.pop();
@@ -58,11 +64,12 @@ app.mediaItems().forEach(m => {
                 albums.set(p, album);
             }
             // only add to album, if the photo is not already added
-            if(album.mediaItems.whose({id: m.id()}).length === 0) {
+            if (album.mediaItems.whose({id: m.id()}).length === 0) {
                 console.log(`>> adding ${m.filename()} to ${p.substring(2)}`);
                 app.add([m], {to: album});
             }
         });
     }
+    Progress.completedUnitCount = i;
 });
 $.exit(0)