Пример #1
0
def download_task(args):
	import lixian_download_tools
	download = lixian_download_tools.get_tool(args.tool)
	download_args = {'output': args.output,
	                 'output_dir': args.output_dir,
	                 'delete': args.delete,
	                 'resuming': args._args['continue'],
	                 'overwrite': args.overwrite,
	                 'mini_hash': args.mini_hash,
	                 'no_hash': not args.hash,
	                 'no_bt_dir': not args.bt_dir,
	                 'save_torrent_file': args.save_torrent_file,
	                 'colors': args.colors}
	client = XunleiClient(args.username, args.password, args.cookies)
	assert len(args) or args.input or args.all or args.category, 'Not enough arguments'
	query = lixian_query.build_query(client, args)
	query.query_once()

	def sleep(n):
		assert isinstance(n, (int, basestring)), repr(n)
		import time
		if isinstance(n, basestring):
			n, u = re.match(r'^(\d+)([smh])?$', n.lower()).groups()
			n = int(n) * {None: 1, 's': 1, 'm': 60, 'h': 3600}[u]
		time.sleep(n)

	if args.watch_present:
		assert not args.output, 'not supported with watch option yet'
		tasks = query.pull_completed()
		while True:
			if tasks:
				download_multiple_tasks(client, download, tasks, download_args)
			if not query.download_jobs:
				break
			if not tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			tasks = query.pull_completed()

	elif args.watch:
		assert not args.output, 'not supported with watch option yet'
		tasks = query.pull_completed()
		while True:
			if tasks:
				download_multiple_tasks(client, download, tasks, download_args)
			if (not query.download_jobs) and (not query.queries):
				break
			if not tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			query.query_search()
			tasks = query.pull_completed()

	else:
		tasks = query.peek_download_jobs()
		if args.output:
			assert len(tasks) == 1
			download_single_task(client, download, tasks[0], download_args)
		else:
			download_multiple_tasks(client, download, tasks, download_args)
Пример #2
0
def download_task(args):
	import lixian_download_tools
	download = lixian_download_tools.get_tool(args.tool)
	download_args = {'output': args.output,
	                 'output_dir': args.output_dir,
	                 'delete': args.delete,
	                 'resuming': args._args['continue'],
	                 'overwrite': args.overwrite,
	                 'mini_hash': args.mini_hash,
	                 'no_hash': not args.hash,
	                 'no_bt_dir': not args.bt_dir,
	                 'save_torrent_file': args.save_torrent_file,
	                 'colors': args.colors}
	client = create_client(args)
	assert len(args) or args.input or args.all or args.category, 'Not enough arguments'
	query = lixian_query.build_query(client, args)
	query.query_once()

	def sleep(n):
		assert isinstance(n, (int, basestring)), repr(n)
		import time
		if isinstance(n, basestring):
			n, u = re.match(r'^(\d+)([smh])?$', n.lower()).groups()
			n = int(n) * {None: 1, 's': 1, 'm': 60, 'h': 3600}[u]
		time.sleep(n)

	if args.watch_present:
		assert not args.output, 'not supported with watch option yet'
		tasks = query.pull_completed()
		while True:
			if tasks:
				download_multiple_tasks(client, download, tasks, download_args)
			if not query.download_jobs:
				break
			if not tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			tasks = query.pull_completed()

	elif args.watch:
		assert not args.output, 'not supported with watch option yet'
		tasks = query.pull_completed()
		while True:
			if tasks:
				download_multiple_tasks(client, download, tasks, download_args)
			if (not query.download_jobs) and (not query.queries):
				break
			if not tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			query.query_search()
			tasks = query.pull_completed()

	else:
		tasks = query.peek_download_jobs()
		if args.output:
			assert len(tasks) == 1
			download_single_task(client, download, tasks[0], download_args)
		else:
			download_multiple_tasks(client, download, tasks, download_args)
