Private GIT

Skip to content
Snippets Groups Projects
Commit 0a7765f6 authored by Ruud's avatar Ruud
Browse files

uTorrent status support. closes #1391

Thanks to Stourwalk
parent c2144587
Branches
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ from hashlib import sha1 ...@@ -6,6 +6,7 @@ from hashlib import sha1
from multipartpost import MultipartPostHandler from multipartpost import MultipartPostHandler
import cookielib import cookielib
import httplib import httplib
import json
import re import re
import time import time
import urllib import urllib
...@@ -64,6 +65,59 @@ class uTorrent(Downloader): ...@@ -64,6 +65,59 @@ class uTorrent(Downloader):
log.error('Failed to send torrent to uTorrent: %s', err) log.error('Failed to send torrent to uTorrent: %s', err)
return False return False
def getAllDownloadStatus(self):
log.debug('Checking uTorrent download status.')
# Load host from config and split out port.
host = self.conf('host').split(':')
if not isInt(host[1]):
log.error('Config properties are not filled in correctly, port is missing.')
return False
try:
self.utorrent_api = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password'))
except Exception, err:
log.error('Failed to get uTorrent object: %s', err)
return False
data = ''
try:
data = self.utorrent_api.get_status()
queue = json.loads(data)
if queue.get('error'):
log.error('Error getting data from uTorrent: %s', queue.get('error'))
return False
except Exception, err:
log.error('Failed to get status from uTorrent: %s', err)
return False
if queue.get('torrents', []) == []:
log.debug('Nothing in queue')
return False
statuses = []
# Get torrents
for item in queue.get('torrents', []):
# item[21] = Paused | Downloading | Seeding | Finished
status = 'busy'
if item[21] == 'Finished' or item[21] == 'Seeding':
status = 'completed'
statuses.append({
'id': item[0],
'name': item[2],
'status': status,
'original_status': item[1],
'timeleft': item[10],
})
return statuses
class uTorrentAPI(object): class uTorrentAPI(object):
...@@ -94,9 +148,7 @@ class uTorrentAPI(object): ...@@ -94,9 +148,7 @@ class uTorrentAPI(object):
try: try:
open_request = self.opener.open(request) open_request = self.opener.open(request)
response = open_request.read() response = open_request.read()
log.debug('response: %s', response)
if response: if response:
log.debug('uTorrent action successfull')
return response return response
else: else:
log.debug('Unknown failure sending command to uTorrent. Return text is: %s', response) log.debug('Unknown failure sending command to uTorrent. Return text is: %s', response)
...@@ -133,3 +185,7 @@ class uTorrentAPI(object): ...@@ -133,3 +185,7 @@ class uTorrentAPI(object):
def pause_torrent(self, hash): def pause_torrent(self, hash):
action = "action=pause&hash=%s" % hash action = "action=pause&hash=%s" % hash
return self._request(action) return self._request(action)
def get_status(self):
action = "list=1"
return self._request(action)
...@@ -566,7 +566,7 @@ class Renamer(Plugin): ...@@ -566,7 +566,7 @@ class Renamer(Plugin):
found = False found = False
for item in statuses: for item in statuses:
if item['name'] == nzbname or getImdb(item['name']) == movie_dict['library']['identifier']: if item['name'] == nzbname or rel_dict['info']['name'] in item['name'] or getImdb(item['name']) == movie_dict['library']['identifier']:
timeleft = 'N/A' if item['timeleft'] == -1 else item['timeleft'] timeleft = 'N/A' if item['timeleft'] == -1 else item['timeleft']
log.debug('Found %s: %s, time to go: %s', (item['name'], item['status'].upper(), timeleft)) log.debug('Found %s: %s, time to go: %s', (item['name'], item['status'].upper(), timeleft))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment