Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/
67 changes: 66 additions & 1 deletion PyMediaRSS2Gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,55 @@ 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."""
Expand All @@ -139,6 +188,8 @@ def __init__(
media_group=None,
# Allows grouping of <media:content> 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.
Expand All @@ -152,6 +203,8 @@ 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_keywords = media_keywords
self.media_player = media_player
self.media_peerLink = media_peerLink
self.media_location = media_location
Expand All @@ -172,10 +225,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_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_keywords),
str(self.media_group),
str(self.media_player),
str(self.media_peerLink),
Expand All @@ -196,6 +251,8 @@ 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_keywords
and not self.media_player
and not self.media_peerLink
and not self.media_location
Expand Down Expand Up @@ -243,3 +300,11 @@ 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)

if hasattr(self, 'media_keywords'):
PyRSS2Gen._opt_element(
handler, "media:keywords", self.media_keywords)
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ according to the `Media Feed specification`_.
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| media:description | Not implemented | `See issue <https://github.com/wedi/PyMediaRSS2Gen/issues/4>`__ |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| media:keywords | Not implemented | `See issue <https://github.com/wedi/PyMediaRSS2Gen/issues/5>`__ |
| media:keywords | Ready | |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| media:thumbnail | Not implemented | `See issue <https://github.com/wedi/PyMediaRSS2Gen/issues/6>`__ |
| media:thumbnail | Ready | |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| media:category | Not implemented | `See issue <https://github.com/wedi/PyMediaRSS2Gen/issues/7>`__ |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
Expand Down Expand Up @@ -197,7 +197,7 @@ according to the `Media Feed specification`_.
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| media:scenes | Not implemented | `See issue <https://github.com/wedi/PyMediaRSS2Gen/issues/25>`__ |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+
| **Summary** | **3 of 28 implemented** | `See all issues <https://github.com/wedi/PyMediaRSS2Gen/labels/specification>`__ |
| **Summary** | **5 of 28 implemented** | `See all issues <https://github.com/wedi/PyMediaRSS2Gen/labels/specification>`__ |
+----------------------------------+-------------------------+----------------------------------------------------------------------------------+


Expand Down