def list_task(args): args = parse_login_command_line(args, [], [ 'all', 'completed', 'id', 'name', 'status', 'size', 'dcid', 'original-url', 'download-url', 'speed', 'progress', 'search' ], default={ 'id': True, 'name': True, 'status': True }, help=lixian_help.list) 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: 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=(args.completed and 'completed' or 'all'), check=False) elif args.completed: tasks = client.read_all_completed() else: tasks = client.read_all_tasks() columns = [ 'id', 'name', 'status', 'size', 'progress', 'speed', 'dcid', 'original-url', 'download-url' ] columns = filter(lambda k: getattr(args, k), columns) for t in tasks: for k in columns: if k == 'id': print t.get('index', t['id']), elif k == 'name': print t['name'].encode(default_encoding), elif k == 'status': print t['status_text'], elif k == 'size': print t['size'], elif k == 'progress': print t['progress'], elif k == 'speed': print t['speed'], elif k == 'dcid': print t['dcid'], elif k == 'original-url': print t['original_url'], elif k == 'download-url': print t['xunlei_url'], else: raise NotImplementedError() print
def rename_task(args): if len(args) != 2 or not re.match(r'\d+$', args[0]): usage(lixian_help.rename, 'Incorrect arguments') sys.exit(1) client = XunleiClient(args.username, args.password, args.cookies) taskid, new_name = args task = client.get_task_by_id(taskid) client.rename_task(task, from_native(new_name))
def rename_task(args): args = parse_login_command_line(args, [], [], help=lixian_help.rename) if len(args) != 2 or not re.match(r"\d+$", args[0]): usage(lixian_help.rename, "Incorrect arguments") sys.exit(1) client = XunleiClient(args.username, args.password, args.cookies) taskid, new_name = args task = client.get_task_by_id(taskid) client.rename_task(task, from_native(new_name))
def list_task(args): args = parse_login_command_line(args, [], ['all', 'completed', 'id', 'name', 'status', 'size', 'dcid', 'gcid', 'original-url', 'download-url', 'speed', 'progress', 'date', 'search'], default={'id': True, 'name': True, 'status': True}, help=lixian_help.list) 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: 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=(args.completed and 'completed' or 'all'), check=False) elif args.completed: tasks = client.read_all_completed() else: tasks = client.read_all_tasks() columns = ['id', 'name', 'status', 'size', 'progress', 'speed', 'date', 'dcid', 'gcid', 'original-url', 'download-url'] columns = filter(lambda k: getattr(args, k), columns) for t in tasks: for k in columns: if k == 'id': print t.get('index', t['id']), elif k == 'name': print t['name'].encode(default_encoding), elif k == 'status': print t['status_text'], elif k == 'size': print t['size'], elif k == 'progress': print t['progress'], elif k == 'speed': print t['speed'], elif k == 'date': print t['date'], elif k == 'dcid': print t['dcid'], elif k == 'gcid': print t['gcid'], elif k == 'original-url': print t['original_url'], elif k == 'download-url': print t['xunlei_url'], else: raise NotImplementedError() print
def list_task(args): args = parse_login_command_line( args, [], [ "all", "completed", "id", "name", "status", "size", "dcid", "gcid", "original-url", "download-url", "speed", "progress", "date", "search", ], default={"id": True, "name": True, "status": True}, help=lixian_help.list, ) 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: 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=(args.completed and "completed" or "all"), check=False) elif args.completed: tasks = client.read_all_completed() else: tasks = client.read_all_tasks() columns = [ "id", "name", "status", "size", "progress", "speed", "date", "dcid", "gcid", "original-url", "download-url", ] columns = filter(lambda k: getattr(args, k), columns) for t in tasks: for k in columns: if k == "id": print t.get("index", t["id"]), elif k == "name": print t["name"].encode(default_encoding), elif k == "status": print t["status_text"], elif k == "size": print t["size"], elif k == "progress": print t["progress"], elif k == "speed": print t["speed"], elif k == "date": print t["date"], elif k == "dcid": print t["dcid"], elif k == "gcid": print t["gcid"], elif k == "original-url": print t["original_url"], elif k == "download-url": print t["xunlei_url"], else: raise NotImplementedError() print