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'})
评论列表
文章目录