download.py 文件源码

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

项目:film-spider 作者: huzecong 项目源码 文件源码
def start_download(self, dic):
        writeln('[' + color('DOWN', 'cyan') + '] Starting download of %s from %s, saving as ID %d'
                % (dic['name'], dic['url'], dic['id']))
        # cur_option = self.options
        # cur_option['progress_hooks'] = [partial(self.download_progress, dic['id'])]
        # cur_option['outtmpl'] = 'video/' + str(dic['id']) + '/' + str(dic['id']) + r'.%(title)s-%(id)s.%(ext)s'
        # downloader = youtube_dl.YoutubeDL(cur_option)
        # try:
        #     downloader.download([dic['url']])
        #     self.download_progress(dic['id'], {'status': 'complete'})
        # except youtube_dl.DownloadError as e:
        #     writeln('[' + color('ERROR', 'red') + '] youtube_dl error for %s: ' % dic['name'] + e.message)
        #     self.download_progress(dic['id'], {'status': 'error'})
        self.download_progress(dic['id'], {'status': 'downloading'})
        outpath = 'video/' + str(dic['id']) + '/'
        try:
            os.makedirs(outpath)
        except:
            pass
        log = open(outpath + 'log.txt', 'w')
        process = subprocess.Popen(["you-get", dic['url']], stdout=log, stderr=subprocess.STDOUT, cwd=outpath)
        retcode = process.wait()
        log.close()
        log = open(outpath + 'log.txt', 'r')
        if retcode != 0 or ' '.join(log.readlines()).find('error') != -1:
            self.download_progress(dic['id'], {'status': 'error'})
        else:
            self.download_progress(dic['id'], {'status': 'complete'})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号