ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: jween on March 03, 2022, 03:23:00 AM

Title: OSX Photo filenames
Post by: jween on March 03, 2022, 03:23:00 AM
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
Title: Re: OSX Photo filenames
Post by: greybeard on March 03, 2022, 03:45:54 AM
How are you accessing the Photos? It is possible to program access to the Photos metadata using Xcode/Swift.
Title: Re: OSX Photo filenames
Post by: wywh on March 03, 2022, 04:00:00 AM
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
Title: Re: OSX Photo filenames
Post by: Hubert on March 03, 2022, 04:09:46 AM
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.



Title: Re: OSX Photo filenames
Post by: jween on March 03, 2022, 05:30:39 AM
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
Title: Re: OSX Photo filenames
Post by: StarGeek on March 03, 2022, 10:31:17 AM
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 (https://exiftool.org/faq.html#Q3) with the -api MDItemTags option (https://exiftool.org/ExifTool.html#MDItemTags) so as to get the MacOS specific tags (https://exiftool.org/TagNames/MacOS.html) and still see nothing, then the data is not in or attached to the file but instead in the program's database someplace.
Title: Re: OSX Photo filenames
Post by: Hubert on March 03, 2022, 10:46:52 AM
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



Title: Re: OSX Photo filenames
Post by: Hubert on March 03, 2022, 11:46:10 AM
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.
Title: Re: OSX Photo filenames
Post by: StarGeek on March 03, 2022, 01:26:03 PM
Ah, I missed that there was a separate api for XAttrTags, -api XAttrTags option (https://exiftool.org/ExifTool.html#XAttrTags).
Title: Re: OSX Photo filenames
Post by: Phil Harvey on March 03, 2022, 03:28:05 PM
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 (https://exiftool.org/ExifTool.html#XAttrTags).

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

- Phil
Title: Re: OSX Photo filenames
Post by: wywh on March 05, 2022, 05:16:03 AM
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
Title: Re: OSX Photo filenames
Post by: jween on May 05, 2022, 07:40:20 PM
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'
Title: Re: OSX Photo filenames
Post by: Phil Harvey on May 05, 2022, 08:38:43 PM
This test shouldn't be necessary because ExifTool won't overwrite an existing image file.

- Phil
Title: Re: OSX Photo filenames
Post by: jween on May 05, 2022, 09:35:40 PM
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".
Title: Re: OSX Photo filenames
Post by: Phil Harvey on May 07, 2022, 07:29:37 AM
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