Beispiel #1
0
def cmd_add(*args):
	"""add a new torrent to transmission
....$add url <torrent_url>
....$add base64 '<torrent_base64>'"""
	if len(args) != 2:
		return "Oops, wrong number of arguments, type $help for more"

	if args[0].lower() == 'url':
		TransmissionClient.add_uri(args[1])
		resp = 'Torrent added'
	elif args[0].lower() == 'base64':
		TransmissionClient.add(args[1])
		resp = 'Torrent added'
	else:
		return "'%s' is not a valid option, type $help for more" % args[0].lower()

	return resp
Beispiel #2
0
def cmd_queue(*args):
	'''manage item queue discovered from subscribed feeds  	
....$queue list
....$queue download <ids>|all
....$queue remove <ids>|all'''

	if len(args) not in [1,2]:
		return "Oops, wrong number of arguments, type $help for more"	

	resp = ''
	if len(args) == 1 and args[0].lower() == 'list':
		resp += 'ID  Published  Title\n'
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
		
		#when json loaded to dict, it's not sorted by key
		sorted_ids = [int(x) for x in dynamics['queue'].keys()]
		sorted_ids.sort()
		for k in sorted_ids:
			v = dynamics['queue'][str(k)]
			resp += "%s  %-s  %-s\n" %(k, v['published'], v['title'])
		
		return resp

	elif len(args) == 2 and args[0].lower() == 'download':
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
				
		if args[1].lower() == 'all':
			ids_to_dl = dynamics['queue'].keys()
		else:
			ids_to_dl = args[1].split(',')

		ids_downloading = []
		for _id in ids_to_dl:
			if dynamics['queue'].has_key(_id):
				TransmissionClient.add_uri(dynamics['queue'][_id]['torrent_uri'])
				ids_downloading.append(_id)
				del dynamics['queue'][_id]

		dynamics.sync()

		if ids_downloading:
			return "Started downloading item %s" % (','.join(sort_as_int(ids_downloading)))
		else:
			return "No download started"

	elif len(args) == 2 and args[0].lower() == 'remove':
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
				
		if args[1].lower() == 'all':
			ids_to_rm = dynamics['queue'].keys()
		else:
			ids_to_rm = args[1].split(',')

		ids_removed = []
		for _id in ids_to_rm:
			if dynamics['queue'].has_key(_id):
				ids_removed.append(_id)
				del dynamics['queue'][_id]

		dynamics.sync()

		if ids_removed:
			return "Removed item %s" % (','.join(sort_as_int(ids_removed)))
		else:
			return "No item removed"

	else:
		return "Oops, invalid arguments, type $help for more"