From 7473d69488a19af680db3cb72fb01db4eb4e5e41 Mon Sep 17 00:00:00 2001 From: inpos Date: Fri, 4 Mar 2016 18:02:14 +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=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pyrrent2http/engine.py | 2 +- lib/pyrrent2http/pyrrent2http.py | 33 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/pyrrent2http/engine.py b/lib/pyrrent2http/engine.py index 1217475..f5aea27 100644 --- a/lib/pyrrent2http/engine.py +++ b/lib/pyrrent2http/engine.py @@ -399,7 +399,7 @@ class Engine: :rtype : list of FileStatus :return: List of files of specified media types or None if torrent is not loaded yet """ - files = self._decode(self._request('ls', timeout))['files'] + files = self.pyrrent2http.Ls()['files'] if files: res = [FileStatus(index=index, media_type=self._detect_media_type(f['name']), **f) for index, f in enumerate(files)] diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index f52b0dc..fc65305 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -533,21 +533,7 @@ def HttpHandlerFactory(): self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() - retFiles = {'files': []} - if self.server.root_obj.TorrentFS.HasTorrentInfo(): - files = self.server.root_obj.TorrentFS.Files() - for file_ in files: - Url = 'http://' + self.server.root_obj.config.bindAddress + '/files/' + urllib.quote(file_.Name()) - fi = { - 'name': file_.Name(), - 'size': file_.size, - 'offset': file_.offset, - 'download': file_.Downloaded(), - 'progress': file_.Progress(), - 'save_path': file_.SavePath(), - 'url': Url - } - retFiles['files'].append(fi) + retFiles = self.server.root_obj.Ls() output = json.dumps(retFiles) self.wfile.write(output) def peersHandler(self): @@ -889,6 +875,23 @@ class Pyrrent2http(object): 'total_peers' : tstatus.num_incomplete } return status + def Ls(self): + retFiles = {'files': []} + if self.TorrentFS.HasTorrentInfo(): + files = self.TorrentFS.Files() + for file_ in files: + Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(file_.Name()) + fi = { + 'name': file_.Name(), + 'size': file_.size, + 'offset': file_.offset, + 'download': file_.Downloaded(), + 'progress': file_.Progress(), + 'save_path': file_.SavePath(), + 'url': Url + } + retFiles['files'].append(fi) + return retFiles def stats(self): status = self.torrentHandle.status() dhtStatusStr = ''