bugfix for invalid rss files + rssReader improvements

git-svn-id: svn://svn.berlios.de/gpodder/trunk@230 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
Thomas Perl 2007-01-06 13:48:46 +00:00
parent ea1599cb1f
commit 46e86ef18f
6 changed files with 66 additions and 41 deletions

View File

@ -1,3 +1,18 @@
Sat, 6 Jan 2007 14:45:20 +0100 <thp@perli.net>
* src/gpodder/libgpodder.py: Re-factured gPodderChannelReader
to not have static members when they're not needed; only add
channel to the list if our rssReader returns a valid channel
* src/gpodder/librssreader.py: Removed rssErrorHandler class
and added handling routines directly to rssReader class; re-factor
static members to object members; do better error handling, etc..
* src/gpodder/libopmlreader.py: Don't use rssErrorHandler from
librssreader but handle errors directly in opmlReader
* src/gpodder/gpodder.py: Only ask user to download newer episodes
when the channel really has been added (thanks to Alain Tauch for
bringing this bug to my attention)
* bin/gpodder: Bumped version + release date - this being the first
svn revision to mention 2007 in the version string :) Enjoy!
Sat, 6 Jan 2007 14:06:31 +0100 <thp@perli.net>
* src/gpodder/libgpodder.py: Set the default download dir to
some same value when initializing gPodderLib

View File

@ -26,8 +26,8 @@
# PLEASE DO NOT CHANGE FORMAT OF __version__ LINE (setup.py reads this)
__author__ = "Thomas Perl <thp@perli.net>"
__version__ = "0.8.0+svn20061229"
__date__ = "2006-12-29"
__version__ = "0.8.0+svn20070106"
__date__ = "2007-01-06"
__copyright__ = "Copyright (c) 2005-2007 %s. All rights reserved." % __author__
__licence__ = "GPL"

View File

@ -312,6 +312,7 @@ class Gpodder(SimpleGladeApp):
self.statusLabel.set_text( _("Fetching channel index..."))
channel = podcastChannel( url = result)
channel.remove_cache_file()
num_channels_before = len(self.channels)
self.channels.append( channel)
# download changed channels
@ -321,9 +322,10 @@ class Gpodder(SimpleGladeApp):
self.updateComboBox()
self.statusLabel.set_text( "")
# ask user to download some new episodes
self.comboAvailable.set_active( len( self.channels)-1)
self.on_btnDownloadNewer_clicked( None)
if num_channels_before < len(self.channels):
# ask user to download some new episodes
self.comboAvailable.set_active( len( self.channels)-1)
self.on_btnDownloadNewer_clicked( None)
else:
if result:
self.showMessage( _('Could not add new channel.\n\nThe URL must start with <b>http://</b>, <b>feed://</b> or <b>ftp://</b>.'))

View File

@ -418,12 +418,10 @@ class gPodderChannelWriter( object):
fd.close()
class gPodderChannelReader( DefaultHandler):
channels = []
current_item = None
current_element_data = ""
def __init__( self):
None
self.channels = []
self.current_item = None
self.current_element_data = ''
def read( self, force_update = False, callback_proc = None):
"""Read channels from a file into gPodder's cache
@ -460,7 +458,8 @@ class gPodderChannelReader( DefaultHandler):
# check if download was a success
if cachefile != None:
reader.parseXML( channel.url, cachefile)
input_channels.append( reader.channel)
if reader.channel != None:
input_channels.append( reader.channel)
position = position + 1

View File

@ -41,18 +41,22 @@ from urllib import unquote_plus
from libpodcasts import opmlChannel
from libpodcasts import stripHtml
from librssreader import rssErrorHandler
class opmlReader( DefaultHandler):
channels = []
title = 'Unknown OPML Channel'
current_item = None
current_element_data = ""
class opmlReader( DefaultHandler, ErrorHandler):
def __init__( self):
None
self.channels = []
self.title = 'Unknown OPML Channel'
self.current_item = None
self.current_element_data = ''
def error( self, exception):
log( '[opmlReader] Error: %s', str( exception))
def fatalError( self, exception):
log( '[opmlReader] Fatal Error: %s', str( exception))
def warning( self, exception):
log( '[opmlReader] Warning: %s', str( exception))
def get_model( self):
new_model = gtk.ListStore( gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING)

View File

@ -37,34 +37,38 @@ from libpodcasts import podcastChannel
from libpodcasts import podcastItem
from libpodcasts import stripHtml
class rssErrorHandler( ErrorHandler):
def __init__( self):
None
from liblogger import log
class rssReader( DefaultHandler, ErrorHandler):
def __init__( self):
self.channel_url = ''
self.channel = None
self.current_item = None
self.current_element_data = ''
def error( self, exception):
print exception
log( '[rssReader] Error: %s', str( exception))
log( 'Disposing channel: %s', self.channel_url)
self.channel = None
def fatalError( self, exception):
print "FATAL ERROR: ", exception
log( '[rssReader] Fatal Error: %s', str( exception))
log( 'Disposing channel: %s', self.channel_url)
self.channel = None
def warning( self, exception):
print "warning: ", exception
log( '[rssReader] Warning: %s', str( exception))
class rssReader( DefaultHandler):
channel_url = ""
channel = None
current_item = None
current_element_data = ""
def __init__( self):
None
def parseXML( self, url, filename):
log('rssReader parseXML-> %s, %s', url, filename)
self.channel_url = url
self.channel = None
self.current_item = None
self.current_element_data = ''
parser = make_parser()
parser.returns_unicode = True
parser.setContentHandler( self)
parser.setErrorHandler( rssErrorHandler())
parser.setErrorHandler( self)
# no multithreaded access to filename
libgpodder.getLock()
try:
@ -77,19 +81,20 @@ class rssReader( DefaultHandler):
if name == "channel":
self.channel = podcastChannel( self.channel_url)
if name == "item":
self.current_item = podcastItem()
if name == "enclosure" and self.current_item != None:
if name == "enclosure" and self.current_item:
self.current_item.url = attrs.get( "url", "")
self.current_item.length = attrs.get( "length", "")
self.current_item.mimetype = attrs.get( "type", "")
if name == "itunes:image":
if name == "itunes:image" and self.channel != None:
self.channel.image = attrs.get( "href", "")
def endElement( self, name):
if self.current_item == None:
if self.channel != None and not self.current_item:
if name == "title":
self.channel.title = self.current_element_data
if name == "link":
@ -105,7 +110,7 @@ class rssReader( DefaultHandler):
if name == "webMaster":
self.channel.webMaster = self.current_element_data
if self.current_item != None:
if self.channel != None and self.current_item:
if name == "title":
self.current_item.title = self.current_element_data
if name == "link":