def list_torrent(args): ''' usage: lx list-torrent [--size] xxx.torrent... ''' args = parse_command_line(args, [], ['size'], default={'size':get_config('size')}) torrents = args if not torrents: from glob import glob torrents = glob('*.torrent') if not torrents: raise Exception('No .torrent file found') for p in torrents: with open(p, 'rb') as stream: from lixian_hash_bt import bdecode b = bdecode(stream.read()) encoding = b_encoding(b) info = b['info'] print '*', b_name(info, encoding).encode(default_encoding) if 'files' in info: for f in info['files']: if f['path'][0].startswith('_____padding_file_'): continue path = '/'.join(b_path(f, encoding)).encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(f['length'])) else: print path else: path = b_name(info, encoding).encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(info['length'])) else: print path
def list_torrent(args): ''' usage: lx list-torrent [--size] xxx.torrent... ''' args = parse_command_line(args, [], ['size']) for p in args: with open(p, 'rb') as stream: from lixian_hash_bt import bdecode info = bdecode(stream.read())['info'] print '*', info['name'].decode('utf-8').encode(default_encoding) if 'files' in info: for f in info['files']: if f['path'][0].startswith('_____padding_file_'): continue path = '/'.join( f['path']).decode('utf-8').encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(f['length'])) else: print path else: path = info['name'].decode('utf-8').encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(info['length'])) else: print path
def list_torrent(args): ''' usage: lx list-torrent [--size] xxx.torrent... ''' args = parse_command_line(args, [], ['size']) for p in args: with open(p, 'rb') as stream: from lixian_hash_bt import bdecode info = bdecode(stream.read())['info'] print '*', info['name'].decode('utf-8').encode(default_encoding) if 'files' in info: for f in info['files']: if f['path'][0].startswith('_____padding_file_'): continue path = '/'.join(f['path']).decode('utf-8').encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(f['length'])) else: print path else: path = info['name'].decode('utf-8').encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(info['length'])) else: print path
def output_tasks(tasks, columns, args, top=True): from lixian_colors import colors for i, t in enumerate(tasks): status_colors = { "waiting": "yellow", "downloading": "magenta", "completed": "green", "pending": "cyan", "failed": "red", } c = status_colors[t["status_text"]] with colors(args.colors).ansi(c)(): for k in columns: if k == "n": if top: print "#%d" % t["#"], elif k == "id": print t.get("index", t["id"]), elif k == "name": print t["name"].encode(default_encoding), elif k == "status": with colors(args.colors).bold(): print t["status_text"], elif k == "size": if args.format_size: from lixian_util import format_size print format_size(t["size"]), else: 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(k) print
def output_feedbackItems(tasks, top=True): # --name --no-id --size --status --progress --download-url --n # n: t['#'] # name: t['name'].encode(default_encoding) # size: from lixian_util import format_size # format_size(t['size']) # progress: t['progress'] # download-url: t['xunlei_url'] items = [] for i, t in enumerate(tasks): # [Task_Name: progress] isBT = True if t['type'] == 'bt' else False seqNum = str(t['#'] if top else t.get('index', t['id'])) feedTitle = ' '.join([seqNum, t['name']]) subTitles = [format_size(t['size']), t['status_text'], t['progress']] feedsubTitle = ' '.join(str(subT) for subT in subTitles) d_url = t['xunlei_url'] items.append(alp_item(title=feedTitle, subtitle=feedsubTitle, arg=(str(t['#']) + '/' if top and isBT else d_url), # autocomplete=(str(t['#']) + '/@' if top and isBT else ''), fileType = True if top and isBT else False, icon = 'org.bittorrent.torrent' if top and isBT else 'icon.png', valid=True)) if len(items): alp.feedback(items) else: alp.feedback(alp_item(title="没有找到", subtitle="修改[关键字],或使用 [ID]来检索", valid=False, fileIcon=True, icon="/System/Library/CoreServices/Problem Reporter.app"))
def output_tasks(tasks, columns, args, top=True): for i, t in enumerate(tasks): status_colors = { 'waiting': 'yellow', 'downloading': 'magenta', 'completed':'green', 'pending':'cyan', 'failed':'red', } c = status_colors[t['status_text']] with colors(args.colors).ansi(c)(): for k in columns: if k == 'n': if top: print '#%d' % t['#'], elif k == 'id': print t.get('index', t['id']), elif k == 'name': print t['name'].encode(default_encoding), elif k == 'status': with colors(args.colors).bold(): print t['status_text'], elif k == 'size': if args.format_size: from lixian_util import format_size print format_size(t['size']), else: 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(k) print return tasks
def output_tasks(tasks, columns, args, top=True): for i, t in enumerate(tasks): status_colors = { 'waiting': 'yellow', 'downloading': 'magenta', 'completed': 'green', 'pending': 'cyan', 'failed': 'red', } c = status_colors[t['status_text']] with colors(args.colors).ansi(c)(): for k in columns: if k == 'n': if top: print '#%d' % t['#'], elif k == 'id': print t.get('index', t['id']), elif k == 'name': print t['name'].encode(default_encoding), elif k == 'status': with colors(args.colors).bold(): print t['status_text'], elif k == 'size': if args.format_size: from lixian_util import format_size print format_size(t['size']), else: 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(k) print return tasks
def list_torrent(args): ''' usage: lx list-torrent [--size] xxx.torrent... ''' args = parse_command_line(args, [], ['size'], default={'size': get_config('size')}) torrents = args if not torrents: from glob import glob torrents = glob('*.torrent') if not torrents: raise Exception('No .torrent file found') for p in torrents: with open(p, 'rb') as stream: from lixian_hash_bt import bdecode b = bdecode(stream.read()) encoding = b_encoding(b) info = b['info'] from lixian_util import format_size if args.size: size = sum( f['length'] for f in info['files']) if 'files' in info else info['length'] print '*', b_name( info, encoding).encode(default_encoding), format_size(size) else: print '*', b_name(info, encoding).encode(default_encoding) if 'files' in info: for f in info['files']: if f['path'][0].startswith('_____padding_file_'): continue path = '/'.join(b_path(f, encoding)).encode(default_encoding) if args.size: print '%s (%s)' % (path, format_size(f['length'])) else: print path else: path = b_name(info, encoding).encode(default_encoding) if args.size: from lixian_util import format_size print '%s (%s)' % (path, format_size(info['length'])) else: print path
def list_torrent(args): args = parse_command_line(args, [], ['size']) for p in args: with open(p, 'rb') as stream: from lixian_hash_bt import bdecode info = bdecode(stream.read())['info'] print '*', info['name'].decode('utf-8') for f in info['files']: path = '/'.join(f['path']).decode('utf-8') if args.size: from lixian_util import format_size print u'%s (%s)' % (path, format_size(f['length'])) else: print path
def output_feedbackItems(tasks, top=True): # --name --no-id --size --status --progress --download-url --n # n: t['#'] # name: t['name'].encode(default_encoding) # size: from lixian_util import format_size # format_size(t['size']) # progress: t['progress'] # download-url: t['xunlei_url'] items = [] for i, t in enumerate(tasks): # [Task_Name: progress] isBT = True if t['type'] == 'bt' else False seqNum = str(t['#'] if top else t.get('index', t['id'])) feedTitle = ' '.join([seqNum, t['name']]) subTitles = [format_size(t['size']), t['status_text'], t['progress']] feedsubTitle = ' '.join(str(subT) for subT in subTitles) d_url = t['xunlei_url'] items.append( alp_item( title=feedTitle, subtitle=feedsubTitle, arg=(str(t['#']) + '/' if top and isBT else d_url), # autocomplete=(str(t['#']) + '/@' if top and isBT else ''), fileType=True if top and isBT else False, icon='org.bittorrent.torrent' if top and isBT else 'icon.png', valid=True)) if len(items): alp.feedback(items) else: alp.feedback( alp_item(title="没有找到", subtitle="修改[关键字],或使用 [ID]来检索", valid=False, fileIcon=True, icon="/System/Library/CoreServices/Problem Reporter.app"))
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', 'n', 'format-size' ], default={'id': True, 'name': True, 'status': True, 'n': get_config('n'), 'format-size': get_config('format-size')}, 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: args[0] = args[0][:-1] tasks = search_tasks(client, args, status=(args.completed and 'completed' or 'all')) 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=(args.completed and 'completed' or 'all')) elif args.completed: tasks = client.read_all_completed() else: tasks = client.read_all_tasks() columns = ['n', 'id', 'name', 'status', 'size', 'progress', 'speed', 'date', 'dcid', 'gcid', 'original-url', 'download-url'] columns = filter(lambda k: getattr(args, k), columns) for i, t in enumerate(tasks): for k in columns: if k == 'n': if not parent_ids: print '#%d' % t['#'], elif 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': if args.format_size: from lixian_util import format_size print format_size(t['size']), else: 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(k) print
def list_task(args): args = parse_login_command_line(args, [], [ 'all', 'completed', 'deleted', 'expired', 'id', 'name', 'status', 'size', 'dcid', 'gcid', 'original-url', 'download-url', 'speed', 'progress', 'date', 'n', 'format-size', 'colors' ], default={ 'id': get_config('id', True), 'name': True, 'status': True, 'n': get_config('n'), 'size': get_config('size'), 'format-size': get_config('format-size'), 'colors': get_config('colors', True) }, help=lixian_help.list) 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 status == 'all': tasks = client.read_all_tasks() elif status == 'completed': tasks = client.read_all_completed() 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) from lixian_colors import colors for i, t in enumerate(tasks): status_colors = { 'waiting': 'yellow', 'downloading': 'magenta', 'completed': 'green', 'pending': 'cyan', 'failed': 'red', } c = status_colors[t['status_text']] with colors(args.colors).ansi(c)(): for k in columns: if k == 'n': if not parent_ids: print '#%d' % t['#'], elif k == 'id': print t.get('index', t['id']), elif k == 'name': print t['name'].encode(default_encoding), elif k == 'status': with colors(args.colors).bold(): print t['status_text'], elif k == 'size': if args.format_size: from lixian_util import format_size print format_size(t['size']), else: 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(k) 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", "n", "format-size", ], default={ "id": True, "name": True, "status": True, "n": get_config("n"), "format-size": get_config("format-size"), }, 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: args[0] = args[0][:-1] tasks = search_tasks(client, args, status=(args.completed and "completed" or "all")) 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=(args.completed and "completed" or "all")) elif args.completed: tasks = client.read_all_completed() else: tasks = client.read_all_tasks() columns = [ "n", "id", "name", "status", "size", "progress", "speed", "date", "dcid", "gcid", "original-url", "download-url", ] columns = filter(lambda k: getattr(args, k), columns) for i, t in enumerate(tasks): for k in columns: if k == "n": if not parent_ids: print "#%d" % t["#"], elif 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": if args.format_size: from lixian_util import format_size print format_size(t["size"]), else: 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(k) print