feedparser
feedparser copied to clipboard
Handle enclosure tags and extract URL -(working solution)
To modify the code to handle the <enclosure> tag as the image part, you can update the logic within the update method. Specifically, you can check for the presence of the
tag and extract the url attribute as the image URL.
# Check for the enclosure tag
if "enclosures" in entry:
enclosure = entry["enclosures"][0] # Assuming only one enclosure
entry_value["image"] = enclosure.get("url", "")
if not entry_value.get("image"):
# If there's no enclosure, check for image in summary
images = []
if "summary" in entry:
images = re.findall(
r"<img.+?src=\"(.+?)\".+?>", entry["summary"]
)
if images:
entry_value["image"] = images[0]
else:
entry_value[
"image"
] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
This modification checks for the presence of the enclosures key in the entry. If it exists, it assumes there is at least one enclosure, and it extracts the url attribute from the first enclosure as the image URL. If there is no enclosure, it falls back to the previous logic of checking for an image in the summary.
@hardrockhodl Could you please check the latest implementation from the master branch? I have slightly modified the implementation around getting the images from the feed entries. You might want to try installing the latest beta release using HACS, if you have the integration installed through HACS.
If the latest implementation still does not work, I am happy to work on a solution with you.
@ogajduse , I'm also having problems to get images from these two feeds. I tried latest v2.0b6.
https://rss.sueddeutsche.de/alles/
- img link is part of summary, but not set as "image"
https://www.stern.de/feed/standard/auto/
- img link is second under "links", but not set as "image"
Do you need more information? Thanks for your support