Permalink
Browse files

Common prefix elimination for episode titles

This should improve the amount of useful information
in episode lists, especially on mobile devices.
  • Loading branch information...
1 parent 876acad commit 7a44f05c80a3fa2bb6f9177168fab17ad7dba054 @thp thp committed Dec 5, 2011
Showing with 24 additions and 5 deletions.
  1. +4 −3 src/gpodder/gtkui/model.py
  2. +19 −1 src/gpodder/model.py
  3. +1 −1 src/gpodder/qmlui/model.py
@@ -221,17 +221,18 @@ def get_search_term(self):
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
@@ -348,6 +348,15 @@ def channel(self):
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 @@ def update_from(self, episode):
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 @@ def __init__(self, model):
self.pause_subscription = False
self.section = _('Other')
+ self._common_prefix = None
@property
def model(self):
@@ -1213,6 +1223,14 @@ def get_downloaded_episodes(self):
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):
@@ -96,7 +96,7 @@ def _podcast(self):
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)

0 comments on commit 7a44f05

Please sign in to comment.