Don't mark old episodes as new on update (bug 340)

Another attempt at finally fixing bug 340, but this time I'm pretty sure
that it works, because we are more selective now.

Whenever a new episode appears in the feed, its date is compared to the
date of the newest-known episode in the same feed. If it's more than one
week older than the newest-known episode, it's marked as old by default.

The "one week" value is just a randomly-chosen one to allow for border
cases (like a daily podcast re-issuing an episode of the last few days)
to work correctly and not cause "missing episodes".
This commit is contained in:
Thomas Perl 2010-03-11 19:41:29 +01:00
parent 3d3fcd256b
commit 2b3a2aa743
2 changed files with 23 additions and 3 deletions

View File

@ -603,6 +603,16 @@ class Database(object):
self.log("find_channel_id(%s)", url)
return self.__get__("SELECT id FROM channels WHERE url = ?", (url, ))
def get_last_pubdate(self, channel):
"""
Look up the highest "pubDate" value for
all episodes of the given podcast.
"""
return self.__get__("""
SELECT MAX(pubDate) FROM episodes
WHERE channel_id = ?
""", (channel.id, ))
def force_last_new(self, channel):
old = self.__get__("""SELECT COUNT(*) FROM episodes WHERE channel_id = ?
AND state IN (?, ?)""", (channel.id, gpodder.STATE_DOWNLOADED,

View File

@ -117,6 +117,7 @@ class PodcastModelObject(object):
class PodcastChannel(PodcastModelObject):
"""holds data for a complete channel"""
MAX_FOLDERNAME_LENGTH = 150
SECONDS_PER_WEEK = 7*24*60*60
feed_fetcher = gPodderFetcher()
@ -224,6 +225,9 @@ class PodcastChannel(PodcastModelObject):
# GUID-based existing episode list
existing_guids = dict((e.guid, e) for e in existing)
# Get most recent pubDate of all episodes
last_pubdate = self.db.get_last_pubdate(self) or 0
# Search all entries for new episodes
for entry in entries:
try:
@ -252,8 +256,15 @@ class PodcastChannel(PodcastModelObject):
existing_episode.save()
continue
# Otherwise we have found a new episode to store in the DB
self.count_new += 1
# Workaround for bug 340: If the episode has been
# published earlier than one week before the most
# recent existing episode, do not mark it as new.
if episode.pubDate < last_pubdate - self.SECONDS_PER_WEEK:
log('Episode with old date: %s', episode.title, sender=self)
episode.is_played = True
else:
self.count_new += 1
episode.save()
# Remove "unreachable" episodes - episodes that have not been
@ -365,7 +376,6 @@ class PodcastChannel(PodcastModelObject):
self.image = None
self.pubDate = 0
self.parse_error = None
self.newest_pubdate_cached = None
self.foldername = None
self.auto_foldername = 1 # automatically generated foldername