Переделал получение списка файлов

sandbox1
inpos 2016-03-04 18:02:14 +03:00
parent 312fcf05e0
commit 7473d69488
2 changed files with 19 additions and 16 deletions

View File

@ -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)]

View File

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