Skip to content

Instantly share code, notes, and snippets.

@ianunruh
Created July 28, 2017 03:40
Show Gist options
  • Save ianunruh/2fc2f70fedbf836673623f4ddf27a8f8 to your computer and use it in GitHub Desktop.
Save ianunruh/2fc2f70fedbf836673623f4ddf27a8f8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from argparse import ArgumentParser
import json
import hashlib
import subprocess
import os
def main():
parser = ArgumentParser()
parser.add_argument('-u', '--username', default=os.environ.get('DELUGE_USERNAME', 'localclient'))
parser.add_argument('-p', '--password', default=os.environ.get('DELUGE_PASSWORD'))
parser.add_argument('-I', '--interface', default='tun0')
parser.add_argument('-b', '--base-url', default='http://209.222.18.222:2000')
parser.add_argument('-H', '--deluge-host', default='localhost')
parser.add_argument('-P', '--deluge-port', default=58846, type=int)
args = parser.parse_args()
client_id = hashlib.sha256(os.urandom(32)).hexdigest()
out = subprocess.check_output([
'curl',
'-s',
'--interface', args.interface,
'{}/?client_id={}'.format(args.base_url, client_id),
])
result = json.loads(out)
port = result['port']
print('Configuring Deluge to use port {}'.format(port))
cmds = [
'connect {}:{} {} {}'.format(args.deluge_host, args.deluge_port, args.username, args.password),
'config --set listen_ports ({port},{port})'.format(port=port),
]
subprocess.check_call([
'deluge-console',
';'.join(cmds),
])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment