Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support serial chrono order. #39

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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