Last active
December 15, 2015 17:19
-
-
Save gamblore/5295720 to your computer and use it in GitHub Desktop.
SABnzbd-remote which works a bit like tranmission-remote
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 getopt | |
import sys | |
import os | |
import urllib2 | |
import json | |
HOST = "localhost" | |
PORT = 9092 # Set to your port | |
APIKEY = "GIBERISHGIBERISHGIBERISH" # Change to your API KEY | |
def run_cmd(cmd): | |
url = "http://%s:%d/sabnzbd/api?apikey=%s&output=json&%s" % ( HOST, PORT, APIKEY, cmd) | |
handle = urllib2.urlopen(url) | |
data = json.loads(handle.read()) | |
handle.close() | |
return data | |
def list(): | |
data = run_cmd("mode=qstatus") | |
print "\t".join(["Name", "Downloaded", "Size", "Percent", "Bytes Remaining", "Time Remaining"]) | |
for j in data['jobs']: | |
progress = j['mb'] - j['mbleft'] | |
print "\t".join([j['filename'], "%dMB" % (progress), "%dMB" % (j['mb']), "%d%%" % ((progress / j['mb']) * 100), "%dMB" % (j['mbleft']), j['timeleft']]) | |
def add(uri): | |
localfile = os.access(uri, os.F_OK) | |
data = None | |
if localfile: | |
print "Adding local file." | |
data = run_cmd("mode=addlocalfile&name=%s&pp=3" % (uri)) | |
else: | |
print "Adding remote file." | |
data = run_cmd("mode=addurl&name=%s&pp=3" % (uri)) | |
if (data['status'] == True): | |
print "Success." | |
else: | |
print "Failed." | |
def main(): | |
opts, args = getopt.getopt(sys.argv[1:], "a:") | |
for o, a in opts: | |
if (o == "-a"): | |
add(a) | |
print "Added" | |
sys.exit(0) | |
list() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment