def login(args): if args.cookies == '-': args._args['cookies'] = None if len(args) < 1: args.username = args.username or XunleiClient(cookie_path=args.cookies, login=False).get_username() or get_config( 'username') or raw_input('ID: ') args.password = args.password or get_config('password') or getpass('Password: '******'username') args.password = args[0] if args.password == '-': args.password = getpass('Password: '******'-': args.password = getpass('Password: '******'-': args.password = getpass('Password: '******'Too many arguments') if not args.username: raise RuntimeError("What's your name?") if args.cookies: print 'Saving login session to', args.cookies else: print 'Testing login without saving session' import lixian_verification_code verification_code_reader = lixian_verification_code.default_verification_code_reader(args) XunleiClient(args.username, args.password, args.cookies, login=True, verification_code_reader=verification_code_reader)
def login(self, username=None, password=None): username = self.username password = self.password if not username and self.has_cookie('.xunlei.com', 'usernewno'): username = self.get_username() if not username: # TODO: don't depend on lixian_config import lixian_config username = lixian_config.get_config('username') # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError('user is not logged in') logger.debug('login') cachetime = current_timestamp() check_url = 'http://login.xunlei.com/check?u=%s&cachetime=%d' % (username, cachetime) login_page = self.urlopen(check_url).read() verification_code = self.get_cookie('.xunlei.com', 'check_result')[2:].upper() if not verification_code: verification_code = self.read_verification_code() if verification_code: verification_code = verification_code.upper() assert verification_code password = encypt_password(password) password = md5(password+verification_code) login_page = self.urlopen('http://login.xunlei.com/sec2login/', data={'u': username, 'p': password, 'verifycode': verification_code}) self.id = self.get_userid() with self.attr(page_size=1): login_page = self.urlopen('http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0'%current_timestamp()).read() if not self.is_login_ok(login_page): logger.trace(login_page) raise RuntimeError('login failed') self.save_cookies() self.login_time = time.time()
def __init__(self, username=None, password=None, cookie_path=None, login=True): self.cookie_path = cookie_path if cookie_path: self.cookiejar = cookielib.LWPCookieJar() if os.path.exists(cookie_path): self.load_cookies() else: self.cookiejar = cookielib.CookieJar() self.set_page_size(9999) self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar)) if login: if not self.has_logged_in(): if not username and self.has_cookie(".xunlei.com", "usernewno"): username = self.get_username() if not username: import lixian_config username = lixian_config.get_config("username") # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError("user is not logged in") self.login(username, password) else: self.id = self.get_userid()
def login(self, username=None, password=None): username = self.username password = self.password if not username and self.has_cookie('.xunlei.com', 'usernewno'): username = self.get_username() if not username: # TODO: don't depend on lixian_config import lixian_config username = lixian_config.get_config('username') # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError('user is not logged in') logger.debug('login') self.check_device_id() cachetime = current_timestamp() #check_url = 'http://login.xunlei.com/check/?u=%s&business_type=108&v=101&cachetime=%d&' % (username, cachetime) #login_page = self.urlopen(check_url).read() verification_code = self.get_cookie('.xunlei.com', 'check_result')[2:].upper() if not verification_code: verification_code = self.read_verification_code() if verification_code: verification_code = verification_code.upper() assert verification_code login_page = self.urlopen('https://login3.xunlei.com/sec2login/', headers={'User-Agent': USER_AGENT}, data={'u': username, 'p': password, 'verifycode': verification_code, 'login_enable': '0', 'business_type': '108', 'v': '101'}) self.id = self.get_userid() with self.attr(page_size=1): login_page = self.urlopen('http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0'%current_timestamp(), headers={ 'User-Agent': USER_AGENT}).read() #login_page = self.urlopen('http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0'%current_timestamp()).read() if not self.is_login_ok(login_page): logger.trace(login_page) raise RuntimeError('login failed') self.save_cookies() self.login_time = time.time()
def __init__(self, username=None, password=None, cookie_path=None, login=True): self.cookie_path = cookie_path if cookie_path: self.cookiejar = cookielib.LWPCookieJar() if os.path.exists(cookie_path): self.load_cookies() else: self.cookiejar = cookielib.CookieJar() self.set_page_size(self.page_size) self.opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(self.cookiejar)) if login: if not self.has_logged_in(): if not username and self.has_cookie('.xunlei.com', 'usernewno'): username = self.get_username() if not username: import lixian_config username = lixian_config.get_config('username') # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError('user is not logged in') self.login(username, password) else: self.id = self.get_userid()
def login(args): if args.cookies == '-': args._args['cookies'] = None if len(args) < 1: args.username = args.username or XunleiClient( cookie_path=args.cookies, login=False).get_username( ) or get_config('username') or raw_input('ID: ') args.password = args.password or get_config('password') or getpass( 'Password: '******'username') args.password = args[0] if args.password == '-': args.password = getpass('Password: '******'-': args.password = getpass('Password: '******'-': args.password = getpass('Password: '******'Too many arguments') if not args.username: raise RuntimeError("What's your name?") if args.cookies: print 'Saving login session to', args.cookies else: print 'Testing login without saving session' import lixian_verification_code args.verification_code_path = "/Users/haidong.tang/Code/xunlei-lixian/a" verification_code_reader = lixian_verification_code.default_verification_code_reader( args) assert verification_code_reader != None XunleiClient(args.username, args.password, args.cookies, login=True, verification_code_reader=verification_code_reader)
def add_task(args): assert len(args) or args.input client = create_client(args) tasks = lixian_query.find_tasks_to_download(client, args) print 'All tasks added. Checking status...' columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') return output_tasks(tasks, columns, args)
def add_task(args): assert len(args) or args.input client = XunleiClient(args.username, args.password, args.cookies) tasks = lixian_query.find_tasks_to_download(client, args) print 'All tasks added. Checking status...' columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') output_tasks(tasks, columns, args)
def add_task(args): assert len(args) or args.input client = create_client(args) tasks = lixian_query.find_tasks_to_download(client, args) print 'All tasks added. Checking status...' columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') output_tasks(tasks, columns, args)
def login(self, username=None, password=None): username = self.username password = self.password if not username and self.has_cookie('.xunlei.com', 'usernewno'): username = self.get_username() if not username: # TODO: don't depend on lixian_config import lixian_config username = lixian_config.get_config('username') # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError('user is not logged in') logger.debug('login') self.check_device_id() cachetime = current_timestamp() check_url = 'http://login.xunlei.com/check/?u=%s&business_type=108&v=101&cachetime=%d&' % ( username, cachetime) login_page = self.urlopen(check_url).read() verification_code = self.get_cookie('.xunlei.com', 'check_result')[2:].upper() if not verification_code: verification_code = self.read_verification_code() if verification_code: verification_code = verification_code.upper() assert verification_code login_page = self.urlopen('https://login3.xunlei.com/sec2login/', headers={'User-Agent': USER_AGENT}, data={ 'u': username, 'p': password, 'verifycode': verification_code, 'login_enable': '0', 'business_type': '108', 'v': '101' }) self.id = self.get_userid() with self.attr(page_size=1): login_page = self.urlopen( 'http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0' % current_timestamp(), headers={ 'User-Agent': USER_AGENT }).read() #login_page = self.urlopen('http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0'%current_timestamp()).read() if not self.is_login_ok(login_page): logger.trace(login_page) raise RuntimeError('login failed') self.save_cookies() self.login_time = time.time()
def login(self, username=None, password=None): username = self.username password = self.password if not username and self.has_cookie(".xunlei.com", "usernewno"): username = self.get_username() if not username: # TODO: don't depend on lixian_config import lixian_config username = lixian_config.get_config("username") # if not username: # raise NotImplementedError('user is not logged in') if not password: raise NotImplementedError("user is not logged in") logger.debug("login") cachetime = current_timestamp() check_url = "http://login.xunlei.com/check?u=%s&cachetime=%d" % (username, cachetime) login_page = self.urlopen(check_url).read() verification_code = self.get_cookie(".xunlei.com", "check_result")[2:].upper() if not verification_code: if not self.verification_code_reader: raise NotImplementedError("Verification code required") else: verification_code_url = "http://verify2.xunlei.com/image?cachetime=%s" % current_timestamp() image = self.urlopen(verification_code_url).read() verification_code = self.verification_code_reader(image) if verification_code: verification_code = verification_code.upper() assert verification_code password = encypt_password(password) password = md5(password + verification_code) login_page = self.urlopen( "http://login.xunlei.com/sec2login/", data={"u": username, "p": password, "verifycode": verification_code} ) self.id = self.get_userid() self.set_page_size(1) login_page = self.urlopen( "http://dynamic.lixian.vip.xunlei.com/login?cachetime=%d&from=0" % current_timestamp() ).read() self.set_page_size(self.page_size) if not self.is_login_ok(login_page): logger.trace(login_page) raise RuntimeError("login failed") self.save_cookies()
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): ''' 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
__all__ = ['parse_login', 'parse_colors', 'parse_logging', 'parse_size', 'create_client', 'output_tasks', 'usage'] from lixian_cli_parser import * from lixian_config import get_config from lixian_config import LIXIAN_DEFAULT_COOKIES from lixian_encoding import default_encoding, to_native from lixian_colors import colors from getpass import getpass import lixian_help @command_line_value('username', default=get_config('username')) @command_line_value('password', default=get_config('password')) @command_line_value('cookies', default=LIXIAN_DEFAULT_COOKIES) def parse_login(args): if args.password == '-': args.password = getpass('Password: '******'-': args._args['cookies'] = None return args @command_line_option('colors', default=get_config('colors', True)) def parse_colors(args): pass @command_line_value('log-level', default=get_config('log-level')) @command_line_value('log-path', default=get_config('log-path')) @command_line_option('debug') @command_line_option('trace') def parse_logging(args): path = args.log_path
from lixian_commands.util import * from lixian_cli_parser import * from lixian_config import get_config from lixian_encoding import default_encoding import lixian_help import lixian_query @command_line_parser(help=lixian_help.restart) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @command_line_option('i') @command_line_option('all') @command_line_value('limit', default=get_config('limit')) @command_line_value('page-size', default=get_config('page-size')) def restart_task(args): client = create_client(args) to_restart = lixian_query.search_tasks(client, args) print "Below files are going to be restarted:" for x in to_restart: print x['name'].encode(default_encoding) client.restart_tasks(to_restart)
from lixian_config import get_config import sys default_encoding = get_config('encoding', sys.getfilesystemencoding()) if default_encoding is None or default_encoding.lower() == 'ascii': default_encoding = 'utf-8' def to_native(s): if type(s) == unicode: return s.encode(default_encoding) else: return s def from_native(s): if type(s) == str: return s.decode(default_encoding) else: return s def try_native_to_utf_8(url): try: return url.decode(default_encoding).encode('utf-8') except: return url
from lixian_commands.util import * from lixian_cli_parser import * from lixian_config import get_config import lixian_help import lixian_query @command_line_parser(help=lixian_help.add) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @with_parser(parse_size) @command_line_value('limit', default=get_config('limit')) @command_line_value('page-size', default=get_config('page-size')) @command_line_value('input', alias='i') @command_line_option('torrent', alias='bt') def add_task(args): assert len(args) or args.input client = create_client(args) tasks = lixian_query.find_tasks_to_download(client, args) print 'All tasks added. Checking status...' columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') return output_tasks(tasks, columns, args)
from lixian_config import get_config import sys default_encoding = get_config('encoding', sys.getfilesystemencoding()) if default_encoding is None or default_encoding.lower() == 'ascii': default_encoding = 'utf-8'
from lixian_commands.util import * from lixian_cli_parser import * from lixian_config import get_config from lixian_encoding import default_encoding from lixian_colors import colors import lixian_help import lixian_query @command_line_parser(help=lixian_help.delete) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @command_line_option("i") @command_line_option("all") @command_line_value("limit", default=get_config("limit")) @command_line_value("page-size", default=get_config("page-size")) def delete_task(args): client = create_client(args) to_delete = lixian_query.search_tasks(client, args) if not to_delete: print "Nothing to delete" return with colors(args.colors).red.bold(): print "Below files are going to be deleted:" for x in to_delete: print x["name"].encode(default_encoding) if args.i: yes_or_no = raw_input("Are your sure to delete below files from Xunlei cloud? ") while yes_or_no.lower() not in ("y", "yes", "n", "no"): yes_or_no = raw_input("yes or no? ")
from lixian_config import get_config import lixian_help import lixian_query import re @command_line_parser(help=lixian_help.list) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @with_parser(parse_size) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) def list_task(args): 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")
def addarpc(args): ''' usage: python lixian_cli.py addarpc url python lixian_cli.py addarpc -i url.txt python lixian_cli.py addarpc --input=url.txt cat url | python lixian_cli.py addarpc -I python lixian_cli.py addarpc 1.torrent python lixian_cli.py addarpc torrent-info-hash python lixian_cli.py addarpc --bt http://xxx/xxx.torrent ''' assert len(args) or args.input or args.I client = create_client(args) referer = client.get_referer() tasks = lixian_query.find_tasks_to_download(client, args) print('\033[35mAll tasks added. Checking status...\033[0m') #jsonrpc = get_config('aria2jsonrpc') #if jsonrpc is None: # global DEFAULT_JSONRPC # jsonrpc = DEFAULT_JSONRPC host = DEFAULT_HOST if args.dev is True: host = DEV_HOST port = DEFAULT_PORT jsonrpc = SERVER_URI_FORMAT.format(host, port) print("\033[35mAria2c jsonrpc server:%s\033[0m" % jsonrpc) columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') output_tasks(tasks, columns, args) files = [] for task in tasks: if task['type'] == 'bt': subs, skipped, single_file = lixian_query.expand_bt_sub_tasks(task) if not subs: continue if single_file: files.append((subs[0]['xunlei_url'], subs[0]['name'], None, task['original_url'])) else: for f in subs: files.append((f['xunlei_url'], f['name'], task['name'], task['original_url'])) else: files.append( (task['xunlei_url'], task['name'], None, task['original_url'])) for url, name, dir, original_url in files: if type(url) == unicode: url = url.encode(default_encoding) if dir: dir = dir.encode(default_encoding) urls = [url] if original_url.startswith("http"): urls.append(original_url) jsonreq = json.dumps({ "jsonrpc": "2.0", "id": "qwer", "method": "aria2.addUri", "params": [ urls, { "out": name.encode(default_encoding), "continue": "true", "header": ['Cookie: gdriveid=%s' % client.get_gdriveid()], "referer": referer } ] }) c = urllib2.urlopen(jsonrpc, jsonreq) result = c.read() if result is None or result == "": print("\033[31mCann't add aria2 task %s\033[0m" % name) else: result = json.loads(result.decode(default_encoding)) print("\033[32mAdd aria2 task[id= %s ] %s\033[0m" % (result[u"result"], name))
from lixian_cli_parser import command_line_parser from lixian_cli_parser import with_parser from lixian_cli_parser import command_line_option, command_line_value from lixian_commands.util import parse_login, parse_colors, create_client from lixian_config import get_config from lixian_encoding import default_encoding from lixian_colors import colors import lixian_nodes @command(usage='test download speed from multiple vod nodes') @command_line_parser() @with_parser(parse_login) @with_parser(parse_colors) @command_line_value('vod-nodes', default=get_config('vod-nodes', lixian_nodes.VOD_RANGE)) def speed_test(args): ''' usage: lx speed_test [--vod-nodes=0-50] [id|name] ''' assert len(args) client = create_client(args) import lixian_query tasks = lixian_query.search_tasks(client, args) if not tasks: raise Exception('No task found') task = tasks[0] urls = [] if task['type'] == 'bt': subs, skipped, single_file = lixian_query.expand_bt_sub_tasks(task) if not subs:
from lixian_config import LIXIAN_DEFAULT_COOKIES from lixian_commands.util import * from lixian_util import format_size import lixian_help import lixian_query import alp from alp.item import Item as alp_item @command_line_parser(help=lixian_help.list) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) @command_line_value('username', default=get_config('username')) @command_line_value('password', default=get_config('password')) @command_line_value('cookies', default=LIXIAN_DEFAULT_COOKIES) def query_task(args):
import lixian_help import lixian_query import re @command_line_parser(help=lixian_help.list) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @with_parser(parse_size) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) def list_task(args): 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")
from lixian_config import get_config from lixian_config import LIXIAN_DEFAULT_COOKIES from lixian_commands.util import * from lixian_util import format_size import lixian_help import lixian_query import alp from alp.item import Item as alp_item @command_line_parser(help=lixian_help.list) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) @command_line_value('username', default=get_config('username')) @command_line_value('password', default=get_config('password')) @command_line_value('cookies', default=LIXIAN_DEFAULT_COOKIES) def query_task(args):
__all__ = [ 'parse_login', 'parse_colors', 'parse_logging', 'parse_size', 'create_client', 'output_tasks', 'usage' ] from lixian_cli_parser import * from lixian_config import get_config from lixian_config import LIXIAN_DEFAULT_COOKIES from lixian_encoding import default_encoding, to_native from lixian_colors import colors from getpass import getpass import lixian_help @command_line_value('username', default=get_config('username')) @command_line_value('password', default=get_config('password')) @command_line_value('cookies', default=LIXIAN_DEFAULT_COOKIES) def parse_login(args): if args.password == '-': args.password = getpass('Password: '******'-': args._args['cookies'] = None return args @command_line_option('colors', default=get_config('colors', True)) def parse_colors(args): pass @command_line_value('log-level', default=get_config('log-level'))
import lixian_help import lixian_query import re @command_line_parser(help=lixian_help.list) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @with_parser(parse_size) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('failed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_value('limit', default=get_config('limit')) @command_line_value('page-size', default=get_config('page-size')) @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) def list_task(args): parent_ids = [a[:-1] for a in args if re.match(r'^#?\d+/$', a)]
def addarpc(args): ''' usage: python lixian_cli.py addarpc url python lixian_cli.py addarpc -i url.txt python lixian_cli.py addarpc --input=url.txt cat url | python lixian_cli.py addarpc -I python lixian_cli.py addarpc 1.torrent python lixian_cli.py addarpc torrent-info-hash python lixian_cli.py addarpc --bt http://xxx/xxx.torrent ''' assert len(args) or args.input or args.I client = create_client(args) referer = client.get_referer() tasks = lixian_query.find_tasks_to_download(client, args) print('\033[35mAll tasks added. Checking status...\033[0m') #jsonrpc = get_config('aria2jsonrpc') #if jsonrpc is None: # global DEFAULT_JSONRPC # jsonrpc = DEFAULT_JSONRPC host = DEFAULT_HOST if args.dev is True: host = DEV_HOST port = DEFAULT_PORT jsonrpc = SERVER_URI_FORMAT.format(host, port) print("\033[35mAria2c jsonrpc server:%s\033[0m" % jsonrpc) columns = ['id', 'status', 'name'] if get_config('n'): columns.insert(0, 'n') if args.size: columns.append('size') output_tasks(tasks, columns, args) files = [] for task in tasks: if task['type'] == 'bt': subs, skipped, single_file = lixian_query.expand_bt_sub_tasks(task) if not subs: continue if single_file: files.append((subs[0]['xunlei_url'], subs[0]['name'], None, task['original_url'])) else: for f in subs: files.append((f['xunlei_url'], f['name'], task['name'], task['original_url'])) else: files.append((task['xunlei_url'], task['name'], None, task['original_url'])) for url, name, dir, original_url in files: if type(url) == unicode: url = url.encode(default_encoding) if dir: dir = dir.encode(default_encoding) urls = [url] if original_url.startswith("http"): urls.append(original_url) jsonreq = json.dumps({"jsonrpc": "2.0", "id": "qwer", "method": "aria2.addUri", "params": [ urls, { "out": name.encode(default_encoding), "continue": "true", "header": ['Cookie: gdriveid=%s' % client.get_gdriveid()], "referer":referer } ] }) c = urllib2.urlopen(jsonrpc, jsonreq) result = c.read() if result is None or result == "": print("\033[31mCann't add aria2 task %s\033[0m" % name) else: result = json.loads(result.decode(default_encoding)) print("\033[32mAdd aria2 task[id= %s ] %s\033[0m" % (result[u"result"], name))
import lixian_help import lixian_query import re @command_line_parser(help=lixian_help.list) @with_parser(parse_login) @with_parser(parse_colors) @with_parser(parse_logging) @with_parser(parse_size) @command_line_option('all', default=True) @command_line_option('completed') @command_line_option('deleted') @command_line_option('expired') @command_line_value('category') @command_line_value('limit', default=get_config('limit')) @command_line_value('page-size', default=get_config('page-size')) @command_line_option('id', default=get_config('id', True)) @command_line_option('name', default=True) @command_line_option('status', default=True) @command_line_option('dcid') @command_line_option('gcid') @command_line_option('original-url') @command_line_option('download-url') @command_line_option('speed') @command_line_option('progress') @command_line_option('date') @command_line_option('n', default=get_config('n')) def list_task(args): parent_ids = [a[:-1] for a in args if re.match(r'^#?\d+/$', a)]