RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
1.84k stars 94 forks source link

KeyError: PLModelVersion #1557

Closed markrsteiner closed 3 weeks ago

markrsteiner commented 4 weeks ago

Describe the bug It seems like there's some kind of "PLModelVersion" error with this file. The file could possibly be old or corrupt or something, I don't suspect it is - but I can no longer open it in icloud either. it has 250GB of photos in it, but obviously all of them have been stripped of EXIF data - hence why I was wanting to use osxphotos. It is not my main photos library, photos has been whacked up on my computer as well for some unknown reason. Probably to do with formerly having my photos library stored on an external drive?

To Reproduce 1) using old photoslibrary file (exported 2023) 2) it's stored on an external drive 3) I just used the cl command: osxphotos export --export-by-date --library /Volumes/Samsung_T5/2020\ Photo\ Library.photoslibrary /Volumes/Samsung_T5/export_photos 4) it throws the follow error:

Using osxphotos export database: version 9.1 located at /Volumes/Samsung_T5/export_photos/.osxphotos_export.db Processing database /Volumes/Samsung_T5/2020 Photo Library.photoslibrary/database/photos.db Processing database /Volumes/Samsung_T5/2020 Photo Library.photoslibrary/database/Photos.sqlite Something went wrong and osxphotos encountered an error: 'PLModelVersion'

5) not even 1 photo in the export folder

Expected behavior I expected osxphotos to export everything out of that photoslibrary file to the folder I gave it

Desktop (please complete the following information): osxphotos, version 0.67.10 Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] macOS 14.4.1, x86_64

