Имя в статусе серии

pull/1/head
inpos 2016-03-19 22:00:16 +03:00
parent ad26862286
commit 3ecaa41dbb
2 changed files with 40 additions and 39 deletions

View File

@ -196,7 +196,7 @@ class Engine:
'maxFailCount': self.max_failcount,
'showPiecesProgress': self.log_pieces_progress,
'idleTimeout': self.max_idle_timeout,
'fileIndex': start_index,
#'fileIndex': start_index,
'connectionsLimit': self.connections_limit,
'enableScrape': self.enable_scrape,
'enableUTP': self.enable_utp,
@ -245,6 +245,9 @@ class Engine:
raise Error("Can't start pyrrent2http, time is out", Error.TIMEOUT)
self._log("pyrrent2http successfully started.")
def activate_file(self, index):
self.pyrrent2http.TorrentFS.file(index)
def check_torrent_error(self, status=None):
"""
It is recommended to call this method periodically to check if any libtorrent errors occurred.
@ -324,11 +327,10 @@ class Engine:
:return: File with specified index
:rtype: FileStatus
"""
files = self.pyrrent2http.Ls()['files']
if files:
for f in files:
if f['index'] == file_index:
return FileStatus(**f)
filestatus = self.pyrrent2http.Ls(file_index)
try:
return FileStatus(**filestatus)
except:
raise Error("Requested file index (%d) is invalid" % (file_index,), Error.INVALID_FILE_INDEX,
file_index=file_index)

View File

@ -261,25 +261,21 @@ class TorrentFS(object):
progresses = list()
save_path = None
def __init__(self, root, handle, startIndex):
def __init__(self, root, handle):
self.root = root
self.handle = handle
self.waitForMetadata()
self.save_path = localize_path(self.root.torrentParams['save_path'])
self.priorities = list(self.handle.file_priorities())
file_ = self.__file_at_(startIndex)
num_files = self.info.num_files()
for i in range(num_files):
self.setPriority(i, 0)
def file(self, index):
file_ = self.__file_at_(index)
self.files = {file_.name: file_}
#self.handle.set_piece_deadline(self.files[startIndex].startPiece, 50)
if startIndex < 0:
logging.info('No -file-index specified, downloading will be paused until any file is requested')
num_files = self.info.num_files()
for i in range(num_files):
if startIndex == i:
self.setPriority(i, 1)
else:
self.setPriority(i, 0)
self.setPriority(index, 1)
return file_
def Shutdown(self):
self.shuttingDown = True
@ -462,7 +458,7 @@ def HttpHandlerFactory():
class Pyrrent2http(object):
def __init__(self, uri = '', bindAddress = 'localhost:5001', downloadPath = '.',
idleTimeout = -1, fileIndex = -1, keepComplete = False,
idleTimeout = -1, keepComplete = False,
keepIncomplete = False, keepFiles = False, showAllStats = False,
showOverallProgress = False, showFilesProgress = False,
showPiecesProgress = False, debugAlerts = False,
@ -484,7 +480,7 @@ class Pyrrent2http(object):
self.config.bindAddress = bindAddress
self.config.downloadPath = downloadPath
self.config.idleTimeout = idleTimeout
self.config.fileIndex = fileIndex
#self.config.fileIndex = fileIndex
self.config.keepComplete = keepComplete
self.config.keepIncomplete = keepIncomplete
self.config.keepFiles = keepFiles
@ -582,9 +578,12 @@ class Pyrrent2http(object):
info = self.torrentHandle.get_torrent_info()
logging.info('Downloading torrent: %s' % (info.name(),))
try:
self.TorrentFS = TorrentFS(self, self.torrentHandle, self.config.fileIndex)
self.TorrentFS = TorrentFS(self, self.torrentHandle)
except Exception as e:
logging.error(e.args)
#_ = self.TorrentFS.file(self.config.fileIndex)
name = self.TorrentFS.info.name()
self.torrent_name = name.decode(chardet.detect(name)['encoding'])
def startHTTP(self):
#def http_server_loop(listener, alive):
@ -720,7 +719,7 @@ class Pyrrent2http(object):
tstatus = self.torrentHandle.status()
status = {
'name' : info.name(),
'name' : self.torrent_name,
'state' : int(tstatus.state),
'state_str' : str(tstatus.state),
'error' : tstatus.error,
@ -735,11 +734,12 @@ class Pyrrent2http(object):
'total_peers' : tstatus.num_incomplete
}
return status
def Ls(self):
retFiles = {'files': []}
def Ls(self, index):
fi = {}
if self.TorrentFS.HasTorrentInfo():
x = [n for n in self.TorrentFS.files.keys() if self.TorrentFS.files[n].index == index]
name = x[0]
files = self.TorrentFS.files
for name in files.keys():
Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(name)
fi = {
'index': files[name].index,
@ -752,8 +752,7 @@ class Pyrrent2http(object):
'save_path': files[name].save_path,
'url': Url
}
retFiles['files'].append(fi)
return retFiles
return fi
def Peers(self):
peers = {'peers': []}
for peer in self.torrentHandle.get_peer_info():