Applied patch from informancer@web.de (download dirs, code cleanups) -- thanks!

git-svn-id: svn://svn.berlios.de/gpodder@36 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
Thomas Perl 2006-03-03 20:04:25 +00:00
parent 5c8b7f34b0
commit b26b758d8e
5 changed files with 121 additions and 110 deletions

View File

@ -1,8 +1,19 @@
Fri, 03 Mar 2006 20:59:17 +0100 <thp@perli.net>
* Applied patch from informancer@web.de (see below)
- Reverted to old-style channel properties dialog for now
Sun, 26 Feb 2006 00:11:28 +0100 <thp@perli.net>
* Bumped version number and date in bin/gpodder
* Updated TODO-List
* Strip html inside <description> tags (Reported by Leo Gomez)
Sat, 25 Fen 2006 12:00:00 +0100 <informancer@web.de>
* Added download dir field to channel property window
* Changed save/load of channel.xml to use download dir
* Added download_dir as a property of podcastChannel
* moved chan properties from gPodderLib to podcastChannel
* merged configChannel in podcastChannel
Sat, 04 Feb 2006 19:07:33 +0100 <thp@perli.net>
* ** gPodder version 0.5 is here! **
+ Added "downloaded episodes" tab

View File

@ -3,7 +3,7 @@
# Python module src/gpodder/gpodder.py
# Autogenerated from gpodder.glade
# Generated on Sun Feb 26 00:30:36 2006
# Generated on Sun Feb 5 08:53:31 2006
# Warning: Do not modify any context comment such as #--
# They are required to keep user's code
@ -565,13 +565,12 @@ class Gpodderstatus(SimpleGladeApp):
class Gpodderchannel(SimpleGladeApp):
waiting = None
url = ""
result = False
def __init__(self, path="gpodder.glade",
root="gPodderChannel",
domain=app_name, **kwargs):
waiting = None
url = ""
result = False
path = os.path.join(glade_dir, path)
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)

View File

@ -23,11 +23,9 @@ from os.path import dirname
from os import mkdir
from os import environ
from os import system
from threading import Event
from libpodcasts import configChannel
from librssreader import rssReader
from libwget import downloadThread
from libpodcasts import podcastChannel
# global debugging variable, set to False on release
# TODO: while developing a new version, set this to "True"
@ -78,15 +76,6 @@ class gPodderLib( object):
def getChannelsFilename( self):
return self.gpodderdir + "channels.xml"
def getChannelSaveDir( self, filename):
savedir = self.downloaddir + filename + "/"
self.createIfNecessary( savedir)
return savedir
def getChannelDownloadDir( self):
return self.downloaddir
def propertiesChanged( self):
# set new environment variables for subprocesses to use
@ -126,10 +115,7 @@ class gPodderLib( object):
if isDebugging():
print "open " + filename + " with " + self.open_app
system( self.open_app + " " + filename + " &")
def getChannelCacheFile( self, filename):
return self.cachedir + filename + ".xml"
def getPodcastFilename( self, channel, url):
# strip question mark (and everything behind it), fix %20 errors
filename = basename( url).replace( "%20", " ")
@ -137,49 +123,25 @@ class gPodderLib( object):
if indexOfQuestionMark != -1:
filename = filename[:indexOfQuestionMark]
# end strip questionmark
return self.getChannelSaveDir( configChannel( channel.title, channel.url, channel.shortname).filename) + filename
channel.download_dir
print "getPodcastFilename: ", channel.download_dir + filename
return channel.download_dir + filename
def getChannelIndexFile( self, channel):
# gets index xml filename from a channel for downloaded channels list
return self.getChannelSaveDir( configChannel( channel.title, channel.url, channel.shortname).filename) + "index.xml"
def podcastFilenameExists( self, channel, url):
return exists( self.getPodcastFilename( channel, url))
def downloadRss( self, channel_url, channel_filename = "__unknown__", force_update = True):
if channel_filename == "":
channel_filename = "__unknown__"
cachefile = gPodderLib().getChannelCacheFile( channel_filename)
if (channel_filename == "__unknown__" or exists( cachefile) == False) or force_update:
event = Event()
downloadThread( channel_url, cachefile, event).download()
while event.isSet() == False:
event.wait( 0.2)
while gtk.events_pending():
gtk.main_iteration( False)
return cachefile
class gPodderChannelWriter( object):
def __init__( self):
None
def write( self, channels):
filename = gPodderLib().getChannelsFilename()
fd = open( filename, "w")
fd.write( "<!-- automatically generated, will be overwritten on next gpodder shutdown.-->\n")
fd.write( "<channels>\n")
print >> fd, '<!-- automatically generated, will be overwritten on next gpodder shutdown.-->'
print >> fd, '<channels>'
for chan in channels:
configch = configChannel( chan.title, chan.url, chan.shortname)
fd.write( " <channel name=\"" + configch.filename + "\">\n")
fd.write( " <url>" + configch.url + "</url>\n")
fd.write( " </channel>\n")
fd.write( "</channels>\n")
print >> fd, ' <channel name="%s">' %chan.filename
print >> fd, ' <url>%s</url>' %chan.url
print >> fd, ' <download_dir>%s</download_dir>' %chan.save_dir
print >> fd, ' </channel>'
print >> fd, '</channels>'
fd.close()
class gPodderChannelReader( DefaultHandler):
@ -202,8 +164,8 @@ class gPodderChannelReader( DefaultHandler):
input_channels = []
for channel in self.channels:
cachefile = gPodderLib().downloadRss( channel.url, channel.filename, force_update)
reader.parseXML( channel.url, cachefile)
cachefile = channel.downloadRss(force_update)
reader.parseXML(channel.url, cachefile)
if channel.filename != "" and channel.filename != "__unknown__":
reader.channel.shortname = channel.filename
@ -216,13 +178,15 @@ class gPodderChannelReader( DefaultHandler):
self.current_element_data = ""
if name == "channel":
self.current_item = configChannel()
self.current_item = podcastChannel()
self.current_item.filename = attrs.get( "name", "")
def endElement( self, name):
if self.current_item != None:
if name == "url":
self.current_item.url = self.current_element_data
if name == "download_dir":
self.current_item.download_dir = self.current_element_data
if name == "channel":
self.channels.append( self.current_item)
self.current_item = None

