From 06a36f066fe26a7c94b753cb34834fa2c84f7522 Mon Sep 17 00:00:00 2001 From: inpos Date: Fri, 4 Mar 2016 18:13:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B8=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pyrrent2http/engine.py | 4 +-- lib/pyrrent2http/pyrrent2http.py | 43 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/pyrrent2http/engine.py b/lib/pyrrent2http/engine.py index f5aea27..52bf13c 100644 --- a/lib/pyrrent2http/engine.py +++ b/lib/pyrrent2http/engine.py @@ -320,7 +320,7 @@ class Engine: self.pyrrent2http = pyrrent2http.Pyrrent2http() - self.pyrrent2http.parseFlags(kwargs) + self.pyrrent2http.parseFlags(args) self.pyrrent2http.startSession() self.pyrrent2http.startServices() self.pyrrent2http.addTorrent() @@ -434,7 +434,7 @@ class Engine: :return: List of peers :rtype: list of PeerInfo """ - peers = self._decode(self._request('peers', timeout))['peers'] + peers = self.pyrrent2http.Peers()['peers'] if peers: return [PeerInfo(**p) for p in peers] diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index fc65305..7814f41 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -540,24 +540,8 @@ def HttpHandlerFactory(): self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() - torrentHandle = self.server.root_obj.torrentHandle - ret = list() - for peer in torrentHandle.get_peer_info(): - if peer.flags & peer.connecting or peer.flags & peer.handshake: - continue - pi = { - 'Ip': peer.ip, - 'Flags': peer.flags, - 'Source': peer.source, - 'UpSpeed': peer.up_speed/1024, - 'DownSpeed': peer.down_speed/1024, - 'TotalDownload': peer.total_download, - 'TotalUpload': peer.total_upload, - 'Country': peer.country, - 'Client': peer.client - } - ret.append(pi) - output = json.dumps(ret) + peers = self.server.root_obj.Peers() + output = json.dumps(peers) self.wfile.write(output) def trackersHandler(self): self.send_response(200) @@ -565,9 +549,9 @@ def HttpHandlerFactory(): self.end_headers() ret = list() try: - self.info = self.server.root_obj.torrentHandler.torrent_file() + info = self.server.root_obj.torrentHandler.torrent_file() except: - self.info = self.server.root_obj.torrentHandler.get_torrent_info() + info = self.server.root_obj.torrentHandler.get_torrent_info() for tracker in info.trackers(): pi = { 'Url': tracker.url, @@ -588,6 +572,7 @@ def HttpHandlerFactory(): ret.append(pi) output = json.dumps(ret) self.wfile.write(output) + # Вырубаем access-log def log_message(self, format, *args): return return HttpHandler @@ -892,6 +877,24 @@ class Pyrrent2http(object): } retFiles['files'].append(fi) return retFiles + def Peers(self): + peers = {'peers': []} + for peer in self.torrentHandle.get_peer_info(): + if peer.flags & peer.connecting or peer.flags & peer.handshake: + continue + pi = { + 'Ip': peer.ip, + 'Flags': peer.flags, + 'Source': peer.source, + 'UpSpeed': peer.up_speed/1024, + 'DownSpeed': peer.down_speed/1024, + 'TotalDownload': peer.total_download, + 'TotalUpload': peer.total_upload, + 'Country': peer.country, + 'Client': peer.client + } + peers['peers'].append(pi) + return peers def stats(self): status = self.torrentHandle.status() dhtStatusStr = ''