def dl_process(dlm): colors = ['red', 'blue', 'yellow', 'white', 'cyan', 'green', 'magenta'] dlm.config(max_task=MAX_TASK) id_pbar = [] color_index = 0 for i, j in dlm.getAllTask().items(): if color_index == len(colors): color_index = 0 pbar = progressBar(i, j.file.size, color=colors[color_index]) id_pbar.append((i, pbar)) color_index += 1 dlm.run() while not dlm.isEnd(): cur_queue = dlm.getRunQueue() ids, pbars = zip(*id_pbar) for i in cur_queue: dl = dlm.getHandler(i) inc = dl.file.size - dl.getLeft() speed = round(dl.getInsSpeed() / 1024, 1) pbars[i].update(inc, '%6s kb/s' % speed) time.sleep(1)
def dl_process(dl_list): dl_tmp = dl_list[:] colors = ['red', 'blue', 'yellow', 'white', 'cyan', 'black', 'green', 'magenta'] running_list = [] while True: running_list = filter(lambda (x, y): x.isDone() is False, running_list) if len(running_list) <= MAX_TASK: cur_run_len = MAX_TASK - len(running_list) for i in dl_list[:cur_run_len]: isin = False for j in running_list: if i in j: isin = True break if isin is True: break i.start() sel_color = None for m in colors: for j, k in running_list: if k.color == m: break else: sel_color = m break if sel_color is None: sel_color = colors[0] pbar = ___progressbar.progressBar(dl_tmp.index(i), i.file.size, color=sel_color) running_list.append((i, pbar)) dl_list = dl_list[cur_run_len:] for i, j in running_list: left_size = i.file.size - i.getLeft() j.update(left_size, '%d kb/s' % int(i.getinsSpeed() / 1024)) time.sleep(1) if len(dl_list) == 0 and len(running_list) == 0: break
if __name__ == '__main__': from ___progressbar import progressBar _list = [] _bar = [] for index in range(3): _list.append(downloader()) _list[-1].config(file_name=str(index), thread_count=10, force=True) _list[-1].add_server( 'http://xiazai.xiazaiba.com/Soft/T/TIM_2.2.0_XiaZaiBa.zip') _list[-1].add_server( 'http://dblt.xiazaiba.com/Soft/T/TIM_2.2.0_XiaZaiBa.zip') a = _list[-1].open() a.start() _list[-1] = a _bar.append(progressBar(index, a.file.size)) while True: _end = True for i, j in enumerate(_list): if j.isDone() is False: _end = False _bar[i].update(j.file.size - j.getLeft(), str(int(j.getinsSpeed() / 1024)) + ' kb/s') time.sleep(0.5) if _end is True: break
def main(): save_config() load_config() # last_url = '' url = '' # print top print '[Ctrl + C] to copy the iqiyi video url, and go back to see this console.' while True: last_url = url url = catch_url(last_url) if last_url == url: continue videoname, _msg = iqiyi.parse(url, global_bids) if _msg: print '+---------------------------------------------------------------+' print '\033[0;37;41m' + videoname + '\033[0m' print '+---------------------------------------------------------------+' _count = 0 for i, j in _msg.items(): print '[%d]%9s - Total size: %4s mb - Add up %d parts' % ( _count, i, int(j['vsize']) * 1.0 / 1024 / 1024, len( j['fs'])) _count += 1 print '[-1] back.' index = int_select_input(0, _count) if index == -1: continue else: break else: continue if _msg: _count = 0 for i, j in _msg.items(): if index == _count: sel_msg = j break _count += 1 else: raise AttributeError names = make_filenames(videoname, sel_msg) if not os.path.exists(unicode(videoname)): os.mkdir(unicode(videoname)) dlm = build_dl(videoname, names, sel_msg) dl_process(dlm) merger_bar = progressBar(0, len(names), 30) name_paths = [] filepath = unicode(os.path.join(SAVE_PATH, unicode(videoname))) for i in names: name_paths.append(os.path.join(filepath, i)) mer = merger.merger( os.path.join(SAVE_PATH, unicode(videoname)) + u'.f4v', name_paths) mer.start() while True: merger_bar.update(mer.now) time.sleep(0.2) if mer.now == mer.sum: merger_bar.update(mer.now) break if DEL_AFTER: del_seg_video(name_paths, filepath) print 'OK!' while True: time.sleep(1)