Additional context Log file: osxphotos crash log Created: 2024-06-07 14:11:31.215818 osxphotos version: 0.67.10 Platform: macOS-14.4.1-x86_64-i386-64bit Python version: 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] sys.argv: ['/Users/mner/.local/bin/osxphotos', 'export', '--export-by-date', '--library', '/Volumes/Samsung_T5/2020 Photo Library.photoslibrary', '/Volumes/Samsung_T5/export_photos'] CRASH_DATA: locals: {'dest': '/Volumes/Samsung_T5/export_photos', 'db': '/Volumes/Samsung_T5/2020 Photo Library.photoslibrary', 'add_exported_to_album': None, 'add_missing_to_album': None, 'add_skipped_to_album': None, 'added_after': None, 'added_before': None, 'added_in_last': None, 'album': (), 'album_keyword': False, 'alt_db': None, 'alt_copy': False, 'append': False, 'fix_orientation': False, 'beta': False, 'burst': False, 'checkpoint': None, 'cleanup': False, 'cloudasset': False, 'config_only': False, 'convert_to_jpeg': False, 'crash_after': None, 'current_name': False, 'deleted': False, 'deleted_only': False, 'description': (), 'description_template': None, 'directory': None, 'download_missing': False, 'dry_run': False, 'duplicate': False, 'edited': False, 'edited_suffix': None, 'exif': (), 'exiftool': False, 'exiftool_merge_keywords': False, 'exiftool_merge_persons': False, 'exiftool_option': (), 'exiftool_path': None, 'export_as_hardlink': False, 'export_by_date': True, 'exportdb': None, 'external_edit': False, 'favorite': False, 'favorite_rating': False, 'filename_template': None, 'finder_tag_keywords': False, 'finder_tag_template': (), 'folder': (), 'force_update': False, 'from_date': None, 'from_time': None, 'has_comment': False, 'has_likes': False, 'has_raw': False, 'hdr': False, 'hidden': False, 'ignore_case': False, 'ignore_date_modified': False, 'ignore_exportdb': False, 'ignore_signature': False, 'in_album': False, 'incloud': False, 'is_reference': False, 'jpeg_ext': None, 'jpeg_quality': None, 'keep': (), 'keyword': (), 'keyword_template': (), 'label': (), 'limit': None, 'live': False, 'load_config': None, 'location': False, 'max_size': None, 'min_size': None, 'missing': False, 'name': (), 'no_comment': False, 'no_description': False, 'no_exportdb': False, 'no_keyword': False, 'no_likes': False, 'no_location': False, 'no_place': False, 'no_progress': False, 'no_title': False, 'not_burst': False, 'not_cloudasset': False, 'not_edited': False, 'not_favorite': False, 'not_hdr': False, 'not_hidden': False, 'not_in_album': False, 'not_incloud': False, 'not_live': False, 'not_missing': False, 'not_panorama': False, 'not_portrait': False, 'not_reference': False, 'not_screenshot': False, 'not_selfie': False, 'not_shared': False, 'not_slow_mo': False, 'not_time_lapse': False, 'only_movies': False, 'only_new': False, 'only_photos': False, 'original_suffix': None, 'overwrite': False, 'panorama': False, 'person': (), 'person_keyword': False, 'place': (), 'portrait': False, 'post_command': (), 'post_command_error': None, 'post_function': (), 'preview': False, 'preview_if_missing': False, 'preview_suffix': None, 'print_template': (), 'query_eval': (), 'query_function': (), 'ramdb': False, 'regex': (), 'replace_keywords': False, 'report': None, 'retry': None, 'save_config': None, 'screenshot': False, 'selfie': False, 'shared': False, 'export_aae': False, 'sidecar': (), 'sidecar_drop_ext': False, 'sidecar_template': (), 'skip_bursts': False, 'skip_edited': False, 'skip_live': False, 'skip_original_if_edited': False, 'skip_raw': False, 'skip_uuid': (), 'skip_uuid_from_file': None, 'slow_mo': False, 'strip': False, 'theme': None, 'time_lapse': False, 'timestamp': False, 'title': (), 'tmpdir': None, 'to_date': None, 'to_time': None, 'touch_file': False, 'update': False, 'update_errors': False, 'use_photokit': False, 'use_photos_export': False, 'uti': None, 'uuid': (), 'uuid_from_file': None, 'verbose_flag': 0, 'xattr_template': (), 'year': (), 'syndicated': False, 'not_syndicated': False, 'saved_to_library': False, 'not_saved_to_library': False, 'shared_moment': False, 'not_shared_moment': False, 'shared_library': False, 'not_shared_library': False, 'selected': False, 'ctx': <click.core.Context object at 0x10c4aec00>, 'cli_obj': <osxphotos.cli.cli.CLI_Obj object at 0x10bc0a810>} osxphotos version: 0.67.10 Error: 'PLModelVersion' Traceback (most recent call last): File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/crash_reporter.py", line 79, in wrapped return func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/cli/export.py", line 1115, in export return_code = export_cli(locals()) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/cli/export.py", line 1866, in export_cli photosdb = osxphotos.PhotosDB( ^^^^^^^^^^^^^^^^^^^ File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/photosdb/photosdb.py", line 394, in init self._photos_ver = get_photos_version_from_model(self._tmp_db) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/photosdb/photosdb_utils.py", line 107, in get_photos_version_from_model model_ver = get_model_version(db_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mner/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/photosdb/photosdb_utils.py", line 94, in get_model_version return plist["PLModelVersion"]


KeyError: 'PLModelVersion'
markrsteiner commented 4 weeks ago

Not clear how but I was able to get it working by using the command:

osxphotos export --exiftool --library /Volumes/Samsung_T5/2020\ Photo\ Library.photoslibrary /Volumes/Samsung_T5/export_photos

Now my problem is, the vast majority of the files are missing their EXIF data - seemingly anything shot on an iphone, its completely laccking any exif data... what am i doing wrong now...

RhetTbull commented 3 weeks ago

Very odd that it threw the error then worked later. I'll take a look at the error handling for reading the database to see if I can improve it or at least provide a better error description.

Now my problem is, the vast majority of the files are missing their EXIF data

osxphotos export exports the original images from the library. The --exiftool option causes metadata from Photos, e.g. keywords, title, caption, etc. to be written to the exported photo using exiftool. If not metadata got written it's possible there's no metadata associated with the image in the Photos library.

How did you create the Photos library in question? Can you open it in Photos?

RhetTbull commented 3 weeks ago

I've added code to catch this error in the future and if encountered, take a best guess at the Photos library model version. I've never encountered a Photos library with PLModelVersion data but yours appears to be missing this.