From 28952e7fbc38bbcb0124243ab6c76c8b60a4faff Mon Sep 17 00:00:00 2001 From: M D Date: Fri, 6 Jan 2017 15:26:33 -0500 Subject: [PATCH 1/4] Added MediaThumbnail class for media:thumbnail element --- PyMediaRSS2Gen.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++- README.rst | 2 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/PyMediaRSS2Gen.py b/PyMediaRSS2Gen.py index 0cf7771..2b7572e 100644 --- a/PyMediaRSS2Gen.py +++ b/PyMediaRSS2Gen.py @@ -124,6 +124,52 @@ def __repr__(self): self.element_attrs.get('width', None)) +class MediaThumbnail(object): + + """Publish a media:thumbnail element.""" + + element_attrs = None + + def __init__( + self, + url=None, + height=None, + width=None, + ): + """Create a media:thumbnail element, args will be attributes.""" + self.element_attrs = OrderedDict() + + self._add_attribute('url', url) + self._add_attribute('height', height) + self._add_attribute('width', width) + + def _add_attribute(self, name, value, allowed_values=None): + """Add an attribute to the MediaThumbnail element.""" + if value and value != 'none': + + if isinstance(value, (int, bool)): + value = str(value) + + if allowed_values and value not in allowed_values: + raise TypeError( + "Attribute '" + name + "' must be one of " + str( + allowed_values) + " but is '" + str(value) + "'") + + self.element_attrs[name] = value + + def publish(self, handler): + """Publish the MediaThumbnail as XML.""" + PyRSS2Gen._element(handler, "media:thumbnail", None, self.element_attrs) + + def __repr__(self): + """Return a nice string representation for prettier debugging.""" + return "MediaThumbmail(url='%s', width='%s', height='%s')" % \ + (self.element_attrs.get('url', None), + self.element_attrs.get('height', None), + self.element_attrs.get('width', None)) + + + class MediaRSSItem(PyRSS2Gen.RSSItem, object): """Publish a Media RSS Item.""" @@ -139,6 +185,7 @@ def __init__( media_group=None, # Allows grouping of elements with the same content. media_content=None, # can be used to publish any type of media. + media_thumbnail=None, # allows images to be used a representative images for media object media_player=None, # Allows a media object to be accessed through a web browser media # player console. @@ -152,6 +199,7 @@ def __init__( """Create a Media RSS item that contains args as elements.""" self.media_group = media_group self.media_content = media_content + self.media_thumbnail = media_thumbnail self.media_player = media_player self.media_peerLink = media_peerLink self.media_location = media_location @@ -172,10 +220,11 @@ def __init__( def __repr__(self): """Return a nice string representation for prettier debugging.""" return "MediaContent(title='%s', media_content='%s', " \ - "media_group='%s', media_player='%s', media_peerLink='%s', " \ + "media_group='%s', media_thumbnail='%s', media_player='%s', media_peerLink='%s', " \ "media_location='%s')" % ( self.title, str(self.media_content), + str(self.Media_thumbnail), str(self.media_group), str(self.media_player), str(self.media_peerLink), @@ -196,6 +245,7 @@ def check_complicance(self): if ma.startswith('media_') and getattr(self, ma)]) and not self.media_group and not self.media_content + and not self.media_thumbnail and not self.media_player and not self.media_peerLink and not self.media_location @@ -243,3 +293,6 @@ def publish_extensions(self, handler): if hasattr(self, 'media_text'): PyRSS2Gen._opt_element(handler, "media:text", self.media_text) + + if hasattr(self, 'media_thumbnail'): + PyRSS2Gen._opt_element(handler, "media:thumbnail", self.media_thumbnail) diff --git a/README.rst b/README.rst index 4fd1491..13e00c7 100644 --- a/README.rst +++ b/README.rst @@ -157,7 +157,7 @@ according to the `Media Feed specification`_. +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ | media:keywords | Not implemented | `See issue `__ | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ -| media:thumbnail | Not implemented | `See issue `__ | +| media:thumbnail | Ready | | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ | media:category | Not implemented | `See issue `__ | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ From bf662ff65ffe78753dada4416ec24581112c1cdc Mon Sep 17 00:00:00 2001 From: M D Date: Fri, 6 Jan 2017 15:46:01 -0500 Subject: [PATCH 2/4] fixed typo --- PyMediaRSS2Gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyMediaRSS2Gen.py b/PyMediaRSS2Gen.py index 2b7572e..99accdd 100644 --- a/PyMediaRSS2Gen.py +++ b/PyMediaRSS2Gen.py @@ -163,7 +163,7 @@ def publish(self, handler): def __repr__(self): """Return a nice string representation for prettier debugging.""" - return "MediaThumbmail(url='%s', width='%s', height='%s')" % \ + return "MediaThumbnail(url='%s', width='%s', height='%s')" % \ (self.element_attrs.get('url', None), self.element_attrs.get('height', None), self.element_attrs.get('width', None)) From 09684e186fd9e54beb97724290f747e7715668f7 Mon Sep 17 00:00:00 2001 From: M D Date: Sat, 7 Jan 2017 00:57:19 -0500 Subject: [PATCH 3/4] added media:keywords element --- PyMediaRSS2Gen.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/PyMediaRSS2Gen.py b/PyMediaRSS2Gen.py index 99accdd..b6fcf7b 100644 --- a/PyMediaRSS2Gen.py +++ b/PyMediaRSS2Gen.py @@ -163,13 +163,12 @@ def publish(self, handler): def __repr__(self): """Return a nice string representation for prettier debugging.""" - return "MediaThumbnail(url='%s', width='%s', height='%s')" % \ + return "MediaThumbmail(url='%s', width='%s', height='%s')" % \ (self.element_attrs.get('url', None), self.element_attrs.get('height', None), self.element_attrs.get('width', None)) - class MediaRSSItem(PyRSS2Gen.RSSItem, object): """Publish a Media RSS Item.""" @@ -186,6 +185,7 @@ def __init__( # Allows grouping of elements with the same content. media_content=None, # can be used to publish any type of media. media_thumbnail=None, # allows images to be used a representative images for media object + media_keywords=None, # keywords as metadata associated with media object media_player=None, # Allows a media object to be accessed through a web browser media # player console. @@ -200,6 +200,7 @@ def __init__( self.media_group = media_group self.media_content = media_content self.media_thumbnail = media_thumbnail + self.media_keywords = media_keywords self.media_player = media_player self.media_peerLink = media_peerLink self.media_location = media_location @@ -220,11 +221,12 @@ def __init__( def __repr__(self): """Return a nice string representation for prettier debugging.""" return "MediaContent(title='%s', media_content='%s', " \ - "media_group='%s', media_thumbnail='%s', media_player='%s', media_peerLink='%s', " \ + "media_group='%s', media_thumbnail='%s', media_keywords='%s', media_player='%s', media_peerLink='%s', " \ "media_location='%s')" % ( self.title, str(self.media_content), - str(self.Media_thumbnail), + str(self.media_thumbnail), + str(self.media_keywords), str(self.media_group), str(self.media_player), str(self.media_peerLink), @@ -246,6 +248,7 @@ def check_complicance(self): and not self.media_group and not self.media_content and not self.media_thumbnail + and not self.media_keywords and not self.media_player and not self.media_peerLink and not self.media_location @@ -296,3 +299,6 @@ def publish_extensions(self, handler): if hasattr(self, 'media_thumbnail'): PyRSS2Gen._opt_element(handler, "media:thumbnail", self.media_thumbnail) + + if hasattr(self, 'media_keywords'): + PyRSS2Gen._opt_element(handler, "media:keywords", self.media_keywords) From 931de1aa2d7e92562e875bd6892225b2e2c06846 Mon Sep 17 00:00:00 2001 From: M D Date: Tue, 10 Jan 2017 19:06:15 -0500 Subject: [PATCH 4/4] updated README.rst --- AUTHORS.rst | 1 + PyMediaRSS2Gen.py | 16 +++++++++++----- README.rst | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 1b2f9f7..124acb8 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -22,4 +22,5 @@ request. .. _Dirk Weise: http://www.dirk-weise.de/ .. _Andrew Dalke: http://dalkescientific.com/ +.. _Matt Dublin: https://github.com/mdublin .. _PyRSS2Gen: https://pypi.python.org/pypi/PyRSS2Gen/ diff --git a/PyMediaRSS2Gen.py b/PyMediaRSS2Gen.py index b6fcf7b..e2907c1 100644 --- a/PyMediaRSS2Gen.py +++ b/PyMediaRSS2Gen.py @@ -159,7 +159,11 @@ def _add_attribute(self, name, value, allowed_values=None): def publish(self, handler): """Publish the MediaThumbnail as XML.""" - PyRSS2Gen._element(handler, "media:thumbnail", None, self.element_attrs) + PyRSS2Gen._element( + handler, + "media:thumbnail", + None, + self.element_attrs) def __repr__(self): """Return a nice string representation for prettier debugging.""" @@ -184,8 +188,8 @@ def __init__( media_group=None, # Allows grouping of elements with the same content. media_content=None, # can be used to publish any type of media. - media_thumbnail=None, # allows images to be used a representative images for media object - media_keywords=None, # keywords as metadata associated with media object + media_thumbnail=None, # allows images to be used a representative images for media object + media_keywords=None, # keywords as metadata associated with media object media_player=None, # Allows a media object to be accessed through a web browser media # player console. @@ -298,7 +302,9 @@ def publish_extensions(self, handler): PyRSS2Gen._opt_element(handler, "media:text", self.media_text) if hasattr(self, 'media_thumbnail'): - PyRSS2Gen._opt_element(handler, "media:thumbnail", self.media_thumbnail) + PyRSS2Gen._opt_element( + handler, "media:thumbnail", self.media_thumbnail) if hasattr(self, 'media_keywords'): - PyRSS2Gen._opt_element(handler, "media:keywords", self.media_keywords) + PyRSS2Gen._opt_element( + handler, "media:keywords", self.media_keywords) diff --git a/README.rst b/README.rst index 13e00c7..8c395f4 100644 --- a/README.rst +++ b/README.rst @@ -155,7 +155,7 @@ according to the `Media Feed specification`_. +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ | media:description | Not implemented | `See issue `__ | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ -| media:keywords | Not implemented | `See issue `__ | +| media:keywords | Ready | | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ | media:thumbnail | Ready | | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ @@ -197,7 +197,7 @@ according to the `Media Feed specification`_. +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ | media:scenes | Not implemented | `See issue `__ | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+ -| **Summary** | **3 of 28 implemented** | `See all issues `__ | +| **Summary** | **5 of 28 implemented** | `See all issues `__ | +----------------------------------+-------------------------+----------------------------------------------------------------------------------+