Skip to main content

add more readme stuff

ID
e9f071a
date
2023-05-14 15:51:19+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
5f24a25
message
add more readme stuff
changed files
3 files, 40 additions, 2 deletions

Changed files

README.md (2253) → README.md (2371)

diff --git a/README.md b/README.md
index fba413d..1a9a7e9 100644
--- a/README.md
+++ b/README.md
@@ -39,10 +39,9 @@ On the rendered page, I capture keyboard input with the [`document.keydown` even
 
 The web server runs scripts in a mixture of Swift/AppleScript, which update my photos in Photos.app as appropriate.
 Most of the heavy lifting is done with the [PhotoKit framework].
+I'm not touching the Photos SQLite database directly, or trying to analyse the structure of the Photos Library package.
 
 If you're interested in the details of how I'm talking to Photos.app, you might want to look in the [actions folder](./actions).
 
 [event]: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event
 [PhotoKit framework]: https://developer.apple.com/documentation/photokit
-
-

actions/README.md (0) → actions/README.md (1708)

diff --git a/actions/README.md b/actions/README.md
new file mode 100644
index 0000000..bd7d6df
--- /dev/null
+++ b/actions/README.md
@@ -0,0 +1,38 @@
+This folder contains all the code that actually interacts with the Photos library.
+If you're building your own project to interact with Photos, some of this might be useful/reusable.
+
+These scripts are built around [PHObject.localIdentifier], a persistent string that identifies objects (and assets in particular).
+In my experience, these identifiers are a UUID with some trailing info, e.g. `F011D947-B547-4FFC-92A1-31D197B5EF4E/L0/001`.
+
+[PHObject.localIdentifier]: https://developer.apple.com/documentation/photokit/phobject/1622400-localidentifier
+
+The scripts are as follows:
+
+<dl>
+  <dt><code>get_asset_jpeg.swift [LOCAL_IDENTIFIER] [SIZE]</code></dt>
+  <dd>
+    get a JPEG for a photo in my library.
+    It prints a path to the generated file.
+    <br/><br/>
+    This includes downloading the photo from iCloud Photo Library, if it isn’t already saved locally.
+    There are two potentially interesting functions in here: one to create an NSImage from a PHAsset, one to convert an NSImage into JPEG Data.
+  </dd>
+
+  <dt><code>get_structural_metadata.swift</code></dt>
+  <dd>
+    extract a bunch of information about my albums and assets, and print it as a JSON object.
+  </dd>
+
+  <dt><code>open_photos_app.applescript [LOCAL_IDENTIFIER]</code></dt>
+  <dd>
+    open the given photo in Photos.app.
+  </dd>
+
+  <dt><code>run_action.swift [LOCAL_IDENTIFIER] [ACTION_NAME]</code></dt>
+  <dd>
+    this script does all the modification of stuff in Photos.app.
+    This includes marking a photo as a favourite and adding/removing photos from albums.
+    <br/><br/>
+    This could be a bunch of separate scripts, but I collapsed them into a single script because there was a lot of similar code.
+  </dd>
+</dl>
\ No newline at end of file

actions/get_asset_jpeg.swift (4641) → actions/get_asset_jpeg.swift (4722)

diff --git a/actions/get_asset_jpeg.swift b/actions/get_asset_jpeg.swift
index 9833fdc..2cad6f7 100644
--- a/actions/get_asset_jpeg.swift
+++ b/actions/get_asset_jpeg.swift
@@ -80,6 +80,7 @@ extension PHAsset {
 }
 
 extension NSImage {
+  // Based on https://gist.github.com/zappycode/3b5e151d4d98407901af5748745f5845
   func jpegData() -> Data {
     let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil)!
     let bitmapRep = NSBitmapImageRep(cgImage: cgImage)