gtkui.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:yt-browser 作者: juanfgs 项目源码 文件源码
def download_video_thread(self,video_id, filename, video_iter):
        def update_progress(progress):
            """ Depending on the download status update the dialog or notify the user """
            for item in self.download_queue_store:
                def get_status(status):
                    return {
                        'downloading' : 'Descargando',
                        'finished' : 'Terminado',
                        'converting' : 'Convirtiendo'
                    }[status]

                # This mumbo-jumbo exists because messing with the progress bar without using Glib.idle_add caused crashes with huge files.
                def update_progressbar(progress):
                    self.download_queue_store[video_iter][1] = get_status(progress['status'])
                    if 'total_bytes_estimate' in progress:
                        self.download_queue_store[video_iter][2] = progress['downloaded_bytes'] / progress['total_bytes_estimate'] * 100
                    else:
                        self.download_queue_store[video_iter][2] = progress['downloaded_bytes'] / progress['total_bytes'] * 100

                GLib.idle_add(update_progressbar, progress)

            if progress['status'] != 'downloading':
                    GLib.idle_add(self.finish_download)

        """ Spawn a new thread and download """
        def start_download():
            self.backend.video = video_id
            self.backend.filename = filename
            self.backend.download_callback = update_progress
            self.backend.download()

        self.download_thread = threading.Thread(target=start_download)
        self.download_thread.daemon = True
        self.download_thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号