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/>.
24 from gpodder
import sync
25 from gpodder
.model
import PodcastChannel
29 def synchronize_device(db
, config
):
30 device
= sync
.open_device(config
)
32 print >>sys
.stderr
, _('No device configured.')
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
)
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
)
55 print >>sys
.stderr
, _('Device synchronized successfully.')
58 print >>sys
.stderr
, _('Error: Cannot open device!')