Пример #3
0
def download_task(args):
	assert len(args) or args.input or args.all or args.category, 'Not enough arguments'
	lixian_download_tools.get_tool(args.tool) # check tool
	download_args = {'tool': args.tool,
	                 'output': args.output,
	                 'output_dir': args.output_dir,
	                 'delete': args.delete,
	                 'resuming': args._args['continue'],
	                 'async': args._args['async'],
	                 'overwrite': args.overwrite,
	                 'mini_hash': args.mini_hash,
	                 'no_hash': not args.hash,
	                 'no_bt_dir': not args.bt_dir,
	                 'save_torrent_file': args.save_torrent_file,
	                 'node': args.node,
	                 'colors': args.colors}
	client = create_client(args)
	query = lixian_query.build_query(client, args)
	query.query_once()

	def sleep(n):
		assert isinstance(n, (int, basestring)), repr(n)
		import time
		if isinstance(n, basestring):
			n, u = re.match(r'^(\d+)([smh])?$', n.lower()).groups()
			n = int(n) * {None: 1, 's': 1, 'm': 60, 'h': 3600}[u]
		time.sleep(n)

	if args.watch_present:
		assert not args.output, 'not supported with watch option yet'
		tasks = query.pull_completed()
		while True:
			if tasks:
				download_multiple_tasks(client, tasks, download_args)
			if not query.download_jobs:
				break
			if not tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			tasks = query.pull_completed()

	elif args.watch:
		assert not args.output, 'not supported with watch option yet'
		old_tasks = []
		tasks = query.pull_completed()
		while True:
			new_tasks = []
			for nt in tasks:
				is_new = True
				for ot in old_tasks:
					if nt['id'] == ot['id']:
						is_new = False
						break
				if is_new:
					new_tasks.append(nt)

			if new_tasks:
				download_multiple_tasks(client, new_tasks, download_args)
			if (not query.download_jobs) and (not query.queries):
				break
			if not new_tasks:
				sleep(args.watch_interval)
			query.refresh_status()
			query.query_search()
			old_tasks = tasks
			tasks = query.pull_completed()

	else:
		tasks = query.peek_download_jobs()
		if args.output:
			assert len(tasks) == 1
			download_single_task(client, tasks[0], download_args)
		else:
			download_multiple_tasks(client, tasks, download_args)
Пример #4
0
def download_task(args):
    assert len(args) or args.input or args.all or args.category, "Not enough arguments"
    lixian_download_tools.get_tool(args.tool)  # check tool
    download_args = {
        "tool": args.tool,
        "output": args.output,
        "output_dir": args.output_dir,
        "delete": args.delete,
        "resuming": args._args["continue"],
        "overwrite": args.overwrite,
        "mini_hash": args.mini_hash,
        "no_hash": not args.hash,
        "no_bt_dir": not args.bt_dir,
        "save_torrent_file": args.save_torrent_file,
        "colors": args.colors,
    }
    client = create_client(args)
    query = lixian_query.build_query(client, args)
    query.query_once()

    def sleep(n):
        assert isinstance(n, (int, basestring)), repr(n)
        import time

        if isinstance(n, basestring):
            n, u = re.match(r"^(\d+)([smh])?$", n.lower()).groups()
            n = int(n) * {None: 1, "s": 1, "m": 60, "h": 3600}[u]
        time.sleep(n)

    if args.watch_present:
        assert not args.output, "not supported with watch option yet"
        tasks = query.pull_completed()
        while True:
            if tasks:
                download_multiple_tasks(client, tasks, download_args)
            if not query.download_jobs:
                break
            if not tasks:
                sleep(args.watch_interval)
            query.refresh_status()
            tasks = query.pull_completed()

    elif args.watch:
        assert not args.output, "not supported with watch option yet"
        tasks = query.pull_completed()
        while True:
            if tasks:
                download_multiple_tasks(client, tasks, download_args)
            if (not query.download_jobs) and (not query.queries):
                break
            if not tasks:
                sleep(args.watch_interval)
            query.refresh_status()
            query.query_search()
            tasks = query.pull_completed()

    else:
        tasks = query.peek_download_jobs()
        if args.output:
            assert len(tasks) == 1
            download_single_task(client, tasks[0], download_args)
        else:
            download_multiple_tasks(client, tasks, download_args)