From 312fcf05e033dec1a8a1ad9f1af9814e1f4576cd Mon Sep 17 00:00:00 2001 From: inpos Date: Fri, 4 Mar 2016 17:52:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pyrrent2http/engine.py | 2 +- lib/pyrrent2http/pyrrent2http.py | 46 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/pyrrent2http/engine.py b/lib/pyrrent2http/engine.py index 730d057..1217475 100644 --- a/lib/pyrrent2http/engine.py +++ b/lib/pyrrent2http/engine.py @@ -368,7 +368,7 @@ class Engine: :rtype : SessionStatus :param timeout: pyrrent2http client request timeout """ - status = self._decode(self._request('status', timeout)) + status = self.pyrrent2http.Status() status = SessionStatus(**status) return status diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index a56f922..f52b0dc 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -526,28 +526,7 @@ def HttpHandlerFactory(): self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() - torrentHandle = self.server.root_obj.torrentHandle - try: - info = torrentHandle.torrent_file() - except: - info = torrentHandle.get_torrent_info() - - tstatus = torrentHandle.status() - status = { - 'name' : info.name(), - 'state' : int(tstatus.state), - 'state_str' : str(tstatus.state), - 'error' : tstatus.error, - 'progress' : tstatus.progress, - 'download_rate' : tstatus.download_rate / 1024, - 'upload_rate' : tstatus.upload_rate / 1024, - 'total_download' : tstatus.total_download, - 'total_upload' : tstatus.total_upload, - 'num_peers' : tstatus.num_peers, - 'num_seeds' : tstatus.num_seeds, - 'total_seeds' : tstatus.num_complete, - 'total_peers' : tstatus.num_incomplete - } + status = self.server.root_obj.Status() output = json.dumps(status) self.wfile.write(output) def lsHandler(self): @@ -886,7 +865,30 @@ class Pyrrent2http(object): self.session.set_pe_settings(encryptionSettings) except Exception as e: logging.info('Encryption not supported: %s' % (e.args,)) + + def Status(self): + try: + info = self.torrentHandle.torrent_file() + except: + info = self.torrentHandle.get_torrent_info() + tstatus = self.torrentHandle.status() + status = { + 'name' : info.name(), + 'state' : int(tstatus.state), + 'state_str' : str(tstatus.state), + 'error' : tstatus.error, + 'progress' : tstatus.progress, + 'download_rate' : tstatus.download_rate / 1024, + 'upload_rate' : tstatus.upload_rate / 1024, + 'total_download' : tstatus.total_download, + 'total_upload' : tstatus.total_upload, + 'num_peers' : tstatus.num_peers, + 'num_seeds' : tstatus.num_seeds, + 'total_seeds' : tstatus.num_complete, + 'total_peers' : tstatus.num_incomplete + } + return status def stats(self): status = self.torrentHandle.status() dhtStatusStr = ''