Example #1
0
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:
			raise Exception('No files found')
		subs = [f for f in subs if f['size'] > 1000*1000] or subs # skip files with length < 1M
		if single_file:
			urls.append((subs[0]['xunlei_url'], subs[0]['name'], None))
		else:
			for f in subs:
				urls.append((f['xunlei_url'], f['name'], task['name']))
	else:
		urls.append((task['xunlei_url'], task['name'], None))
	url, filename, dirname = urls[0]
	name = dirname + '/' + filename if dirname else filename
	test_file(client, url, name, args)
Example #2
0
def export_aria2_conf(args):
    client = create_client(args)
    import lixian_query

    tasks = lixian_query.search_tasks(client, 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))
            else:
                for f in subs:
                    files.append((f['xunlei_url'], f['name'], task['name']))
        else:
            files.append((task['xunlei_url'], task['name'], None))
    output = ''
    for url, name, dir in files:
        if type(url) == unicode:
            url = url.encode(default_encoding)
        output += url + '\n'
        output += '  out=' + name.encode(default_encoding) + '\n'
        if dir:
            output += '  dir=' + dir.encode(default_encoding) + '\n'
        output += '  header=Cookie: gdriveid=' + client.get_gdriveid() + '\n'
    return output
Example #3
0
def get_torrent(args):
	'''
	usage: lx get-torrent [info-hash|task-id]...
	'''
	client = create_client(args)
	for id in args:
		id = id.lower()
		import re
		if re.match(r'[a-fA-F0-9]{40}$', id):
			torrent = client.get_torrent_file_by_info_hash(id)
		elif re.match(r'\d+$', id):
			import lixian_query
			task = lixian_query.get_task_by_id(client, id)
			id = task['bt_hash']
			id = id.lower()
			torrent = client.get_torrent_file_by_info_hash(id)
		else:
			raise NotImplementedError()
		if args.rename:
			import lixian_hash_bt
			from lixian_encoding import default_encoding
			info = lixian_hash_bt.bdecode(torrent)['info']
			name = info['name'].decode(info.get('encoding', 'utf-8')).encode(default_encoding)
			import re
			name = re.sub(r'[\\/:*?"<>|]', '-', name)
		else:
			name = id
		path = name + '.torrent'
		print path
		with open(path, 'wb') as output:
			output.write(torrent)
Example #4
0
def export_aria2_conf(args):
	client = create_client(args)
	import lixian_query
	tasks = lixian_query.search_tasks(client, 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))
			else:
				for f in subs:
					files.append((f['xunlei_url'], f['name'], task['name']))
		else:
			files.append((task['xunlei_url'], task['name'], None))
	output = ''
	for url, name, dir in files:
		if type(url) == unicode:
			url = url.encode(default_encoding)
		output += url + '\n'
		output += '  out=' + name.encode(default_encoding) + '\n'
		if dir:
			output += '  dir=' + dir.encode(default_encoding) + '\n'
		output += '  header=Cookie: gdriveid=' + client.get_gdriveid() + '\n'
	return output
Example #5
0
def get_torrent(args):
    '''
	usage: lx get-torrent [info-hash|task-id]...
	'''
    client = create_client(args)
    for id in args:
        id = id.lower()
        import re
        if re.match(r'[a-fA-F0-9]{40}$', id):
            torrent = client.get_torrent_file_by_info_hash(id)
        elif re.match(r'\d+$', id):
            import lixian_query
            task = lixian_query.get_task_by_id(client, id)
            id = task['bt_hash']
            id = id.lower()
            torrent = client.get_torrent_file_by_info_hash(id)
        else:
            raise NotImplementedError()
        if args.rename:
            import lixian_hash_bt
            from lixian_encoding import default_encoding
            info = lixian_hash_bt.bdecode(torrent)['info']
            name = info['name'].decode(info.get(
                'encoding', 'utf-8')).encode(default_encoding)
            import re
            name = re.sub(r'[\\/:*?"<>|]', '-', name)
        else:
            name = id
        path = name + '.torrent'
        print path
        with open(path, 'wb') as output:
            output.write(torrent)
Example #6
0
def execute_download_aria2rpc(args):
    client = create_client(args)
    task_list = get_download_task_info(args, client)
    # print(export_download_task_info(task_list, client))

    for url, name, dir in task_list:
        if type(url) == unicode:
            url = url.encode(default_encoding)
        if dir:
            dir = dir.encode(default_encoding)

        jsonreq = json.dumps({
            "jsonrpc":
            "2.0",
            "id":
            "qwer",
            "method":
            "aria2.addUri",
            "params": [[url], {
                "out":
                name.encode(default_encoding),
                "continue":
                "true",
                "header": ['Cookie: gdriveid=%s' % client.get_gdriveid()]
            }]
        })
        # print(jsonreq)
        host = '127.0.0.1'
        if args.dev is True:
            host = '192.168.0.2'

        print("Add to aria2c server:%s" % host)
        c = urllib2.urlopen("http://%s:6800/jsonrpc" % host, jsonreq)
        # {u'jsonrpc': u'2.0', u'id': u'qwer', u'result': u'f1257fa333f235e6'}
        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))
