-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide access to album sort order #184
Comments
I don't quite understand the use case? If exporting, then exported images are just a set of files in a directory -- there's no inherent order. Do you mean the order in which files are written to disk? I'm not sure this even matters as the file creation date is preserved when exporting. If you're referring to programmatically accessing the images via an Update: @Rott-Apple are you using the command line tool or writing your own export script? Playing around with Photos export I see it offers an export in form "Album-Name-1 of 3.jpg"...the command line tool doesn't support this but if you were writing your own export script, I can see how this information would be useful. |
I think I've figured out where the album sort order data is stored in Catalina. The table
If you add photos to an album, the value for In the screenshot below, the last photo ( If you change the sort order manually, the value of |
OSXPhotos didn't preserve custom ordering so I am trying to write my own export script. The use case is this: After creating an album in Photos app, I can rearrange the photos within that album. I now want to export the album as a folder to Dropbox while preserving the ordering within the exported folder. This would be useful e.g. to share the exported album (folder) with a Windows PC user with the photos in my desired sequence. Hopefully Catalina can now be solved with your previous advice, but where is re-ordering information stored in Mojave and prior? Hugely appreciate your time and effort. |
Ah, makes sense. You're correct that I'll need to a take a look at Mojave database again to see if I can figure out where the album order is stored. What format are you using for photo export name to preserve order? I may be able to also modify the |
@Rott-Apple Found the sort order for Mojave! It's stored in table The highlighted rows in screenshot below show 4 photos in an album with default sort order. Note the In screenshot below, I manually re-sorted the images, moving the second to last image (uuid = 6bxcNnzRQKGnK4uPrCJ9UQ) to the beginning of the album. Note it's Now that I can extract the sort order for both Mojave and Catalina, I'll work on adding this to If you want to use import pathlib
import osxphotos
photosdb = osxphotos.PhotosDB()
conn, cursor = photosdb.get_db_connection()
albums = photosdb.album_info
for album in albums:
print(f"processing album title: {album.title}")
results = cursor.execute(
"SELECT COUNT(*) FROM RKCustomSortOrder WHERE containerUuid = ?", ([album.uuid])
).fetchone()
total = results[0]
cursor.execute(
""" SELECT objectUuid, orderNumber
FROM RKCustomSortOrder
WHERE containerUuid = ?
ORDER BY orderNumber
""",
([album.uuid]),
)
sequence = 1
for row in cursor:
uuid = row[0]
photo = photosdb.photos(uuid=[uuid])[0]
if photo and not photo.ismissing:
ext = pathlib.Path(photo.path).suffix
photo.export("/tmp", f"{album.title} {sequence} of {total}{ext}")
sequence += 1
else:
print(f"did not find photo for uuid {uuid}")
conn.close() |
I was thinking of renaming and renumbering the photos and videos in reordered albums as "album_name 00n.filetype", where 00n will increment based on the custom ordering. |
Brilliant! You must practically live inside photos.db to know it so intimately! One typo to fix in your reply (to help others who read it): "orderNumber changed from 4096 to 1536, placing it first in the album" should be "changed from 3072 to 1536". I'll experiment a bit more by rearranging a test album to understand why 3072 changed to 1536 and not 1024, how does renumbering work as I move more and more photos around, etc. Meanwhile, thanks a ton for this brilliant project and such prompt replies. |
@Rott-Apple I've fixed This should simplify the export script to something like: import pathlib
import osxphotos
photosdb = osxphotos.PhotosDB()
for album in photosdb.album_info:
print(f"processing album title: {album.title}")
sequence = 1
for photo in album.photos:
if not photo.ismissing:
ext = pathlib.Path(photo.path).suffix
photo.export("/tmp", f"{album.title} {sequence:04}{ext}")
sequence += 1 |
@Rott-Apple Having implemented user-defined custom sort orders at former There are probably some other heuristics as well that attempt to keep the amount of space between items relatively balanced so that continued re-sorting doesn't degenerate quickly. If you always target the same "slot" there's only |
While exporting an album in which photos have been manually reordered, the organization seems to be preserved in Catalina but not Mojave.
The text was updated successfully, but these errors were encountered: