Skip to content

Fix ExifTool geolocation parsing for custom path templates#525

Open
vesaias wants to merge 1 commit into
jmathai:masterfrom
vesaias:fix/exiftool-geolocation-key-prefix-and-custom-template
Open

Fix ExifTool geolocation parsing for custom path templates#525
vesaias wants to merge 1 commit into
jmathai:masterfrom
vesaias:fix/exiftool-geolocation-key-prefix-and-custom-template

Conversation

@vesaias

@vesaias vesaias commented Apr 25, 2026

Copy link
Copy Markdown

Summary

Two related fixes for the ExifTool reverse-geolocation flow added in #481 / #505 so country/city/state placeholders resolve correctly end-to-end when used inside %custom templates.

Verified end-to-end against an iPhone photo geotagged in Chivay, Peru:

  • Before: 2022-03/Chivay/... — country slot filled with city name.
  • After: 2022-03 Peru/... — country resolves correctly from the [Directory] location=%country alias.

Changes

  1. elodie/geolocation.py — accept both prefixed and bare exiftool keys. is_exiftool_available, exiftool_coordinates_by_name, and exiftool_place_name only checked for ExifTool:GeolocationCity/etc., but exiftool returns bare GeolocationCity/etc. when the -G group flag isn't in effect. A new _geolocation_field helper tries both forms.

  2. elodie/filesystem.py — expand sub-key aliases inside %custom templates. get_dynamic_path for custom recursively dispatched each %foo token but passed the literal %foo as the mask, ignoring the [Directory] config alias. With a config like

    [Directory]
    date=%Y-%m
    location=%country
    custom=%date %location
    full_path=%custom

    %location resolved to place_name['default'] (the city, since exiftool_place_name sets default to the most-specific field) instead of expanding via the location=%country alias. The custom resolver now looks up sub-keys in [Directory] and passes the alias value when dispatching, mirroring the top-level path resolver.

Tests

  • 4 new tests in geolocation_test.py cover both bare and prefixed Geolocation* key forms in is_exiftool_available, exiftool_coordinates_by_name, and exiftool_place_name (mocking ExifTool so they're network-free and deterministic).
  • 1 new test in filesystem_test.py (test_get_folder_path_custom_template_expands_location_alias) exercises the %custom%location%country expansion chain with a mocked place_name.

All other tests pass except for 7 pre-existing failures on master that depend on a live MapQuest key (test_get_folder_path_with_location, test_get_folder_path_with_album_and_location_fallback, test_get_folder_path_with_custom_path, test_get_folder_path_with_with_more_than_two_levels, test_get_folder_path_with_location_and_title, test_process_file_with_location, test_process_file_with_location_and_title) — verified to fail identically against master before this change.

Test plan

  • pytest elodie/tests/geolocation_test.py — 27 passed, 2 skipped, 5 pre-existing env failures unchanged
  • pytest elodie/tests/filesystem_test.py — new test passes; same 7 pre-existing failures as master
  • Live import dry-run with [Directory] location=%country config: *.JPG (Chivay/Peru GPS) lands at out/2022-03 Peru/...

@CLAassistant

CLAassistant commented Apr 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Two related fixes for the new ExifTool reverse-geolocation flow added in
PR jmathai#481/jmathai#505 so paths like `%date %country` resolve correctly end-to-end:

1. geolocation.py: accept both prefixed and bare exiftool keys.
   `is_exiftool_available`, `exiftool_coordinates_by_name`, and
   `exiftool_place_name` only matched `ExifTool:GeolocationCity`/etc.,
   missing the bare `GeolocationCity` form that exiftool returns when
   the `-G` group flag is not in effect. A new helper `_geolocation_field`
   transparently tries both forms.

2. filesystem.py: expand sub-key aliases inside `%custom` templates.
   `get_dynamic_path` for `custom` recursively dispatched each `%foo`
   token but passed the literal `%foo` as the mask, ignoring the
   `[Directory]` config alias. As a result, configurations like

       location=%country
       custom=%date %location
       full_path=%custom

   resolved `%location` to `place_name['default']` (the city, since
   exiftool_place_name sets default to the most-specific field) instead
   of expanding via the `location=%country` alias. The custom resolver
   now substitutes the alias value before recursing, mirroring the
   top-level path resolver.

Tests:
- 4 new geolocation tests cover both bare and prefixed key forms in
  is_exiftool_available, exiftool_coordinates_by_name, and
  exiftool_place_name.
- 1 new filesystem test exercises the `%custom` -> `%location` ->
  `%country` expansion chain.
@vesaias vesaias force-pushed the fix/exiftool-geolocation-key-prefix-and-custom-template branch from 3203f8c to 4263c8a Compare April 25, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants