mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Merge pull request #766 from JackDandy/feature/FixDSM
Fix data logger for clients on develop branch (DSM).
This commit is contained in:
commit
be2e53f73f
3 changed files with 51 additions and 41 deletions
|
@ -136,6 +136,7 @@
|
|||
* Change PrivateHD torrent provider
|
||||
* Fix Add from Trakt
|
||||
* Change unpack files once only in auto post processing copy mode
|
||||
* Fix data logger for clients
|
||||
|
||||
|
||||
### 0.11.14 (2016-07-25 03:10:00 UTC)
|
||||
|
|
|
@ -18,58 +18,66 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Uses the Synology Download Station API: http://download.synology.com/download/Document/DeveloperGuide/Synology_Download_Station_Web_API.pdf
|
||||
# Uses the Synology Download Station API:
|
||||
# http://download.synology.com/download/Document/DeveloperGuide/Synology_Download_Station_Web_API.pdf
|
||||
|
||||
import sickbeard
|
||||
from sickbeard.clients.generic import GenericClient
|
||||
|
||||
|
||||
class DownloadStationAPI(GenericClient):
|
||||
|
||||
def __init__(self, host=None, username=None, password=None):
|
||||
|
||||
super(DownloadStationAPI, self).__init__('DownloadStation', host, username, password)
|
||||
|
||||
self.url = self.host + 'webapi/DownloadStation/task.cgi'
|
||||
self.url = '%swebapi/DownloadStation/task.cgi' % self.host
|
||||
|
||||
def _get_auth(self):
|
||||
|
||||
auth_url = self.host + 'webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=' + self.username + '&passwd=' + self.password + '&session=DownloadStation&format=sid'
|
||||
auth_url = ('%swebapi/auth.cgi?api=SYNO.API.Auth&' % self.host +
|
||||
'version=2&method=login&account=%s&passwd=%s' % (self.username, self.password) +
|
||||
'&session=DownloadStation&format=sid')
|
||||
|
||||
try:
|
||||
response = self.session.get(auth_url, verify=False)
|
||||
self.auth = response.json()['data']['sid']
|
||||
except:
|
||||
except (StandardError, Exception):
|
||||
return None
|
||||
|
||||
return self.auth
|
||||
|
||||
def _add_torrent_uri(self, result):
|
||||
|
||||
data = {'api':'SYNO.DownloadStation.Task',
|
||||
'version':'1', 'method':'create',
|
||||
'session':'DownloadStation',
|
||||
'_sid':self.auth,
|
||||
'uri':result.url
|
||||
}
|
||||
if sickbeard.TORRENT_PATH:
|
||||
data['destination'] = sickbeard.TORRENT_PATH
|
||||
response = self._request(method='post', data=data)
|
||||
|
||||
return response.json()['success']
|
||||
return self.send_dsm_request(params={'uri': result.url})
|
||||
|
||||
def _add_torrent_file(self, result):
|
||||
|
||||
data = {'api':'SYNO.DownloadStation.Task',
|
||||
'version':'1',
|
||||
'method':'create',
|
||||
'session':'DownloadStation',
|
||||
'_sid':self.auth
|
||||
}
|
||||
return self.send_dsm_request(files={'file': ('%s.torrent' % result.name, result.content)})
|
||||
|
||||
def send_dsm_request(self, params=None, files=None):
|
||||
|
||||
api_params = {
|
||||
'method': 'create',
|
||||
'version': '1',
|
||||
'api': 'SYNO.DownloadStation.Task',
|
||||
'session': 'DownloadStation',
|
||||
'_sid': self.auth
|
||||
}
|
||||
|
||||
if sickbeard.TORRENT_PATH:
|
||||
data['destination'] = sickbeard.TORRENT_PATH
|
||||
files = {'file':(result.name + '.torrent', result.content)}
|
||||
api_params['destination'] = sickbeard.TORRENT_PATH
|
||||
|
||||
data = api_params.copy()
|
||||
if params:
|
||||
data.update(params)
|
||||
response = self._request(method='post', data=data, files=files)
|
||||
|
||||
return response.json()['success']
|
||||
try:
|
||||
result = response.json()['success']
|
||||
except (StandardError, Exception):
|
||||
result = None
|
||||
|
||||
return result
|
||||
|
||||
api = DownloadStationAPI()
|
||||
|
|
|
@ -33,22 +33,23 @@ class GenericClient(object):
|
|||
self.last_time = time.time()
|
||||
self._get_auth()
|
||||
|
||||
logger.log(
|
||||
'%s: Requested a %s connection to url %s with Params= %s' % (self.name, method.upper(), self.url, params) +
|
||||
' Data= ' + ('None' if not data else '%s%s' % (data[0:99], ('', '...')[200 < len(data)])) +
|
||||
' Json= ' + ('None' if not kwargs.get('json') else '%s%s' %
|
||||
(str(kwargs.get('json'))[0:99],
|
||||
('', '...')[200 < len(str(kwargs.get('json')))])),
|
||||
logger.DEBUG
|
||||
)
|
||||
|
||||
logger.log(
|
||||
'%s: Requested a %s connection to url %s with Params= %s' % (self.name, method.upper(), self.url, params) +
|
||||
('' if not data else ' Data= %s%s' % (data[0:100], ('', '...')[100 < len(data)])) +
|
||||
('' if not kwargs.get('json') else ' Json= %s%s' % (str(kwargs.get('json'))[0:100],
|
||||
('', '...')[100 < len(str(kwargs.get('json')))])),
|
||||
logger.DEBUG
|
||||
)
|
||||
logger.log('%s: sending %s request to %s with ...' % (self.name, method.upper(), self.url), logger.DEBUG)
|
||||
lines = [('params', (str(params), '')[not params]),
|
||||
('data', (str(data), '')[not data]),
|
||||
('files', (str(files), '')[not files]),
|
||||
('json', (str(kwargs.get('json')), '')[not kwargs.get('json')])]
|
||||
m, c = 300, 100
|
||||
type_chunks = [(linetype, [ln[i:i + c] for i in range(0, min(len(ln), m), c)]) for linetype, ln in lines if ln]
|
||||
for (arg, chunks) in type_chunks:
|
||||
output = []
|
||||
nch = len(chunks) - 1
|
||||
for i, seg in enumerate(chunks):
|
||||
if nch == i and 'files' == arg:
|
||||
sample = ' ..excerpt(%s/%s)' % (m, len(lines[2][1]))
|
||||
seg = seg[0:c - (len(sample) - 2)] + sample
|
||||
output += ['%s: request %s= %s%s%s' % (self.name, arg, ('', '..')[bool(i)], seg, ('', '..')[i != nch])]
|
||||
for out in output:
|
||||
logger.log(out, logger.DEBUG)
|
||||
|
||||
if not self.auth:
|
||||
logger.log('%s: Authentication Failed' % self.name, logger.ERROR)
|
||||
|
@ -228,5 +229,5 @@ class GenericClient(object):
|
|||
if authenticated and self.auth:
|
||||
return True, 'Success: Connected and Authenticated'
|
||||
return False, 'Error: Unable to get %s Authentication, check your config!' % self.name
|
||||
except Exception:
|
||||
except (StandardError, Exception):
|
||||
return False, 'Error: Unable to connect to %s' % self.name
|
||||
|
|
Loading…
Reference in a new issue