Ignore image enclosures for audio/video in Media RSS (bug 1430)

We have only checked if audio and/or video is available in
normal enclosures. This check is now extended to Media RSS
items, because there are feeds that have the image as
enclosure and the media file as Media RSS content.

Example feed: http://www.rtl.fr/emission/a-la-bonne-heure.rss
This commit is contained in:
Thomas Perl 2011-09-06 11:47:57 +02:00
parent 580056a59c
commit 7cea824359
1 changed files with 8 additions and 3 deletions

View File

@ -170,10 +170,11 @@ class PodcastEpisode(PodcastModelObject):
episode.published = rfc822.mktime_tz(entry.updated_parsed+(0,))
enclosures = entry.get('enclosures', ())
media_rss_content = entry.get('media_content', ())
audio_available = any(e.get('type', '').startswith('audio/') \
for e in enclosures)
for e in enclosures + media_rss_content)
video_available = any(e.get('type', '').startswith('video/') \
for e in enclosures)
for e in enclosures + media_rss_content)
# Create the list of preferred mime types
mimetype_prefs = mimetype_prefs.split(',')
@ -204,6 +205,7 @@ class PodcastEpisode(PodcastModelObject):
continue
# Skip images in feeds if audio or video is available (bug 979)
# This must (and does) also look in Media RSS enclosures (bug 1430)
if episode.mime_type.startswith('image/') and \
(audio_available or video_available):
continue
@ -226,11 +228,14 @@ class PodcastEpisode(PodcastModelObject):
return episode
# Media RSS content
for m in entry.get('media_content', ()):
for m in sorted(media_rss_content, key=calculate_preference_value):
episode.mime_type = m.get('type', 'application/octet-stream')
if '/' not in episode.mime_type:
continue
# XXX: Does Media RSS content also have images? If so, we
# might want to skip these too (see above for enclosures).
episode.url = util.normalize_feed_url(m.get('url', ''))
if not episode.url:
continue