Hidden photos #688
-
Hi! I exported my photos a while ago and used to have some hidden photos that got exported successfully. I've moved to Digikam since then. Do these pictures get some kind of special tag or rating I can use to find them later? Thanks for this tool again :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi @alandefreitas No, hidden photos do not get any special tag or modifier unless you explicitly set one during export, for example, you could have done this to add a
If you still have the original photos library and know a bit of python, you could find all photos marked as hidden and then somehow mark them in digikam. The following script, if saved as from osxphotos import PhotosDB, QueryOptions
if __name__ == "__main__":
photosdb = PhotosDB()
hidden_photos = photosdb.query(QueryOptions(hidden=True))
for photo in hidden_photos:
print(photo.uuid, photo.original_filename) Did you use a
from osxphotos import PhotosDB, QueryOptions
import os.path
if __name__ == "__main__":
# Set these to whatever you used during the original export
export_dir = "/Users/rhet/Desktop"
directory_template = "{created.year}/{created.month}"
filename_template = "{original_name}"
photosdb = PhotosDB()
hidden_photos = photosdb.query(QueryOptions(hidden=True))
for photo in hidden_photos:
# render directory and filename templates; render template returns:
# ([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
# below assume there are no unmatched template values (osxphotos export would have thrown an exception)
# and that each template renders to a single value -- modify if you used a multi-value template
directory = photo.render_template(directory_template)[0][0]
filename = (
photo.render_template(filename_template)[0][0]
+ os.path.splitext(photo.original_filename)[1]
)
exported_path = os.path.join(export_dir, directory, filename)
print(photo.uuid, photo.original_filename, exported_path) |
Beta Was this translation helpful? Give feedback.
-
@alandefreitas I thought about this some more and I think you can easily extract the path to all hidden images directly from the export database (
This will query the metadata stored in the export database to print the path (relative to the export directory) for each photo that had been hidden in Photos. osxphotos stores a JSON dictionary of all the metadata for each photo in the export database and this contains the |
Beta Was this translation helpful? Give feedback.
-
Glad you got this fixed. I'm posting a more complete script here in case others find this in the future. The following script, if saved as """Save this as hidden.py then run with `osxphotos run hidden.py`
to add hidden keyword to photos that were hidden in Photos prior to export
"""
import os.path
import sqlite3
from typing import List
from osxmetadata import OSXMetaData, Tag
from osxphotos import ExifTool
# set these values to match your export path
EXPORT_DB_PATH = "/Users/rhet/Desktop/export/.osxphotos_export.db"
EXPORT_DIR = "/Users/rhet/Desktop/export"
# set this to the keyword you want to add to photos
HIDDEN_KEYWORD = "hidden"
def hidden_photos(export_db_path: str, export_dir: str) -> List[str]:
"""Reads export database to find photos that were hidden in Photos prior to export"""
conn = sqlite3.connect(export_db_path)
c = conn.cursor()
# the export database stores a JSON dictionary of the photo metadata
# in photoinfo.photoinfo; look there for photos that were hidden ("hidden" = 1)
c.execute(
"""
SELECT export_data.filepath
FROM export_data
JOIN photoinfo ON export_data.uuid = photoinfo.uuid
WHERE json_extract(photoinfo.photoinfo, '$.hidden')=1;
"""
)
results = c.fetchall()
conn.close()
# the export database stores photo path as relative to the export directory
return [os.path.join(export_dir, r[0]) for r in results]
def process_photos(photos: List[str]) -> None:
"""Process photos to add hidden keyword"""
for photo_path in photos:
if not os.path.exists(photo_path):
print(f"{photo_path} does not exist; skipping")
continue
print(f"Processing {photo_path}")
# add hidden keyword to photo
ExifTool(photo_path).addvalues("IPTC:Keywords", HIDDEN_KEYWORD)
# add hidden Finder tag to photo
OSXMetaData(photo_path).tags += [Tag(HIDDEN_KEYWORD)]
if __name__ == "__main__":
hidden = hidden_photos(EXPORT_DB_PATH, EXPORT_DIR)
process_photos(hidden) |
Beta Was this translation helpful? Give feedback.
Hi @alandefreitas No, hidden photos do not get any special tag or modifier unless you explicitly set one during export, for example, you could have done this to add a
HIDDEN
tag to any hidden photo:osxphotos export /path/to/export --keyword-template "{photo.hidden?HIDDEN,}" --exiftool
If you still have the original photos library and know a bit of python, you could find all photos marked as hidden and then somehow mark them in digikam. The following script, if saved as
hidden.py
and run withosxphotos run hidden.py
will list all hidden images: