Common prefix elimination for episode titles

This should improve the amount of useful information
in episode lists, especially on mobile devices.
This commit is contained in:
Thomas Perl 2011-12-05 16:32:03 +01:00
parent 876acad2e1
commit 7a44f05c80
3 changed files with 24 additions and 5 deletions

View File

@ -221,17 +221,18 @@ class EpisodeListModel(gtk.ListStore):
return self._search_term
def _format_description(self, episode, include_description=False):
title = episode.trimmed_title
a, b = '', ''
if episode.state != gpodder.STATE_DELETED and episode.is_new:
a, b = '<b>', '</b>'
if include_description and self._all_episodes_view:
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(episode.title), b,
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(title), b,
_('from %s') % cgi.escape(episode.channel.title))
elif include_description:
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(episode.title), b,
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(title), b,
cgi.escape(episode.one_line_description()))
else:
return ''.join((a, cgi.escape(episode.title), b))
return ''.join((a, cgi.escape(title), b))
def replace_from_channel(self, channel, include_description=False,
treeview=None):

View File

@ -348,6 +348,15 @@ class PodcastEpisode(PodcastModelObject):
def db(self):
return self.parent.parent.db
@property
def trimmed_title(self):
"""Return the title with the common prefix trimmed"""
if (self.parent._common_prefix is not None and
self.title.startswith(self.parent._common_prefix)):
return self.title[len(self.parent._common_prefix):]
return self.title
def _set_download_task(self, download_task):
self.children = (download_task, self.children[1])
@ -715,7 +724,7 @@ class PodcastEpisode(PodcastModelObject):
class PodcastChannel(PodcastModelObject):
__slots__ = schema.PodcastColumns
__slots__ = schema.PodcastColumns + ('_common_prefix',)
UNICODE_TRANSLATE = {ord(u'ö'): u'o', ord(u'ä'): u'a', ord(u'ü'): u'u'}
@ -747,6 +756,7 @@ class PodcastChannel(PodcastModelObject):
self.pause_subscription = False
self.section = _('Other')
self._common_prefix = None
@property
def model(self):
@ -1213,6 +1223,14 @@ class PodcastChannel(PodcastModelObject):
def get_all_episodes(self):
if self.children is None:
self.children = self.db.load_episodes(self, self.episode_factory)
prefix = os.path.commonprefix([x.title for x in self.children])
# The common prefix must end with a space - otherwise it's not
# on a word boundary, and we might end up chopping off too much
if prefix and prefix[-1] != ' ' and ' ' in prefix:
prefix = prefix[:prefix.rfind(' ')+1]
self._common_prefix = prefix
return self.children
def find_unique_folder_name(self, download_folder):

View File

@ -96,7 +96,7 @@ class QEpisode(QObject):
qpodcast = Property(QObject, _podcast, notify=never_changed)
def _title(self):
return convert(self._episode.title)
return convert(self._episode.trimmed_title)
qtitle = Property(unicode, _title, notify=changed)