Skip to content

Commit

Permalink
Common prefix elimination for episode titles
Browse files Browse the repository at this point in the history
This should improve the amount of useful information
in episode lists, especially on mobile devices.
  • Loading branch information
thp committed Dec 5, 2011
1 parent 876acad commit 7a44f05
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/gpodder/gtkui/model.py
Expand Up @@ -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):
Expand Down
20 changes: 19 additions & 1 deletion src/gpodder/model.py
Expand Up @@ -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])

Expand Down Expand Up @@ -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'}

Expand Down Expand Up @@ -747,6 +756,7 @@ def __init__(self, model):
self.pause_subscription = False

self.section = _('Other')
self._common_prefix = None

@property
def model(self):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/gpodder/qmlui/model.py
Expand Up @@ -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)

Expand Down

0 comments on commit 7a44f05

Please sign in to comment.