Last active
December 18, 2015 16:09
-
-
Save justnom/5809089 to your computer and use it in GitHub Desktop.
Transmission handler for sevabot. Requires: https://github.com/edavis/transmission-fluid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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