def query_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): print parent_ids print 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 = create_client(args) if parent_ids: args[0] = args[0][:-1] tasks = lixian_query.search_tasks(client, args) assert len(tasks) == 1 tasks = client.list_bt(tasks[0]) tasks.sort(key=lambda x: int(x['index'])) else: tasks = lixian_query.search_tasks(client, args) if len(args) == 1 and re.match( r'\d+/', args[0]) and len(tasks) == 1 and 'files' in tasks[0]: parent_ids = [tasks[0]['id']] tasks = tasks[0]['files'] output_feedbackItems(tasks, not parent_ids)
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") 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 = create_client(args) if parent_ids: args[0] = args[0][:-1] tasks = lixian_query.search_tasks(client, args) 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'])) else: tasks = lixian_query.search_tasks(client, args) if len(args) == 1 and re.match( r'\d+/', args[0]) and len(tasks) == 1 and 'files' in tasks[0]: parent_ids = [tasks[0]['id']] tasks = tasks[0]['files'] columns = [ 'n', 'id', 'name', 'status', 'size', 'progress', 'speed', 'date', 'dcid', 'gcid', 'original-url', 'download-url' ] columns = filter(lambda k: getattr(args, k), columns) output_tasks(tasks, columns, args, not parent_ids)
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") 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 = create_client(args) if parent_ids: args[0] = args[0][:-1] tasks = lixian_query.search_tasks(client, args) 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'])) else: tasks = lixian_query.search_tasks(client, args) if len(args) == 1 and re.match(r'\d+/', args[0]) and len(tasks) == 1 and 'files' in tasks[0]: parent_ids = [tasks[0]['id']] tasks = tasks[0]['files'] columns = ['n', 'id', 'name', 'status', 'size', 'progress', 'speed', 'date', 'dcid', 'gcid', 'original-url', 'download-url'] columns = filter(lambda k: getattr(args, k), columns) output_tasks(tasks, columns, args, not parent_ids)
def pause_task(args): client = create_client(args) to_pause = lixian_query.search_tasks(client, args) print "Below files are going to be paused:" for x in to_pause: print x['name'].encode(default_encoding) client.pause_tasks(to_pause)
def readd_task(args): if args.deleted: status = 'deleted' elif args.expired: status = 'expired' else: raise NotImplementedError('Please use --expired or --deleted') client = XunleiClient(args.username, args.password, args.cookies) if status == 'expired' and args.all: return client.readd_all_expired_tasks() to_readd = lixian_query.search_tasks(client, args) non_bt = [] bt = [] if not to_readd: return print "Below files are going to be re-added:" for x in to_readd: print x['name'].encode(default_encoding) if x['type'] == 'bt': bt.append((x['bt_hash'], x['id'])) else: non_bt.append((x['original_url'], x['id'])) if non_bt: urls, ids = zip(*non_bt) client.add_batch_tasks(urls, ids) for hash, id in bt: client.add_torrent_task_by_info_hash2(hash, id)
def restart_task(args): client = XunleiClient(args.username, args.password, args.cookies) 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)
def readd_task(args): if args.deleted: status = "deleted" elif args.expired: status = "expired" else: raise NotImplementedError("Please use --expired or --deleted") client = create_client(args) if status == "expired" and args.all: return client.readd_all_expired_tasks() to_readd = lixian_query.search_tasks(client, args) non_bt = [] bt = [] if not to_readd: return print "Below files are going to be re-added:" for x in to_readd: print x["name"].encode(default_encoding) if x["type"] == "bt": bt.append((x["bt_hash"], x["id"])) else: non_bt.append((x["original_url"], x["id"])) if non_bt: urls, ids = zip(*non_bt) client.add_batch_tasks(urls, ids) for hash, id in bt: client.add_torrent_task_by_info_hash(hash, id)
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)
def pause_task(args): client = XunleiClient(args.username, args.password, args.cookies) to_pause = lixian_query.search_tasks(client, args) print "Below files are going to be paused:" for x in to_pause: print x['name'].encode(default_encoding) client.pause_tasks(to_pause)
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
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)
def export_aria2_conf(args): client = XunleiClient(args.username, args.password, args.cookies) 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: import os.path 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
def readd_task(args): if args.deleted: status = 'deleted' elif args.expired: status = 'expired' else: raise NotImplementedError('Please use --expired or --deleted') client = create_client(args) if status == 'expired' and args.all: return client.readd_all_expired_tasks() to_readd = lixian_query.search_tasks(client, args) non_bt = [] bt = [] if not to_readd: return print "Below files are going to be re-added:" for x in to_readd: print x['name'].encode(default_encoding) if x['type'] == 'bt': bt.append((x['bt_hash'], x['id'])) else: non_bt.append((x['original_url'], x['id'])) if non_bt: urls, ids = zip(*non_bt) client.add_batch_tasks(urls, ids) for hash, id in bt: client.add_torrent_task_by_info_hash(hash, id)
def query_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): print parent_ids print 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 = create_client(args) if parent_ids: args[0] = args[0][:-1] tasks = lixian_query.search_tasks(client, args) assert len(tasks) == 1 tasks = client.list_bt(tasks[0]) tasks.sort(key=lambda x: int(x['index'])) else: tasks = lixian_query.search_tasks(client, args) if len(args) == 1 and re.match(r'\d+/', args[0]) and len(tasks) == 1 and 'files' in tasks[0]: parent_ids = [tasks[0]['id']] tasks = tasks[0]['files'] output_feedbackItems(tasks, not parent_ids)
def get_download_task_info(args, client): 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)) return files
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? ") if yes_or_no.lower() in ("y", "yes"): pass elif yes_or_no.lower() in ("n", "no"): raise RuntimeError("Deletion abort per user request.") client.delete_tasks(to_delete)
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? ') if yes_or_no.lower() in ('y', 'yes'): pass elif yes_or_no.lower() in ('n', 'no'): raise RuntimeError('Deletion abort per user request.') client.delete_tasks(to_delete)
def delete_task(args): client = XunleiClient(args.username, args.password, args.cookies) 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? ') if yes_or_no.lower() in ('y', 'yes'): pass elif yes_or_no.lower() in ('n', 'no'): raise RuntimeError('Deletion abort per user request.') client.delete_tasks(to_delete)
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