예제 #1
0
def parse_login_command_line(args,
                             keys=[],
                             bools=[],
                             alias={},
                             default={},
                             help=None):
    common_keys = ['username', 'password', 'cookies']
    common_default = {
        'cookies': LIXIAN_DEFAULT_COOKIES,
        'username': get_config('username'),
        'password': get_config('password')
    }
    common_keys.extend(keys)
    common_default.update(default)
    args = parse_command_line(args,
                              common_keys,
                              bools,
                              alias,
                              common_default,
                              help=help)
    if args.password == '-':
        args.password = getpass('Password: '******'-':
        args._args['cookies'] = None
    return args
예제 #2
0
def lx_config(args):
    args = parse_command_line(args, [], ["print", "delete"], help=lixian_help.config)
    if args.delete:
        assert len(args) == 1
        delete_config(args[0])
    elif args["print"] or not len(args):
        if len(args):
            assert len(args) == 1
            print get_config(args[0])
        else:
            print "Loading", global_config.path, "...\n"
            print source_config()
            print global_config
    else:
        assert len(args) in (1, 2)
        if args[0] == "password":
            if len(args) == 1 or args[1] == "-":
                password = getpass("Password: "******"Saving password (encrypted) to", global_config.path
            put_config("password", encypt_password(password))
        else:
            print "Saving configuration to", global_config.path
            put_config(*args)
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
예제 #4
0
def lx_config(args):
    args = parse_command_line(args, [], ['print', 'delete'],
                              help=lixian_help.config)
    if args.delete:
        assert len(args) == 1
        delete_config(args[0])
    elif args['print'] or not len(args):
        if len(args):
            assert len(args) == 1
            print get_config(args[0])
        else:
            print 'Loading', global_config.path, '...\n'
            print source_config()
            print global_config
    else:
        assert len(args) in (1, 2)
        if args[0] == 'password':
            if len(args) == 1 or args[1] == '-':
                password = getpass('Password: '******'Saving password (encrypted) to', global_config.path
            put_config('password', encypt_password(password))
        else:
            print 'Saving configuration to', global_config.path
            put_config(*args)
예제 #5
0
def lx_config(args):
	args = parse_command_line(args, [], ['print', 'delete'], help=lixian_help.config)
	if args.delete:
		assert len(args) == 1
		delete_config(args[0])
	elif args['print'] or not len(args):
		if len(args):
			assert len(args) == 1
			print get_config(args[0])
		else:
			print 'Loading', global_config.path, '...\n'
			print source_config()
			print global_config
	else:
		assert len(args) in (1, 2)
		if args[0] == 'password':
			if len(args) == 1 or args[1] == '-':
				password = getpass('Password: '******'Saving password (encrypted) to', global_config.path
			put_config('password', encypt_password(password))
		else:
			print 'Saving configuration to', global_config.path
			put_config(*args)
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
예제 #7
0
def logout(args):
	args = parse_command_line(args, ['cookies'], default={'cookies': LIXIAN_DEFAULT_COOKIES}, help=lixian_help.logout)
	if len(args):
		raise RuntimeError('Too many arguments')
	print 'logging out from', args.cookies
	assert args.cookies
	client = XunleiClient(cookie_path=args.cookies, login=False)
	client.logout()
예제 #8
0
def logout(args):
	args = parse_command_line(args, ['cookies'], default={'cookies': LIXIAN_DEFAULT_COOKIES}, help=lixian_help.logout)
	if len(args):
		raise RuntimeError('Too many arguments')
	print 'logging out from', args.cookies
	assert args.cookies
	client = XunleiClient(cookie_path=args.cookies, login=False)
	client.logout()
예제 #9
0
def get_task_by_any(client, arg):
    import lixian_cli_parser
    tasks = search_tasks(client, lixian_cli_parser.parse_command_line([arg]))
    if not tasks:
        raise LookupError(arg)
    if len(tasks) > 1:
        raise LookupError('Too many results for ' + arg)
    return tasks[0]
예제 #10
0
def get_task_by_any(client, arg):
	import lixian_cli_parser
	tasks = search_tasks(client, lixian_cli_parser.parse_command_line([arg]))
	if not tasks:
		raise LookupError(arg)
	if len(tasks) > 1:
		raise LookupError('Too many results for ' + arg)
	return tasks[0]
예제 #11
0
def main(args):
    from lixian_cli_parser import parse_command_line
    args = parse_command_line(args, [], ['name'])
    for x in args:
        for v in kuai_links(x):
            if args.name:
                print v['name']
            else:
                print v['url']
예제 #12
0
def main(args):
	from lixian_cli_parser import parse_command_line
	args = parse_command_line(args, [], ['name'])
	for x in args:
		for v in kuai_links(x):
			if args.name:
				print v['name']
			else:
				print v['url']
예제 #13
0
def parse_login_command_line(args, keys=[], bools=[], alias={}, default={}, help=None):
	common_keys = ['username', 'password', 'cookies']
	common_default = {'cookies': LIXIAN_DEFAULT_COOKIES, 'username': get_config('username'), 'password': get_config('password')}
	common_keys.extend(keys)
	common_default.update(default)
	args = parse_command_line(args, common_keys, bools, alias, common_default, help=help)
	if args.password == '-':
		args.password = getpass('Password: '******'-':
		args._args['cookies'] = None
	return args
예제 #14
0
def extend_links(args):
	'''
	usage: lx extend-links http://kuai.xunlei.com/d/... http://www.verycd.com/topics/...
	
	parse and print links from pages
	
	lx extend-links urls...
	lx extend-links --name urls...
	'''
	args = parse_command_line(args, [], ['name'])
	import lixian_tasks_extended
	for x in (lixian_tasks_extended.extend_links if not args.name else lixian_tasks_extended.extend_links_name)(args):
		print x
def extend_links(args):
    '''
	usage: lx extend-links http://kuai.xunlei.com/d/... http://www.verycd.com/topics/...
	
	parse and print links from pages
	
	lx extend-links urls...
	lx extend-links --name urls...
	'''
    args = parse_command_line(args, [], ['name'])
    import lixian_tasks_extended
    for x in (lixian_tasks_extended.extend_links if not args.name else
              lixian_tasks_extended.extend_links_name)(args):
        print x
예제 #16
0
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
예제 #17
0
def parse_login_command_line(args, keys=[], bools=[], alias={}, default={}, help=None):
    common_keys = ["username", "password", "cookies"]
    common_default = {
        "cookies": LIXIAN_DEFAULT_COOKIES,
        "username": get_config("username"),
        "password": get_config("password"),
    }
    common_keys.extend(keys)
    common_default.update(default)
    args = parse_command_line(args, common_keys, bools, alias, common_default, help=help)
    if args.password == "-":
        args.password = getpass("Password: "******"-":
        args._args["cookies"] = None
    return args
예제 #18
0
def extend_links(args):
	'''
	usage: lx extend-links http://kuai.xunlei.com/d/... http://www.verycd.com/topics/...
	
	parse and print links from pages
	
	lx extend-links urls...
	lx extend-links --name urls...
	'''
	args = parse_command_line(args, [], ['name'])
	import lixian_tasks_extended
	if args.name:
		for x in lixian_tasks_extended.extend_links_name(args):
			print x.encode(default_encoding)
	else:
		for x in lixian_tasks_extended.extend_links(args):
			print x
예제 #19
0
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
예제 #20
0
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
예제 #21
0
def extend_links(args):
	'''
	usage: lx extend-links http://kuai.xunlei.com/d/... http://www.verycd.com/topics/...

	parse and print links from pages

	lx extend-links urls...
	lx extend-links --name urls...
	'''

	from lixian_cli_parser import parse_command_line
	from lixian_encoding import default_encoding

	args = parse_command_line(args, [], ['name'])
	import lixian_plugins.parsers
	if args.name:
		for x in lixian_plugins.parsers.extend_links_name(args):
			print x.encode(default_encoding)
	else:
		for x in lixian_plugins.parsers.extend_links(args):
			print x
예제 #22
0
def extend_links(args):
	args = parse_command_line(args, [], ['name'])
	import lixian_tasks_extended
	for x in (lixian_tasks_extended.extend_links if not args.name else lixian_tasks_extended.extend_links_name)(args):
		print x