You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle enclosure tags and extract URL -(working solution) #117
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.
{% set description = your_"how_you_fetch_the_content_of_description-xml-tag" %}
{% set imgurl = description | regex_findall_index('(?<=<img src=")[\w:/._ \-]+(?=\?)') %}
{{imgurl}}
for stern (the enclosure doesn't work ?):
could you please post the entry-content ?
you will get this by:
HA -> Entwicklerwerkzeuge -> template
in the editor put in something like this:
{%- for entry in state_attr('YOUR_SENSOR_ENTITY-ID', 'entries') -%} {# ENTITY-ID: something like 'sensor.it_news' #}
{{entry}}
{% endfor %}
copy the result from the preview-window and paste it here, so i can create the regex-filter...
i opened the site and this is actually : <enclosure url="https://image.stern.de/30553162/t/7j/v3/w1440/r1.7778/-/e-bike-zubehoer.jpg" length="0" type="image/jpeg"/>
if you get such a simulary content from the enclosure-tag (i will name it 'enclosure_tag'), then try this:
{% set imgurl = enclosure_tag | regex_findall_index('(?<=url=")[\w:/._ \-]+(?=")') %}
{{imgurl}}
good luck
P.s: du kannst auch in deutsch antworten... ;-)
A new beta, v1.0.0-beta2, handles enclosures and the other image sources from this thread. Image extraction now looks, in order, at image enclosures, media:content, media:thumbnail, the first <img> in the summary, and the first <img> in content:encoded (WordPress). The image field is added when image is in inclusions.
I checked the feeds from the comments with the beta: https://rss.sueddeutsche.de/alles and the stern.de feed both give 10/10 entries with an image.
How to try it
In HACS, open Feedparser → ⋮ → Redownload, and under Need a different version? pick v1.0.0-beta2. Then restart Home Assistant.
Your existing YAML sensors are imported into Settings → Devices & services → Feedparser automatically and keep their entity IDs. A Repairs notice then asks you to remove the YAML.
To go back: delete the Feedparser entries under Devices & services, redownload 0.1.12 and restart. Your YAML isn't changed.
Activity
ogajduse commentedon Jan 10, 2024
@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.
somansch commentedon Feb 17, 2024
@ogajduse ,
I'm also having problems to get images from these two feeds. I tried latest v2.0b6.
https://rss.sueddeutsche.de/alles/
https://www.stern.de/feed/standard/auto/
Do you need more information? Thanks for your support
perlchamp commentedon Feb 24, 2025
Still a problem ?
try this for sueddeutsche:
for stern (the enclosure doesn't work ?):
could you please post the entry-content ?
you will get this by:
i opened the site and this is actually :
<enclosure url="https://image.stern.de/30553162/t/7j/v3/w1440/r1.7778/-/e-bike-zubehoer.jpg" length="0" type="image/jpeg"/>if you get such a simulary content from the enclosure-tag (i will name it 'enclosure_tag'), then try this:
good luck
P.s: du kannst auch in deutsch antworten... ;-)
iantrich commentedon Nov 14, 2026
A new beta, v1.0.0-beta2, handles enclosures and the other image sources from this thread. Image extraction now looks, in order, at image enclosures,
media:content,media:thumbnail, the first<img>in the summary, and the first<img>incontent:encoded(WordPress). Theimagefield is added whenimageis ininclusions.I checked the feeds from the comments with the beta:
https://rss.sueddeutsche.de/allesand the stern.de feed both give 10/10 entries with an image.How to try it
Release notes: https://github.com/custom-components/feedparser/releases/tag/v1.0.0-beta2
Please reply here with whether it works for you. If it doesn't, include the feed URL and your sensor options. Thanks!