custom-components / feedparser

📰 RSS Feed Integration
MIT License
145 stars 33 forks source link

Handle enclosure tags and extract URL -(working solution) #117

Open hardrockhodl opened 11 months ago

hardrockhodl commented 11 months ago

To modify the code to handle the \ 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.

ogajduse commented 10 months ago

@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 commented 9 months ago

@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