Look for cover art in more places (bug 746)
[gpodder.git] / src / gpodder / console.py
blob4fd61ec60a5bc252d571e1683148e138aca13c6d
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 callback_progress = lambda i, n: msg(_('Synchronizing: %d of %d') % (i, n))
40 device.register('progress', callback_progress)
42 if device.open():
43 channels = [c for c in PodcastChannel.load_from_db(db, \
44 config.download_dir) if c.sync_to_devices]
46 for channel in channels:
47 episodes = [e for e in channel.get_downloaded_episodes() \
48 if e.was_downloaded(and_exists=True)]
49 device.add_tracks(episodes)
51 db.commit()
52 device.close()
53 print >>sys.stderr, _('Device synchronized successfully.')
54 return True
55 else:
56 print >>sys.stderr, _('Error: Cannot open device!')
57 return False