More sanitizing hacks for ugly feeds we don't really like
git-svn-id: svn://svn.berlios.de/gpodder/trunk@410 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
parent
41fa8bc909
commit
92ccb39fb5
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Sun, 02 Sep 2007 14:23:17 +0200 <thp@perli.net>
|
||||
More sanitizing hacks for ugly feeds we don't really like
|
||||
|
||||
* src/gpodder/libpodcasts.py: Negotiate which enclosure to select from
|
||||
multiple enclosures, if there are more than one available; skip
|
||||
episodes with a buggy download URL (i.e. no supported URL scheme)
|
||||
* src/gpodder/util.py: Return "(unknown)" if file size cannot be
|
||||
determined from the string passed to format_filesize(); return "None"
|
||||
in file_type_by_extension() if the extension is an empty string
|
||||
|
||||
Fri, 31 Aug 2007 23:38:01 +0200 <thp@perli.net>
|
||||
Handle enclosures (or lack thereof) better if fields are missing
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ class podcastChannel(ListType):
|
|||
|
||||
for entry in c.entries:
|
||||
if not hasattr( entry, 'enclosures'):
|
||||
log('Skipping entry: %s', entry.get( 'id', '(no id available)'))
|
||||
log('Skipping entry: %s', entry.get( 'id', '(no id available)'), sender = channel)
|
||||
continue
|
||||
|
||||
episode = None
|
||||
|
@ -134,7 +134,7 @@ class podcastChannel(ListType):
|
|||
try:
|
||||
episode = podcastItem.from_feedparser_entry( entry, channel)
|
||||
except:
|
||||
log( 'Cannot instantiate episode for %s. Skipping.', entry.enclosures[0].href, sender = channel)
|
||||
log( 'Cannot instantiate episode: %s. Skipping.', entry.get( 'id', '(no id available)'), sender = channel)
|
||||
|
||||
if episode:
|
||||
channel.append( episode)
|
||||
|
@ -498,11 +498,19 @@ class podcastItem(object):
|
|||
if episode.title == '':
|
||||
log( 'Warning: Episode has no title, adding anyways.. (Feed Is Buggy!)', sender = episode)
|
||||
|
||||
if len(entry.enclosures) > 1:
|
||||
log( 'Warning: More than one enclosure found in feed, only using first', sender = episode)
|
||||
|
||||
enclosure = entry.enclosures[0]
|
||||
episode.url = enclosure.href
|
||||
if len(entry.enclosures) > 1:
|
||||
for e in entry.enclosures:
|
||||
if hasattr( e, 'href') and hasattr( e, 'length') and hasattr( e, 'type') and (e.type.startswith('audio/') or e.type.startswith('video/')):
|
||||
if util.normalize_feed_url( e.href) != None:
|
||||
log( 'Selected enclosure: %s', e.href, sender = episode)
|
||||
enclosure = e
|
||||
break
|
||||
|
||||
episode.url = util.normalize_feed_url( enclosure.get( 'href', ''))
|
||||
if not episode.url:
|
||||
raise ValueError( 'Episode has an invalid URL')
|
||||
|
||||
if hasattr( enclosure, 'length'):
|
||||
episode.length = enclosure.length
|
||||
if hasattr( enclosure, 'type'):
|
||||
|
|
|
@ -151,7 +151,10 @@ def format_filesize( bytesize, method = None):
|
|||
'B': 1.0
|
||||
}
|
||||
|
||||
bytesize = float( bytesize)
|
||||
try:
|
||||
bytesize = float( bytesize)
|
||||
except:
|
||||
return _('(unknown)')
|
||||
|
||||
if bytesize < 0:
|
||||
return _('(unknown)')
|
||||
|
@ -251,6 +254,9 @@ def file_type_by_extension( extension):
|
|||
'torrent': [ 'torrent' ],
|
||||
}
|
||||
|
||||
if extension == '':
|
||||
return None
|
||||
|
||||
if extension[0] == '.':
|
||||
extension = extension[1:]
|
||||
|
||||
|
|
Loading…
Reference in New Issue