def list_task(args): status = 'all' if args.completed: status = 'completed' elif args.deleted: status = 'deleted' elif args.expired: status = 'expired' parent_ids = [a[:-1] for a in args if re.match(r'^#?\d+/$', a)] if parent_ids and not all(re.match(r'^#?\d+/$', a) for a in args): raise NotImplementedError("Can't mix 'id/' with others") assert len(parent_ids) <= 1, "sub-tasks listing only supports single task id" ids = [a[:-1] if re.match(r'^#?\d+/$', a) else a for a in args] client = XunleiClient(args.username, args.password, args.cookies) if parent_ids: args[0] = args[0][:-1] tasks = search_tasks(client, args, status=status) assert len(tasks) == 1 tasks = client.list_bt(tasks[0]) #tasks = client.list_bt(client.get_task_by_id(parent_ids[0])) tasks.sort(key=lambda x: int(x['index'])) elif len(ids): tasks = search_tasks(client, args, status=status) elif args.category: tasks = client.read_all_tasks_by_category(from_native(args.category)) elif status == 'all': tasks = client.read_all_tasks() elif status == 'completed': tasks = filter(lambda x: x['status_text'] == 'completed', client.read_all_tasks()) # by #139 elif status == 'deleted': tasks = client.read_all_deleted() elif status == 'expired': tasks = client.read_all_expired() else: raise NotImplementedError(status) columns = ['n', 'id', 'name', 'status', 'size', 'progress', 'speed', 'date', 'dcid', 'gcid', 'original-url', 'download-url'] columns = filter(lambda k: getattr(args, k), columns) output_tasks(tasks, columns, args, not parent_ids)
def download_task(args): import lixian_download_tools download = lixian_download_tools.get_tool(args.tool) download_args = {'output':args.output, 'output_dir':args.output_dir, 'delete':args.delete, 'resuming':args._args['continue'], 'overwrite':args.overwrite, 'mini_hash':args.mini_hash, 'no_hash': not args.hash, 'no_bt_dir': not args.bt_dir, 'save_torrent_file':args.save_torrent_file} client = XunleiClient(args.username, args.password, args.cookies) links = None if len(args) or args.input: tasks = find_tasks_to_download(client, args) if args.output: assert len(tasks) == 1 download_single_task(client, download, tasks[0], download_args) else: download_multiple_tasks(client, download, tasks, download_args) elif args.all: tasks = client.read_all_tasks() download_multiple_tasks(client, download, tasks, download_args) elif args.category: tasks = client.read_all_tasks_by_category(from_native(args.category)) download_multiple_tasks(client, download, tasks, download_args) else: usage(doc=lixian_help.download, message='Not enough arguments')