View File

@ -27,7 +27,7 @@ class localDB( object):
downloaddir = None
def __init__( self):
self.downloaddir = gPodderLib().getChannelDownloadDir()
self.downloaddir = gPodderLib().downloaddir
self.directories = listdir( self.downloaddir)
def getIndexFileList( self):

View File

@ -16,29 +16,48 @@ import gobject
import libgpodder
from os.path import exists
from liblocdbwriter import writeLocalDB
from liblocdbreader import readLocalDB
from threading import Event
from libwget import downloadThread
import re
# podcastChannel: holds data for a complete channel
class podcastChannel(object):
url = ""
title = ""
link = ""
description = ""
items = []
image = None
shortname = None
downloaded = None
"""holds data for a complete channel"""
def __init__( self, url = "", title = "", link = "", description = ""):
self.url = url
self.title = title
self.link = link
self.description = stripHtml( description)
self.items = []
self.image = None
self.shortname = None
self.downloaded = None
self.__filename = None
self.__download_dir = None
# Create all the properties
def get_filename(self):
if self.__filename == None:
self.__filename = ""
for char in self.title.lower():
if (char >= 'a' and char <= 'z') or (char >= 'A' and char <= 'Z') or (char >= '1' and char <= '9'):
self.__filename = self.__filename + char
if self.__filename == "":
self.__filename = "__unknown__"
return self.__filename
def set_filename(self, value):
self.__filename = value
filename = property(fget=get_filename,
fset=set_filename)
def addItem( self, item):
self.items.append( item)
@ -60,9 +79,9 @@ class podcastChannel(object):
writeLocalDB( localdb, self.downloaded)
def printChannel( self):
print "- Channel: \"" + self.title + "\""
print '- Channel: "' + self.title + '"'
for item in self.items:
print "-- Item: \"" + item.title + "\""
print '-- Item: "' + item.title + '"'
def isDownloaded( self, item):
return libgpodder.gPodderLib().podcastFilenameExists( self, item.url)
@ -96,18 +115,63 @@ class podcastChannel(object):
return -1
# podcastItem: holds data for one object in a channel
class podcastItem(object):
url = ""
title = ""
length = ""
mimetype = ""
guid = ""
description = ""
link = ""
def downloadRss( self, force_update = True):
if (self.filename == "__unknown__" or exists( self.cache_file) == False) or force_update:
event = Event()
downloadThread(self.url, self.cache_file, event).download()
while event.isSet() == False:
event.wait( 0.2)
#FIXME: we do not want gtk code when not needed
while gtk.events_pending():
gtk.main_iteration( False)
return self.cache_file
def __init__( self, url = "", title = "", length = "0", mimetype = "", guid = "", description = "", link = ""):
def get_save_dir(self):
savedir = self.download_dir + self.filename + "/"
libgpodder.gPodderLib().createIfNecessary( savedir)
return savedir
save_dir = property(fget=get_save_dir)
def get_download_dir(self):
print "get download dir:", self, self.__download_dir
if self.__download_dir == None:
return libgpodder.gPodderLib().downloaddir
else:
return self.__download_dir
def set_download_dir(self, value):
self.__download_dir = value
libgpodder.gPodderLib().createIfNecessary(self.__download_dir)
print "set download dir:", self, self.__download_dir
download_dir = property (fget=get_download_dir,
fset=set_download_dir)
def get_cache_file(self):
return libgpodder.gPodderLib().cachedir + self.filename + ".xml"
cache_file = property(fget=get_cache_file)
def get_index_file(self):
# gets index xml filename for downloaded channels list
return self.save_dir + "index.xml"
index_file = property(fget=get_index_file)
class podcastItem(object):
"""holds data for one object in a channel"""
def __init__( self,
url = "",
title = "",
length = "0",
mimetype = "",
guid = "",
description = "",
link = ""):
self.url = url
self.title = title
self.length = length
@ -131,31 +195,6 @@ class podcastItem(object):
return str( size) + " Bytes"
class configChannel( object):
title =""
url =""
filename = None
def __init__( self, title = "", url = "", filename = None):
self.title = title
self.url = url
if filename == None:
self.filename = self.createFilename()
else:
self.filename = filename
def createFilename( self):
result = ""
for char in self.title.lower():
if (char >= 'a' and char <= 'z') or (char >= 'A' and char <= 'Z') or (char >= '1' and char <= '9'):
result = result + char
return result
def channelsToModel( channels):
new_model = gtk.ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_OBJECT)
@ -170,9 +209,7 @@ def channelsToModel( channels):
return new_model
def stripHtml( html):
# strips html from a string (fix for <description> tags containing html)
rexp = re.compile( "<[^>]*>")
return rexp.sub( "", html)