Skip to content

Commit 7a44f05

Browse files
committed
Common prefix elimination for episode titles
This should improve the amount of useful information in episode lists, especially on mobile devices.
1 parent 876acad commit 7a44f05

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/gpodder/gtkui/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,18 @@ def get_search_term(self):
221221
return self._search_term
222222

223223
def _format_description(self, episode, include_description=False):
224+
title = episode.trimmed_title
224225
a, b = '', ''
225226
if episode.state != gpodder.STATE_DELETED and episode.is_new:
226227
a, b = '<b>', '</b>'
227228
if include_description and self._all_episodes_view:
228-
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(episode.title), b,
229+
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(title), b,
229230
_('from %s') % cgi.escape(episode.channel.title))
230231
elif include_description:
231-
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(episode.title), b,
232+
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(title), b,
232233
cgi.escape(episode.one_line_description()))
233234
else:
234-
return ''.join((a, cgi.escape(episode.title), b))
235+
return ''.join((a, cgi.escape(title), b))
235236

236237
def replace_from_channel(self, channel, include_description=False,
237238
treeview=None):

src/gpodder/model.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ def channel(self):
348348
def db(self):
349349
return self.parent.parent.db
350350

351+
@property
352+
def trimmed_title(self):
353+
"""Return the title with the common prefix trimmed"""
354+
if (self.parent._common_prefix is not None and
355+
self.title.startswith(self.parent._common_prefix)):
356+
return self.title[len(self.parent._common_prefix):]
357+
358+
return self.title
359+
351360
def _set_download_task(self, download_task):
352361
self.children = (download_task, self.children[1])
353362

@@ -715,7 +724,7 @@ def update_from(self, episode):
715724

716725

717726
class PodcastChannel(PodcastModelObject):
718-
__slots__ = schema.PodcastColumns
727+
__slots__ = schema.PodcastColumns + ('_common_prefix',)
719728

720729
UNICODE_TRANSLATE = {ord(u'ö'): u'o', ord(u'ä'): u'a', ord(u'ü'): u'u'}
721730

@@ -747,6 +756,7 @@ def __init__(self, model):
747756
self.pause_subscription = False
748757

749758
self.section = _('Other')
759+
self._common_prefix = None
750760

751761
@property
752762
def model(self):
@@ -1213,6 +1223,14 @@ def get_downloaded_episodes(self):
12131223
def get_all_episodes(self):
12141224
if self.children is None:
12151225
self.children = self.db.load_episodes(self, self.episode_factory)
1226+
1227+
prefix = os.path.commonprefix([x.title for x in self.children])
1228+
# The common prefix must end with a space - otherwise it's not
1229+
# on a word boundary, and we might end up chopping off too much
1230+
if prefix and prefix[-1] != ' ' and ' ' in prefix:
1231+
prefix = prefix[:prefix.rfind(' ')+1]
1232+
self._common_prefix = prefix
1233+
12161234
return self.children
12171235

12181236
def find_unique_folder_name(self, download_folder):

src/gpodder/qmlui/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _podcast(self):
9696
qpodcast = Property(QObject, _podcast, notify=never_changed)
9797

9898
def _title(self):
99-
return convert(self._episode.title)
99+
return convert(self._episode.trimmed_title)
100100

101101
qtitle = Property(unicode, _title, notify=changed)
102102

0 commit comments

Comments
 (0)