From 8487af298eaa2fb79612d7823442ed7ec5462aa6 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Sun, 21 May 2017 12:48:29 +0200 Subject: [PATCH] Add Media RSS to RSS This patch adds the necessary RSS extension to ensure that added Media RSS elements end up in the resulting RSS XML. Part of #58 --- feedgen/ext/media.py | 7 +++++-- tests/test_extension.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/feedgen/ext/media.py b/feedgen/ext/media.py index 40f506a..e947f8a 100644 --- a/feedgen/ext/media.py +++ b/feedgen/ext/media.py @@ -5,7 +5,7 @@ Extends the feedgen to produce media tags. - :copyright: 2013-2016, Lars Kiesow + :copyright: 2013-2017, Lars Kiesow :license: FreeBSD and LGPL, see license.* for more details. ''' @@ -29,7 +29,7 @@ class MediaEntryExtension(BaseEntryExtension): ''' def __init__(self): - self.__media_content = None + self.__media_content = [] self.__media_thumbnail = None def extend_atom(self, entry): @@ -84,6 +84,9 @@ class MediaEntryExtension(BaseEntryExtension): return entry + def extend_rss(self, item): + return self.extend_atom(item) + def media_content(self, url=None, fileSize=None, type=None, medium=None, isDefault=None, expression=None, bitrate=None, framerate=None, samplingrate=None, channels=None, diff --git a/tests/test_extension.py b/tests/test_extension.py index d717e20..bcb58bb 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -194,3 +194,35 @@ class TestExtensionTorrent(unittest.TestCase): filename = root.xpath('/rss/channel/item/torrent:filename/text()', namespaces=ns) assert filename == ['file.xy'] + + +class TestExtensionMedia(unittest.TestCase): + + def setUp(self): + self.fg = FeedGenerator() + self.fg.load_extension('media') + self.fg.id('id') + self.fg.title('title') + self.fg.link(href='http://example.com', rel='self') + self.fg.description('description') + + def test_media_content(self): + fe = self.fg.add_item() + fe.id('id') + fe.title('title') + fe.content('content') + fe.media.media_content(url='file1.xy') + + ns = {'media': 'http://search.yahoo.com/mrss/', + 'a': 'http://www.w3.org/2005/Atom'} + # Check that we have the item in the resulting RSS + root = etree.fromstring(self.fg.rss_str()) + url = root.xpath('/rss/channel/item/media:group/media:content[1]/@url', + namespaces=ns) + assert url == ['file1.xy'] + + # Check that we have the item in the resulting Atom feed + root = etree.fromstring(self.fg.atom_str()) + url = root.xpath('/a:feed/a:entry/media:group/media:content[1]/@url', + namespaces=ns) + assert url == ['file1.xy']