Enhance xmp processing to support HEIC files tagged with ACDSee Photo Studio on Mac#548
Open
greensum wants to merge 1 commit into
Open
Enhance xmp processing to support HEIC files tagged with ACDSee Photo Studio on Mac#548greensum wants to merge 1 commit into
greensum wants to merge 1 commit into
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe 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
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>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: |
There was a problem hiding this comment.
issue (code-quality): We've found these issues:
- Hoist conditional out of nested conditional [×2] (
hoist-if-from-if) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: