def main(cfg, log): if cfg.playlist: for url in cfg.urls: outpath, cfg.urls = parsers.getPlayListParser(url).info(url) cfg.outpath = pjoin(cfg.outpath, outpath) util.assure_path(cfg.outpath) with open(pjoin(cfg.outpath, 'url.txt'), 'w') as fp: fp.writelines([url + "\n\n"]) for i, clip in enumerate(cfg.urls): fp.writelines(["[%03d] %s\n"%(i, clip)]) bar = ProgressBar() ws = WorkShop(tmin=cfg.tmin, tmax=cfg.tmax, log=log) dlvs = [] for i, url in enumerate(cfg.urls): dlvideo = VUrlTask(url, vidfmt=cfg.vidfmt, npf=cfg.npf, outpath=cfg.outpath, bar=bar, log=log) dlvs.append(dlvideo) try: ws.serve() ws.addTasks(dlvs) while len(dlvs) > 0: for i, dlv in enumerate(dlvs): if dlv.isArchived() or dlv.isError(): del dlvs[i] _sleep(1) except Exception as e: log.exception(e) finally: ws.setToStop() ws.join()
def main(cfg, log): if cfg.playlist: for url in cfg.urls: outpath, cfg.urls = parsers.getPlayListParser(url).info(url) cfg.outpath = pjoin(cfg.outpath, outpath) util.assure_path(cfg.outpath) with open(pjoin(cfg.outpath, 'url.txt'), 'w') as fp: fp.writelines([url + "\n\n"]) for i, clip in enumerate(cfg.urls): fp.writelines(["[%03d] %s\n" % (i, clip)]) bar = ProgressBar() ws = WorkShop(tmin=cfg.tmin, tmax=cfg.tmax, log=log) dlvs = [] for i, url in enumerate(cfg.urls): dlvideo = VUrlTask(url, vidfmt=cfg.vidfmt, npf=cfg.npf, outpath=cfg.outpath, bar=bar, log=log) dlvs.append(dlvideo) try: ws.serve() ws.addTasks(dlvs) while len(dlvs) > 0: for i, dlv in enumerate(dlvs): if dlv.isArchived() or dlv.isError(): del dlvs[i] _sleep(1) except Exception as e: log.exception(e) finally: ws.setToStop() ws.join()
def main(): urls = [ # 'http://v.youku.com/v_show/id_XNzUyNDE4MTQw.html' # 'http://i.youku.com/u/UNTc4NzI3MjY0', # 'http://v.youku.com/v_show/id_XNzQ5NDAwMDIw.html?from=y1.1-2.10001-0.1-1', # 'http://v.youku.com/v_show/id_XNzUwMTE2MDQw.html?f=22611771', # 'http://v.youku.com/v_show/id_XNzQ3MjMxMTYw.html', 'http://video.sina.com.cn/p/ent/v/m/2014-08-14/102164094039.html' ] log = util.get_logger() bar = ProgressBar() ws = WorkShop(tmin=1, tmax=2, log=log) dlvs = [] for i, url in enumerate(urls): dlvideo = VUrlTask(url, 0, 3, './tmp', bar=bar, log=log) dlvs.append(dlvideo) try: ws.serve() ws.addTasks(dlvs) while len(dlvs) > 0: for i, dlv in enumerate(dlvs): if dlv.isArchived() or dlv.isError(): del dlvs[i] _sleep(1) except KeyboardInterrupt: pass except Exception as e: log.exception(e) finally: ws.setToStop() ws.join()