Skip to content

Commit

Permalink
Support serial chrono order.
Browse files Browse the repository at this point in the history
  • Loading branch information
drmikecrowe committed Jun 14, 2020
1 parent 456ff48 commit fb36b3d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
49 changes: 47 additions & 2 deletions bin/gpo
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
list List all subscribed podcasts
update [URL] Check for new episodes (all or only at URL)
episodic URL Set feed to episodic (newest episodes first)
serial URL Set feed to serial (oldest episodes first)
- Episode management -
download [URL] Download new episodes (all or only from URL)
Expand Down Expand Up @@ -488,12 +491,14 @@ class gPodderCli(object):

title, url, status = podcast.title, podcast.url, \
feed_update_status_msg(podcast)
strategy = 'episodic (newest first)' if podcast.download_strategy != podcast.STRATEGY_CHRONO else 'serial (oldest first)'
episodes = self._episodesList(podcast)
episodes = '\n '.join(episodes)
self._pager("""
Title: %(title)s
URL: %(url)s
Feed update is %(status)s
Feed Order: %(strategy)s
Episodes:
%(episodes)s
Expand Down Expand Up @@ -564,10 +569,11 @@ class gPodderCli(object):
return True

def _format_podcast(self, podcast):
strategy = '' if podcast.download_strategy != podcast.STRATEGY_CHRONO else '(serial)'
if not podcast.pause_subscription:
return ' '.join(('#', ingreen(podcast.title)))
return ' '.join(('#', ingreen(podcast.title), strategy))

return ' '.join(('#', inred(podcast.title), '-', _('Subscription suspended')))
return ' '.join(('#', inred(podcast.title), strategy, '-', _('Subscription suspended')))

def list(self):
"""List all podcast subscriptions
Expand Down Expand Up @@ -931,10 +937,49 @@ class gPodderCli(object):
if not podcast.pause_subscription:
podcast.pause_subscription = True
podcast.save()
self._model.load_podcast(url)
self._error(_('Subscription suspended: %(url)s') % {'url': url})

return True

@FirstArgumentIsPodcastURL
def episodic(self, url):
"""Define a podcast as episodic (newest episodes first)
episodic http://example.net/podcast/latest.atom
Use {serial} to change podcast to oldest episodes first
"""
podcast = self._get_podcast(url)

if podcast is not None:
if podcast.download_strategy != podcast.STRATEGY_DEFAULT:
podcast.download_strategy = podcast.STRATEGY_DEFAULT
podcast.save()
podcast.update()
self._error(_('Podcast now set to episodic: %(url)s') % {'url': url})

return True

@FirstArgumentIsPodcastURL
def serial(self, url):
"""Define a podcast as serial (oldest episodes first)
serial http://example.net/podcast/latest.atom
Use {episodic} to change podcast to newest episodes first
"""
podcast = self._get_podcast(url)

if podcast is not None:
if podcast.download_strategy != podcast.STRATEGY_CHRONO:
podcast.download_strategy = podcast.STRATEGY_CHRONO
podcast.save()
podcast.update()
self._error(_('Podcast now set to serial: %(url)s') % {'url': url})

return True

@FirstArgumentIsPodcastURL
def enable(self, url):
"""Resume subscription of a given feed
Expand Down
16 changes: 11 additions & 5 deletions src/gpodder/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class PodcastChannel(PodcastModelFields, PodcastModelMixin):
UNICODE_TRANSLATE = {ord('ö'): 'o', ord('ä'): 'a', ord('ü'): 'u'}

# Enumerations for download strategy
STRATEGY_DEFAULT, STRATEGY_LATEST = list(range(2))
STRATEGY_DEFAULT, STRATEGY_LATEST, STRATEGY_CHRONO = list(range(3))

MAX_FOLDERNAME_LENGTH = 60
SECONDS_PER_WEEK = 7*24*60*60
Expand All @@ -507,7 +507,7 @@ def __init__(self, model):
if self.id:
self._children = sorted(self.db.load_episodes(self, self),
key=lambda e: (e.published, e.id),
reverse=True)
reverse=self.download_strategy != PodcastChannel.STRATEGY_CHRONO)
self._determine_common_prefix()

def one_line_description(self):
Expand Down Expand Up @@ -761,8 +761,11 @@ def _consume_custom_feed(self, custom_feed):
for episode in self.episodes:
self.model.core.cover_downloader.get_cover(self, download=True, episode=episode)

# Sort episodes by pubdate, descending
self.episodes.sort(key=lambda e: e.published, reverse=True)
self._order_episodes()

def _order_episodes(self):
# Sort episodes by pubdate, descending if default, ascending if chrono
self.episodes.sort(key=lambda e: e.published, reverse=self.download_strategy != PodcastChannel.STRATEGY_CHRONO)

def update(self):
if self._updating:
Expand All @@ -781,6 +784,9 @@ def update(self):
if self.save_dir:
self.model.core.cover_downloader.get_cover(self, download=True)

# Make sure episodes are in correct order
self._order_episodes()

self.save()

# Re-determine the common prefix for all episodes
Expand All @@ -798,7 +804,7 @@ def save(self):
if self.download_folder is None:
self.get_save_dir()

super().save(self.db.db)
super().save(self.db.db)

self.model._append_podcast(self)

Expand Down

0 comments on commit fb36b3d

Please sign in to comment.