def synchronize_device(db, config): device = sync.open_device(config) if device is None: print >>sys.stderr, _('No device configured.') return False def msg(s): print >>sys.stderr, s device.register('status', msg) def callback_progress(index, count): d = {'index': index, 'count': count} msg(_('Synchronizing: %(index)s of %(count)s') % d) device.register('progress', callback_progress) if device.open(): channels = [c for c in PodcastChannel.load_from_db(db, \ config.download_dir) if c.sync_to_devices] for channel in channels: episodes = [e for e in channel.get_downloaded_episodes() \ if e.was_downloaded(and_exists=True)] device.add_tracks(episodes) db.commit() device.close() print >>sys.stderr, _('Device synchronized successfully.') return True else: print >>sys.stderr, _('Error: Cannot open device!') return False
def finish(self): """Persist changed data to the database file This has to be called from the API user after data-changing actions have been carried out. """ podcasts = PodcastChannel.load_from_db(self._db, self._config.download_dir) exporter = opml.Exporter(gpodder.subscription_file) exporter.write(podcasts) self._db.commit() return True
def get_podcast(self, url): """Get a specific podcast by URL Returns a podcast object for the URL or None if the podcast has not been subscribed to. """ url = util.normalize_feed_url(url) channel = PodcastChannel.load(self._db, url, create=False, download_dir=self._config.download_dir) if channel is None: return None else: return Podcast(channel, self)
def create_podcast(self, url, title=None): """Subscribe to a new podcast Add a subscription for "url", optionally renaming the podcast to "title" and return the resulting object. """ url = util.normalize_feed_url(url) podcast = PodcastChannel.load(self._db, url, create=True, \ max_episodes=self._config.max_episodes_per_feed, \ download_dir=self._config.download_dir, \ allow_empty_feeds=self._config.allow_empty_feeds) if podcast is not None: if title is not None: podcast.set_custom_title(title) podcast.save() return Podcast(podcast, self) return None
def get_new_episodes(self, channel: PodcastChannel, existing_guids: Mapping[str, PodcastEpisode]): all_seen_episodes = set() all_episodes = [] for episode in self.metadata.episodes: all_seen_episodes.add(episode.guid) if episode.guid in existing_guids: continue episode = channel.episode_factory({ "description_html": episode.description, "description": episode.description, "published": episode.date, "url": episode.audio_url, "guid": episode.guid, "title": episode.title, "total_time": episode.duration, "file_size": episode.filesize }) all_episodes.append(episode) return all_episodes, all_seen_episodes
def create_podcast(self, url, title=None): """Subscribe to a new podcast Add a subscription for "url", optionally renaming the podcast to "title" and return the resulting object. """ url = util.normalize_feed_url(url) podcast = PodcastChannel.load(self._db, url, create=True, \ max_episodes=self._config.max_episodes_per_feed, \ download_dir=self._config.download_dir, \ allow_empty_feeds=self._config.allow_empty_feeds, \ mimetype_prefs=self._config.mimetype_prefs) if podcast is not None: if title is not None: podcast.set_custom_title(title) podcast.save() return Podcast(podcast, self) return None
def synchronize_device(db, config): device = sync.open_device(config) if device is None: print >> sys.stderr, _('No device configured.') return False def msg(s): print >> sys.stderr, s device.register('status', msg) def callback_progress(index, count): d = {'index': index, 'count': count} msg(_('Synchronizing: %(index)s of %(count)s') % d) device.register('progress', callback_progress) if device.open(): channels = [c for c in PodcastChannel.load_from_db(db, \ config.download_dir) if c.sync_to_devices] for channel in channels: episodes = [e for e in channel.get_downloaded_episodes() \ if e.was_downloaded(and_exists=True)] device.add_tracks(episodes) if config.ipod_purge_old_episodes: device.purge() db.commit() device.close() print >> sys.stderr, _('Device synchronized successfully.') return True else: print >> sys.stderr, _('Error: Cannot open device!') return False
def get_podcasts(self): """Get a list of Podcast objects Returns all the subscribed podcasts from gPodder. """ return [Podcast(p, self) for p in PodcastChannel.load_from_db(self._db, self._config.download_dir)]
def fetch_channel(cls, channel: PodcastChannel, max_episodes=0): url = channel.authenticate_url(channel.url) return cls.handle_url(url, max_episodes)