Example #7
0
def get_torrent(args):
	'''
	usage: lx get-torrent [info-hash|task-id]...
	'''
	client = create_client(args)
	for id in args:
		id = id.lower()
		import re
		if re.match(r'[a-fA-F0-9]{40}$', id):
			torrent = client.get_torrent_file_by_info_hash(id)
		elif re.match(r'\d+$', id):
			import lixian_query
			task = lixian_query.get_task_by_id(client, id)
			id = task['bt_hash']
			id = id.lower()
			torrent = client.get_torrent_file_by_info_hash(id)
		else:
			raise NotImplementedError()
		path = id + '.torrent'
		print path
		with open(path, 'wb') as output:
			output.write(torrent)
Example #8
0
def get_torrent(args):
    '''
	usage: lx get-torrent [info-hash|task-id]...
	'''
    client = create_client(args)
    for id in args:
        id = id.lower()
        import re
        if re.match(r'[a-fA-F0-9]{40}$', id):
            torrent = client.get_torrent_file_by_info_hash(id)
        elif re.match(r'\d+$', id):
            import lixian_query
            task = lixian_query.get_task_by_id(client, id)
            id = task['bt_hash']
            id = id.lower()
            torrent = client.get_torrent_file_by_info_hash(id)
        else:
            raise NotImplementedError()
        path = id + '.torrent'
        print path
        with open(path, 'wb') as output:
            output.write(torrent)
def export_download_urls(args):
	'''
	usage: lx export-download-urls [id|name]...
	'''
	assert len(args) or args.all or args.category, 'Not enough arguments'
	client = create_client(args)
	import lixian_query
	tasks = lixian_query.search_tasks(client, args)
	urls = []
	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:
				urls.append((subs[0]['xunlei_url'], subs[0]['name'], None))
			else:
				for f in subs:
					urls.append((f['xunlei_url'], f['name'], task['name']))
		else:
			urls.append((task['xunlei_url'], task['name'], None))
	for url, _, _ in urls:
		print url
def export_download_urls(args):
    '''
	usage: lx export-download-urls [id|name]...
	'''
    assert len(args) or args.all or args.category, 'Not enough arguments'
    client = create_client(args)
    import lixian_query
    tasks = lixian_query.search_tasks(client, args)
    urls = []
    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:
                urls.append((subs[0]['xunlei_url'], subs[0]['name'], None))
            else:
                for f in subs:
                    urls.append((f['xunlei_url'], f['name'], task['name']))
        else:
            urls.append((task['xunlei_url'], task['name'], None))
    for url, _, _ in urls:
        print url
def export_download_urls(args):
    """
    usage: lx export-download-urls [id|name]...
    """
    assert len(args) or args.all or args.category, "Not enough arguments"
    client = create_client(args)
    import lixian_query

    tasks = lixian_query.search_tasks(client, args)
    urls = []
    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:
                urls.append((subs[0]["xunlei_url"], subs[0]["name"], None))
            else:
                for f in subs:
                    urls.append((f["xunlei_url"], f["name"], task["name"]))
        else:
            urls.append((task["xunlei_url"], task["name"], None))
    for url, _, _ in urls:
        print url
Example #12
0
def execute_download_aria2rpc(args):
    client = create_client(args)
    task_list = get_download_task_info(args, client)
    # print(export_download_task_info(task_list, client))

    for url, name, dir in task_list:
        if type(url) == unicode:
            url = url.encode(default_encoding)
        if dir:
            dir = dir.encode(default_encoding)

        jsonreq = json.dumps({"jsonrpc": "2.0", "id": "qwer",
                              "method": "aria2.addUri",
                              "params": [
                                         [url],
                                         {
                                             "out": name.encode(default_encoding),
                                             "continue": "true",
                                             "header": ['Cookie: gdriveid=%s' % client.get_gdriveid()]
                                         }
                              ]
                              })
        # print(jsonreq)
        host = '127.0.0.1'
        if args.dev is True:
            host = '192.168.0.2'

        print("Add to aria2c server:%s" % host)
        c = urllib2.urlopen("http://%s:6800/jsonrpc" % host, jsonreq)
        # {u'jsonrpc': u'2.0', u'id': u'qwer', u'result': u'f1257fa333f235e6'}
        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))
Example #13
0
def get_vod_torrents(args):
    '''
    usage: lx get-vod-torrents [folder]...
    '''
    client = create_client(args)
    client.download_torrents_from_vod(0, args[0] if len(args) != 0 else '.\\vod')