Maemo 5: Allow deleting of non-downloaded episodes
[gpodder.git] / src / gpodder / console.py
blobf8413a822ad390fa9cdffe1a8e0776a99ef770d9
1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import sys
22 import gpodder
24 from gpodder import sync
25 from gpodder.model import PodcastChannel
27 _ = gpodder.gettext
29 def synchronize_device(db, config):
30 device = sync.open_device(config)
31 if device is None:
32 print >>sys.stderr, _('No device configured.')
33 return False
35 def msg(s):
36 print >>sys.stderr, s
38 device.register('status', msg)
39 def callback_progress(index, count):
40 d = {'index': index, 'count': count}
41 msg(_('Synchronizing: %(index)s of %(count)s') % d)
42 device.register('progress', callback_progress)
44 if device.open():
45 channels = [c for c in PodcastChannel.load_from_db(db, \
46 config.download_dir) if c.sync_to_devices]
48 for channel in channels:
49 episodes = [e for e in channel.get_downloaded_episodes() \
50 if e.was_downloaded(and_exists=True)]
51 device.add_tracks(episodes)
53 db.commit()
54 device.close()
55 print >>sys.stderr, _('Device synchronized successfully.')
56 return True
57 else:
58 print >>sys.stderr, _('Error: Cannot open device!')
59 return False