-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Add media content parsing for images #158
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,7 +260,14 @@ def _process_image(self: FeedParserSensor, feed_entry: FeedParserDict) -> str: | |
| if images: | ||
| # pick the first image found | ||
| return images[0]["href"] | ||
| elif "summary" in feed_entry: | ||
| if feed_entry.get("media_content"): | ||
| images = [ | ||
| enc for enc in feed_entry["media_content"] if enc['type'].startswith("image/") | ||
| ] | ||
| if images: | ||
| # pick the first image found | ||
| return images[0]["url"] | ||
|
Comment on lines
+263
to
+269
|
||
| if "summary" in feed_entry: | ||
| images = re.findall( | ||
| IMAGE_REGEX, | ||
| feed_entry["summary"], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering
media_contentitems withenc['type'].startswith("image/")can raiseKeyError(missingtype) orAttributeError(typeis None). Using a safe accessor (e.g.,enc.get("type", "")) and matching theenclosuresstyle (enc.type) would make this more robust for varying feedparser outputs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider this a minor comment.