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 = ''