Added torrent support for Synology downloader.
This commit is contained in:
1 parent
6dcd74d116
commit
a1a7fec15f
1 file changed
+5
-11
@@ -11,7 +11,7 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
class Synology(Downloader):
|
class Synology(Downloader):
|
||||||
|
|
||||||
type = ['torrent_magnet']
|
type = ['torrent', 'torrent_magnet']
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
def download(self, data, movie, filedata = None):
|
def download(self, data, movie, filedata = None):
|
||||||
@@ -24,10 +24,6 @@ class Synology(Downloader):
|
|||||||
log.error('Config properties are not filled in correctly, port is missing.')
|
log.error('Config properties are not filled in correctly, port is missing.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if data.get('type') == 'torrent':
|
|
||||||
log.error('Can\'t add binary torrent file')
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Send request to Transmission
|
# Send request to Transmission
|
||||||
srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'))
|
srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'))
|
||||||
@@ -71,15 +67,15 @@ class SynologyRPC(object):
|
|||||||
return self._req(self.auth_url, args)
|
return self._req(self.auth_url, args)
|
||||||
|
|
||||||
def _req(self, url, args):
|
def _req(self, url, args):
|
||||||
req_url = url + '?' + urllib.urlencode(args)
|
req = urllib2.Request(url, urllib.urlencode(args))
|
||||||
try:
|
try:
|
||||||
req_open = urllib2.urlopen(req_url)
|
req_open = urllib2.urlopen(req)
|
||||||
response = json.loads(req_open.read())
|
response = json.loads(req_open.read())
|
||||||
if response['success'] == True:
|
if response['success'] == True:
|
||||||
log.info('Synology action successfull')
|
log.info('Synology action successfull')
|
||||||
return response
|
return response
|
||||||
except httplib.InvalidURL, err:
|
except httplib.InvalidURL, err:
|
||||||
log.error('Invalid Transmission host, check your config %s', err)
|
log.error('Invalid Synology host, check your config %s', err)
|
||||||
return False
|
return False
|
||||||
except urllib2.HTTPError, err:
|
except urllib2.HTTPError, err:
|
||||||
log.error('SynologyRPC HTTPError: %s', err)
|
log.error('SynologyRPC HTTPError: %s', err)
|
||||||
@@ -93,7 +89,7 @@ class SynologyRPC(object):
|
|||||||
response = {}
|
response = {}
|
||||||
# login
|
# login
|
||||||
login = self._login()
|
login = self._login()
|
||||||
if len(login) > 0 and login['success'] == True:
|
if login and login['success'] == True:
|
||||||
log.info('Login success, adding torrent')
|
log.info('Login success, adding torrent')
|
||||||
args = {'api':'SYNO.DownloadStation.Task', 'version':1, 'method':'create', 'uri':torrent, '_sid':self.sid}
|
args = {'api':'SYNO.DownloadStation.Task', 'version':1, 'method':'create', 'uri':torrent, '_sid':self.sid}
|
||||||
response = self._req(self.download_url, args)
|
response = self._req(self.download_url, args)
|
||||||
@@ -101,5 +97,3 @@ class SynologyRPC(object):
|
|||||||
else:
|
else:
|
||||||
log.error('Couldn\'t login to Synology, %s', login)
|
log.error('Couldn\'t login to Synology, %s', login)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user