Skip to content
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

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

Open
hardrockhodl opened this issue Dec 27, 2023 · 2 comments
Open

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

hardrockhodl opened this issue Dec 27, 2023 · 2 comments

Comments

@hardrockhodl
Copy link

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.

@ogajduse
Copy link
Collaborator

@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
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants