Skip to content

Enhance xmp processing to support HEIC files tagged with ACDSee Photo Studio on Mac#548

Open
greensum wants to merge 1 commit into
helgeerbe:mainfrom
greensum:feature/enhance-xmp-processing
Open

Enhance xmp processing to support HEIC files tagged with ACDSee Photo Studio on Mac#548
greensum wants to merge 1 commit into
helgeerbe:mainfrom
greensum:feature/enhance-xmp-processing

Conversation

@greensum
Copy link
Copy Markdown

@greensum greensum commented Sep 19, 2025

I use ACDSee Photo Studio on Mac which adds keywords to HEIC files in a way different from what the existing code expects. I made it to look for ['Seq']['li'] if ['Bag']['li'] doesn't exist when looking for 'subject' in xmp. I also made the processing of both 'description' and 'subject' more robust to avoid unnecessary warning messages.

Summary by Sourcery

Enhance XMP metadata parsing to support HEIC files tagged by ACDSee Photo Studio on Mac by adding safer extraction for description fields and a fallback for subject tags.

Enhancements:

  • Add type and key checks for the 'description' XMP field to safely extract Alt/li/text values
  • Fallback to 'Seq/li' when 'Bag/li' is missing for the 'subject' XMP field and handle both list and single string values
  • Validate XMP structure before accessing keys to prevent unnecessary warning messages

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR improves XMP metadata parsing by adding defensive structure checks for the description field, introducing a fallback sequence path for keyword extraction, and supporting both list and string formats when building subject tags to accommodate HEIC files tagged by ACDSee on Mac.

File-Level Changes

Change Details Files
Enhanced safety of description extraction
  • Added isinstance checks for nested 'Alt', 'li', and 'text' keys
  • Only assign description when all expected dict layers exist
src/picframe/get_image_meta.py
Added fallback to 'Seq.li' when extracting 'subject' keywords
  • Wrapped 'subject' value in dict check
  • First look for 'Bag.li', then fallback to 'Seq.li' if absent
src/picframe/get_image_meta.py
Unified handling of keyword tags as list or string
  • Build comma‐separated tags when value is a list
  • Accept single string subjects by appending and tagging appropriately
src/picframe/get_image_meta.py

Possibly linked issues

  • Thankyou! & Wiki suggestion #123: The PR enhances XMP processing to correctly recognize and extract tags from HEIC files, directly resolving the issue where HEIC tags were not recognized.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the repeated nested dict key‐existence checks into a small helper function (e.g. safe_get(xmp_val, ['Alt','li','text'])) to simplify and DRY up the logic.
  • Instead of manually concatenating tags with trailing commas, use ','.join() on the list (or wrap a single string) and assign that—this will avoid the extra comma and make the code clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the repeated nested dict key‐existence checks into a small helper function (e.g. `safe_get(xmp_val, ['Alt','li','text'])`) to simplify and DRY up the logic.
- Instead of manually concatenating tags with trailing commas, use `','.join()` on the list (or wrap a single string) and assign that—this will avoid the extra comma and make the code clearer.

## Individual Comments

### Comment 1
<location> `src/picframe/get_image_meta.py:102` </location>
<code_context>
    def __do_xmp_keywords(self, xmp):
        try:
            # title
            val = self.__find_xmp_key('Headline', xmp)
            if val and isinstance(val, str) and len(val) > 0:
                self.__tags['IPTC Object Name'] = val
            # caption
            try:
                val = self.__find_xmp_key('description', xmp)
                if val:
                    if (isinstance(val, dict) and 'Alt' in val and
                        isinstance(val['Alt'], dict) and 'li' in val['Alt'] and
                        isinstance(val['Alt']['li'], dict) and 'text' in val['Alt']['li']):
                        val = val['Alt']['li']['text']
                    if val and isinstance(val, str) and len(val) > 0:
                        self.__tags['IPTC Caption/Abstract'] = val
            except KeyError:
                pass
            # tags
            try:
                val = self.__find_xmp_key('subject', xmp)
                if val:
                    if isinstance(val, dict):
                        if ('Bag' in val and
                            isinstance(val['Bag'], dict) and 'li' in val['Bag']):
                            val = val['Bag']['li']
                        elif ('Seq' in val and
                            isinstance(val['Seq'], dict) and 'li' in val['Seq']):
                            val = val['Seq']['li']
                    if val:
                        tags = ''
                        if isinstance(val, list):
                            for tag in val:
                                tags += tag + ","
                        elif isinstance(val, str):
                            tags = val + ","
                        if tags:
                            self.__tags['IPTC Keywords'] = tags
            except KeyError:
                pass
        except Exception as e:
            self.__logger.warning("xmp loading has failed: %s -> %s", self.__filename, e)

</code_context>

<issue_to_address>
**issue (code-quality):** We've found these issues:

- Hoist conditional out of nested conditional [×2] ([`hoist-if-from-if`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/hoist-if-from-if/))
- Use f-string instead of string concatenation [×2] ([`use-fstring-for-concatenation`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/use-fstring-for-concatenation/))
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

isinstance(val['Alt'], dict) and 'li' in val['Alt'] and
isinstance(val['Alt']['li'], dict) and 'text' in val['Alt']['li']):
val = val['Alt']['li']['text']
if val and isinstance(val, str) and len(val) > 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

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.

1 participant