Skip to content

Commit

Permalink
Less error-prone enclosure_length getting
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 6, 2016
1 parent 8e71c41 commit cfc8554
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Added ``enclosure_length`` meta field for better interop (Issue #2338)
* New Lithuanian translation by Antanas Lasys

Bugfixes
Expand Down
8 changes: 7 additions & 1 deletion nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ def _enclosure(post, lang):
"""Add an enclosure to RSS."""
enclosure = post.meta('enclosure', lang)
if enclosure:
length = int(post.meta('enclosure_length', lang) or 0)
try:
length = int(post.meta('enclosure_length', lang) or 0)
except KeyError:
length = 0
except ValueError:
utils.LOGGER.warn("Invalid enclosure length for post {0}".format(post.source_path))
length = 0
url = enclosure
mime = mimetypes.guess_type(url)[0]
return url, length, mime
Expand Down
3 changes: 2 additions & 1 deletion tests/test_rss_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def setUp(self):
'tags': 'tags',
'link': 'link',
'description': 'description',
'enclosure': 'http://www.example.org/foo.mp3'},
'enclosure': 'http://www.example.org/foo.mp3',
'enclosure_length': '5'},
True)
))):
with mock.patch('nikola.nikola.utils.os.path.isdir',
Expand Down

0 comments on commit cfc8554

Please sign in to comment.