Skip to content

Can't add enclosure to atom correctly #143

Open
@BlackLotus

Description

@BlackLotus

I'm probably doing something horribly wrong here, but if I generate an rss feed I can add enclosures with this code without any problems

fe.enclosure(url=original_image_url, length='0', type=f"image/{imgtype}")
fe.enclosure(url=proxy_image_url, length='0', type=f"image/{imgtype}")

When I generate the feed as rss

    rss_feed = fg.rss_str(pretty=True)                                                                                                                         

the last enclosure is shown as attachment/enclosure which is what I expected when I create an atom feed

    atom_feed = fg.atom_str(pretty=True)

I just get multiple link objects without any reference of them being an enclosure.
Here is example code to reproduce this behaviour

from feedgen.feed import FeedGenerator

fg = FeedGenerator()
fg.load_extension('podcast')

# Set required fields using the appropriate methods
fg.id('bla')
fg.title('a')
fg.link({'href': 'http://ponyhof.de'})  # Pass a dictionary with 'href' key
fg.description('http://ponyhof.de')
fg.podcast.itunes_category('Technology', 'Podcasting')

fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1/file.mp3')
fe.title('The First Episode')
fe.description('Enjoy our first episode.')
fe.enclosure('http://lernfunk.de/media/654321/1/file.mp3', 0, 'audio/mpeg')
fe.enclosure('http://lernfunk.de/media/654321/2/file.mp3', 0, 'audio/mpeg')

# Generate the RSS feed
rss_feed = fg.rss_str(pretty=True)
print(rss_feed)  # Optional: print the RSS feed to the console
fg.rss_file('podcast-rss.xml')
fg.atom_file('podcast-atom.xml')

Here is your documentation specifying that it should work https://python-feedgen.readthedocs.io/en/latest/api.entry.html#feedgen.entry.FeedEntry.enclosure
Here is the atom rfc specifying how it should look https://validator.w3.org/feed/docs/rfc4287.html

    <link rel="enclosure" type="audio/mpeg" length="1337"
     href="http://example.org/audio/ph34r_my_podcast.mp3"/>

please tell me I'm doing something wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions