added DownloadHistory
git-svn-id: svn://svn.berlios.de/gpodder/trunk@203 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
parent
ba88f68c38
commit
1eb0f3b272
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Fri, 8 Dec 2006 21:50:39 +0100 <thp@perli.net>
|
||||
* src/gpodder/libpodcasts.py: Add DownloadHistory class that saves
|
||||
a list of already downloaded URLs; Make the podcastChannel class
|
||||
utilize DownloadHistory through gPodderLib (background color for
|
||||
already downloaded but already deleted episode is light green,
|
||||
mark as downloaded when adding to localdb, utilize the history
|
||||
in newest_pubdate_downloaded(), but keep the old method as a
|
||||
fallback)
|
||||
* src/gpodder/libgpodder.py: Make a single DownloadHistory object
|
||||
available through gPodderLib (+ functions to utilize it)
|
||||
* src/gpodder/liblocaldb.py: Mark downloaded items when loading
|
||||
the model for the downloaded list (in case one has downloaded
|
||||
episodes before this commit)
|
||||
* bin/gpodder: pushed release date + version
|
||||
|
||||
Wed, 6 Dec 2006 21:23:53 +0100 <thp@perli.net>
|
||||
* merged svn branch thp-december-2006 into trunk
|
||||
|
||||
|
|
|
@ -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+svn20061206-trunk"
|
||||
__date__ = "2006-12-06"
|
||||
__version__ = "0.8.0+svn20061208"
|
||||
__date__ = "2006-12-08"
|
||||
__copyright__ = "Copyright (c) 2005-2006 %s. All rights reserved." % __author__
|
||||
__licence__ = "GPL"
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ from stat import ST_MODE
|
|||
|
||||
from librssreader import rssReader
|
||||
from libpodcasts import podcastChannel
|
||||
from libpodcasts import DownloadHistory
|
||||
from libplayers import dotdesktop_command
|
||||
from liblogger import log
|
||||
|
||||
|
@ -118,6 +119,7 @@ class gPodderLibClass( object):
|
|||
self.desktop_link = _("gPodder downloads")
|
||||
self.device_type = None
|
||||
self.mp3_player_folder = ""
|
||||
self.__download_history = DownloadHistory( self.get_download_history_filename())
|
||||
self.loadConfig()
|
||||
|
||||
def createIfNecessary( self, path):
|
||||
|
@ -137,6 +139,9 @@ class gPodderLibClass( object):
|
|||
def getChannelsFilename( self):
|
||||
return self.gpodderdir + "channels.xml"
|
||||
|
||||
def get_download_history_filename( self):
|
||||
return self.gpodderdir + 'download-history.txt'
|
||||
|
||||
def propertiesChanged( self):
|
||||
# set new environment variables for subprocesses to use,
|
||||
# but only if we are not told to passthru the env vars
|
||||
|
@ -211,6 +216,12 @@ class gPodderLibClass( object):
|
|||
|
||||
downloaddir = property(fget=get_download_dir,fset=set_download_dir)
|
||||
|
||||
def history_mark_downloaded( self, url):
|
||||
self.__download_history.mark_downloaded( url)
|
||||
|
||||
def history_is_downloaded( self, url):
|
||||
return (url in self.__download_history)
|
||||
|
||||
def get_from_parser( self, parser, option, default = ''):
|
||||
try:
|
||||
result = parser.get( self.gpodderconf_section, option)
|
||||
|
|
|
@ -71,6 +71,13 @@ class localDB( object):
|
|||
|
||||
|
||||
def get_tree_model( self, url):
|
||||
# Try to add downloaded items (TODO: remove at some point in the future)
|
||||
to_be_added = []
|
||||
for episode in self.get_channel( url):
|
||||
to_be_added.append( episode.url)
|
||||
if to_be_added:
|
||||
gPodderLib().history_mark_downloaded( to_be_added)
|
||||
|
||||
return self.get_channel( url).getItemsModel( False)
|
||||
|
||||
def get_model( self):
|
||||
|
|
|
@ -134,11 +134,19 @@ class podcastChannel(ListType):
|
|||
self.device_playlist_name = ch.device_playlist_name
|
||||
|
||||
def newest_pubdate_downloaded( self):
|
||||
pubdate = None
|
||||
gl = libgpodder.gPodderLib()
|
||||
last_episode = None
|
||||
|
||||
# Try DownloadHistory's entries first
|
||||
for episode in self:
|
||||
if gl.history_is_downloaded( episode.url) and last_episode:
|
||||
return last_episode.pubDate
|
||||
last_episode = episode
|
||||
|
||||
# If nothing found, do pubDate comparison
|
||||
pubdate = None
|
||||
for episode in self.localdb_channel:
|
||||
pubdate = episode.newer_pubdate( pubdate)
|
||||
|
||||
return pubdate
|
||||
|
||||
def addDownloadedItem( self, item):
|
||||
|
@ -161,6 +169,8 @@ class podcastChannel(ListType):
|
|||
self.downloaded.append( item)
|
||||
else:
|
||||
log( 'Podcast episode already downloaded.')
|
||||
|
||||
libgpodder.gPodderLib().history_mark_downloaded( item.url)
|
||||
|
||||
writeLocalDB( localdb, self.downloaded)
|
||||
libgpodder.releaseLock()
|
||||
|
@ -190,9 +200,11 @@ class podcastChannel(ListType):
|
|||
# Skip items with no download url
|
||||
if item.url:
|
||||
if self.is_downloaded( item) and want_color:
|
||||
background_color = '#AAFFAA'
|
||||
elif downloading_callback and downloading_callback( item.url):
|
||||
background_color = '#FFCCAA'
|
||||
background_color = '#99FF99'
|
||||
elif downloading_callback and downloading_callback( item.url) and want_color:
|
||||
background_color = '#FFBC99'
|
||||
elif libgpodder.gPodderLib().history_is_downloaded( item.url) and want_color:
|
||||
background_color = '#DDFFCC'
|
||||
else:
|
||||
background_color = '#FFFFFF'
|
||||
new_iter = new_model.append()
|
||||
|
@ -409,6 +421,44 @@ class opmlChannel(object):
|
|||
self.xmlurl = xmlurl
|
||||
|
||||
|
||||
class DownloadHistory( ListType):
|
||||
def __init__( self, filename):
|
||||
self.filename = filename
|
||||
try:
|
||||
self.read_from_file()
|
||||
except:
|
||||
log( '(DownloadHistory) Creating new history list.')
|
||||
|
||||
def read_from_file( self):
|
||||
for line in open( self.filename, 'r'):
|
||||
self.append( line.strip())
|
||||
|
||||
def save_to_file( self):
|
||||
if len( self):
|
||||
fp = open( self.filename, 'w')
|
||||
for url in self:
|
||||
fp.write( url + "\n")
|
||||
fp.close()
|
||||
log( '(DownloadHistory) Wrote %d history entries.', len( self))
|
||||
|
||||
def mark_downloaded( self, data, autosave = True):
|
||||
affected = 0
|
||||
if data and type( data) is ListType:
|
||||
# Support passing a list of urls to this function
|
||||
for url in data:
|
||||
affected = affected + self.mark_downloaded( url, autosave = False)
|
||||
else:
|
||||
if data not in self:
|
||||
log( '(DownloadHistory) Marking as downloaded: %s', data)
|
||||
self.append( data)
|
||||
affected = affected + 1
|
||||
|
||||
if affected and autosave:
|
||||
self.save_to_file()
|
||||
|
||||
return affected
|
||||
|
||||
|
||||
def channelsToModel( channels):
|
||||
new_model = gtk.ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING)
|
||||
|
||||
|
@ -429,3 +479,4 @@ def stripHtml( html):
|
|||
stripstr = stripstr.replace( '&'+unicode(key,'iso-8859-1')+';', unicode(dict[key], 'iso-8859-1'))
|
||||
return stripstr
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue