Ejemplo n.º 1
0
 def download(self, progress_callback):
     task = download.DownloadTask(self)
     task.add_progress_callback(progress_callback)
     task.status = download.DownloadTask.QUEUED
     result = task.run()
     task.recycle()
     return result
Ejemplo n.º 2
0
    def download(self, callback=None):
        """Downloads the episode to a local file

        This will run the download in the same thread, so be sure
        to call this method from a worker thread in case you have
        a GUI running as a frontend."""
        task = download.DownloadTask(self._episode, self._manager._config)
        if callback is not None:
            task.add_progress_callback(callback)
        task.status = download.DownloadTask.QUEUED
        task.run()
Ejemplo n.º 3
0
    def qdownload(self,
                  config,
                  finished_callback=None,
                  progress_callback=None):
        # Avoid starting the same download twice
        if self.download_task is not None:
            return

        # Initialize the download task here, so that the
        # UI will be updated as soon as possible
        self._wrapper_manager.add_active_episode(self)
        self._qt_download_progress = 0.
        task = download.DownloadTask(self._episode, config)
        task.status = download.DownloadTask.QUEUED
        self.changed.emit()
        if progress_callback is not None:
            progress_callback(self.id)

        def t(self):
            def cb(progress):
                if progress > self._qt_download_progress + .01 or progress == 1:
                    self._qt_download_progress = progress
                    self.changed.emit()
                    if progress_callback is not None:
                        progress_callback(self.id)

            task.add_progress_callback(cb)
            task.run()
            task.recycle()
            task.removed_from_list()
            self.source_url_changed.emit()

            if progress_callback is not None:
                progress_callback(self.id)

            # Make sure the single channel is updated (main view)
            self._podcast.changed.emit()

            # Make sure that "All episodes", etc.. are updated
            if finished_callback is not None:
                finished_callback()

            self._wrapper_manager.remove_active_episode(self)

        util.run_in_background(lambda: t(self), True)