diff --git a/bin/gpo b/bin/gpo index d8f4c92..d52486f 100755 --- a/bin/gpo +++ b/bin/gpo @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/src/gpodder/model.py b/src/gpodder/model.py index df3159d..46727b6 100644 --- a/src/gpodder/model.py +++ b/src/gpodder/model.py @@ -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 @@ -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): @@ -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: @@ -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 @@ -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)