OSX Photo filenames

Started by jween, March 03, 2022, 03:23:00 AM

Previous topic - Next topic

jween

Hi there!
I've made a script to import exiftool data from Mac OS Photo into a mysql database. However, Photo moxes the file names to synchronize with the cloud and stores the original filename somewhere, I'm assuming in the metadata. Is there an exiftool option to retrieve this? I've not seen it in the standard output.
Thx
Jon

greybeard

How are you accessing the Photos? It is possible to program access to the Photos metadata using Xcode/Swift.

wywh

It is possible to check the movie's or photo's internal database name by dragging the Photos thumbnail to Terminal. Maybe you could reverse-engineer that?

https://discussions.apple.com/thread/253334517?answerId=256237084022#256237084022

Hubert

#3
Hi,

Presumably you're referring to the names of the image files as stored in the Photos database (eg 27E11BA9-41C3-4F3C-8491-3160F19A95E9.jpeg) and you want to get the original file name as written by the camera (eg P1001446.JPG).

As far as I can see this info isn't encoded in the image files: it's not revealed by ExifTool or by MDLS.

The "Photos" filenames are closely related, though not identical, to their database ids.

You don't say what scripting language you're using, but AppleScript may help:

tell application "Photos" to get {id, filename} of item 1 of (get selection)
--{"27E11BA9-41C3-4F3C-8491-3160F19A95E9/L0/001","P1001446.JPG"}


Use at your own risk.




jween

Thanks Guys I appreciate the feedback.

Yes, I've written a simple bash command line script to scan the photos library with exiftool into a file then importing into mysql (for a more easily manageable catalogue). So, I'm trying to retrieve the original file name (eg P1001446.JPG) along with the moxed filename (eg: 7E11BA9-41C3-4F3C-8491-3160F19A95E9.jpeg), but I'm going to need to be consistent in my scripting and I'm only really familiar with bash.

I gather exiftool can't do this.

Not sure its really all that necessary, though I'm going to have to be able to go back to Photo from the database to retrieve and then photoshop the images.

Thx for your help

Jon

StarGeek

Quote from: jween on March 03, 2022, 05:30:39 AMI gather exiftool can't do this.

If you used the command in FAQ #3 with the -api MDItemTags option so as to get the MacOS specific tags and still see nothing, then the data is not in or attached to the file but instead in the program's database someplace.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Hubert

Quote from: jween on March 03, 2022, 05:30:39 AM
I'm going to need to be consistent in my scripting and I'm only really familiar with bash.

Are you familiar with osascript? It lets you run AppleScripts from the Terminal command line, eg:

osascript -e 'tell application "Photos" to get {id, filename} of item 1 of (get selection)'


returns

6B536D15-13E8-4295-B4D3-3DB2A9D920D9/L0/001, P1001450.JPG




Hubert

Quote from: jween on March 03, 2022, 05:30:39 AM

I gather exiftool can't do this.

I do believe it can:

~ % exiftool /path/to/27E11BA9-41C3-4F3C-8491-3160F19A95E9.jpeg -xattrassetsdoriginalfilename
X Attr Assetsd Original Filename: P1001446.JPG


It's in the xattrs, not in the mditems.

StarGeek

Ah, I missed that there was a separate api for XAttrTags, -api XAttrTags option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Quote from: StarGeek on March 03, 2022, 01:26:03 PM
Ah, I missed that there was a separate api for XAttrTags, -api XAttrTags option.

You can get both XAttr and MDItem tags either with -macos:all or  -api requestall=2.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wywh

#10
Quote from: Hubert on March 03, 2022, 10:46:52 AM
Are you familiar with osascript? It lets you run AppleScripts from the Terminal command line, eg:

osascript -e 'tell application "Photos" to get {id, filename} of item 1 of (get selection)'


returns

6B536D15-13E8-4295-B4D3-3DB2A9D920D9/L0/001, P1001450.JPG

Great! With a file selected in macOS 12 Photos.app the command and output is like:

osascript -e 'tell application "Photos" to get {id, filename} of item 1 of (get selection)'

6DC61A08-6460-4E87-B80B-51681B458BAB/L0/001, 2019-0420-1330-40.jpg


Photos.app library's folder and name can vary. The default is:

~/Pictures/Photos Library.photoslibrary

The 1st filename character tells in which /originals/ subfolder the file is stored so that 6DC61A08-6460-4E87-B80B-51681B458BAB is at (for some strange reason newer Photos use .jpeg instead the original's .jpg):

~/Pictures/Photos Library.photoslibrary/originals/6/6DC61A08-6460-4E87-B80B-51681B458BAB.jpeg

Question: how can I combine that first output to this command regardless where the Photos.app library is:

exiftool -a -G1 -s -n -ee '-*GPS*' ~'/Pictures/Photos Library.photoslibrary/originals/6/6DC61A08-6460-4E87-B80B-51681B458BAB'*''

[GPS]           GPSVersionID                    : 2 3 0 0
[GPS]           GPSLatitudeRef                  : S
[GPS]           GPSLatitude                     : 36.6101
[GPS]           GPSLongitudeRef                 : W
[GPS]           GPSLongitude                    : 66.91515
[Composite]     GPSLatitude                     : -36.6101
[Composite]     GPSLongitude                    : -66.91515
[Composite]     GPSPosition                     : -36.6101 -66.91515


p.s. It is not advisable in any way to modify the folders and files inside the library behind Photos.app's back -- the library must also be stored on APFS or Mac OS Extended volume because also non-Mac formats might corrupt it.

- Matti

jween

Thx guys! This helped. Love the open-source community!
A quick question: When using the -o option is there a way to use the -if option to check if the file already exists? Something like:
exiftool -r -o ./DestinationDir/ ../SourceDir/ -if './DestinationDir/$filename !-e'

Phil Harvey

This test shouldn't be necessary because ExifTool won't overwrite an existing image file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

jween

Yeah, I noticed that, but the workflow might require it: 1) I use OSX Photos as main repository for images, 2) I need to extract NEW data (tags and thumbnails) from OS X Photos after each new shoot, 3) Then upload new data and thumbnails into MySQL to catalogue and assign to projects.
I could just hammer through the whole dataset with each new upload (assignment/project) though that will get slower and slower as the repository gets bigger.
So, I wanted to process only NEW images, hence the need to check what is in the dataset from before. I guess I can do that with shell scripts and temporary folders, but wanted to try to be "elegant".

Phil Harvey

If you can automate the process of adding new photos to also add the new filename to a text file, then you can run ExifTool with -@ using the text file for input to process only the new photos.  Then delete the text file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).