Skip to content

Instantly share code, notes, and snippets.

@justnom
Last active December 18, 2015 16:09
Show Gist options
  • Save justnom/5809089 to your computer and use it in GitHub Desktop.
Save justnom/5809089 to your computer and use it in GitHub Desktop.
Transmission handler for sevabot. Requires: https://github.com/edavis/transmission-fluid
#!/usr/bin/env python
import sys
from transmission import Transmission, BadRequest
SETTINGS = {
'host': '127.0.0.1',
'port': 9090,
'username': 'foo', # Comment out if no authentication is needed
'password': 'bar', # Same as above
'ssl': False,
}
def add_torrent(filename):
if filename:
client = Transmission(**SETTINGS)
try:
response = client('torrent-add', filename=filename)
if 'torrent-added' in response:
return 'Torrent "{}" added! (sun)'.format(response['torrent-added']['name'])
elif 'torrent-duplicate' in response:
return 'Torrent already added for: {}'.format(response['torrent-duplicate']['name'])
else:
return 'Error interpreting response from transmission! Raw: "{}"'.format(response)
except BadRequest as br_err:
return 'BadRequest: {}'.format(br_error)
except ValueError as value_err:
return 'Error parsing returned JSON: {}'.format(value_err)
else:
return 'You must provide a torrent link to download.'
if len(sys.argv) < 2:
sys.exit('You must provide a torrent link to download.')
result = add_torrent(sys.argv[1])
print result.encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment