Downloads: Chronological order config option (+add to CLI)

This commit is contained in:
Thomas Perl 2014-05-17 11:46:09 +02:00
parent f83e64e169
commit 14fad9d3ec
3 changed files with 27 additions and 10 deletions

23
bin/gpo
View File

@ -138,6 +138,7 @@ from gpodder import my
from gpodder import opml
from gpodder import util
from gpodder import youtube
from gpodder import model
from gpodder.config import config_value_to_string
def incolor(color_id, s):
@ -540,20 +541,26 @@ class gPodderCli(object):
@FirstArgumentIsPodcastURL
def download(self, url=None):
count = 0
episodes = []
for podcast in self._model.get_podcasts():
podcast_printed = False
if url is None or podcast.url == url:
for episode in podcast.get_all_episodes():
if self.is_episode_new(episode):
if not podcast_printed:
safe_print(inblue(podcast.title))
podcast_printed = True
self._download_episode(episode)
count += 1
episodes.append(episode)
if self._config.downloads.chronological_order:
# download older episodes first
episodes = list(model.Model.sort_episodes_by_pubdate(episodes))
last_podcast = None
for episode in episodes:
if episode.channel != last_podcast:
safe_print(inblue(episode.channel.title))
last_podcast = episode.channel
self._download_episode(episode)
util.delete_empty_folders(gpodder.downloads)
safe_print(count, 'episodes downloaded.')
safe_print(len(episodes), 'episodes downloaded.')
return True
@FirstArgumentIsPodcastURL

View File

@ -69,6 +69,11 @@ defaults = {
'episodes': 200, # max episodes per feed
},
# Behavior of downloads
'downloads': {
'chronological_order': True, # download older episodes first
},
# Automatic feed updates, download removal and retry on download timeout
'auto': {
'update': {

View File

@ -2469,8 +2469,9 @@ class gPodder(BuilderWidget, dbus.service.Object):
# updated, not in other podcasts (for single-feed updates)
episodes = self.get_new_episodes([c for c in updated_channels])
# download older episodes first
episodes = list(Model.sort_episodes_by_pubdate(episodes))
if self.config.downloads.chronological_order:
# download older episodes first
episodes = list(Model.sort_episodes_by_pubdate(episodes))
if not episodes:
# Nothing new here - but inform the user
@ -2769,6 +2770,10 @@ class gPodder(BuilderWidget, dbus.service.Object):
def download_episode_list(self, episodes, add_paused=False, force_start=False):
enable_update = False
if self.config.downloads.chronological_order:
# Download episodes in chronological order (older episodes first)
episodes = list(Model.sort_episodes_by_pubdate(episodes))
for episode in episodes:
logger.debug('Downloading episode: %s', episode.title)
if not episode.was_downloaded(and_exists=True):