Имя в статусе серии
This commit is contained in:
		
							parent
							
								
									ad26862286
								
							
						
					
					
						commit
						3ecaa41dbb
					
				@ -196,7 +196,7 @@ class Engine:
 | 
				
			|||||||
            'maxFailCount': self.max_failcount,
 | 
					            'maxFailCount': self.max_failcount,
 | 
				
			||||||
            'showPiecesProgress': self.log_pieces_progress,
 | 
					            'showPiecesProgress': self.log_pieces_progress,
 | 
				
			||||||
            'idleTimeout': self.max_idle_timeout,
 | 
					            'idleTimeout': self.max_idle_timeout,
 | 
				
			||||||
            'fileIndex': start_index,
 | 
					            #'fileIndex': start_index,
 | 
				
			||||||
            'connectionsLimit': self.connections_limit,
 | 
					            'connectionsLimit': self.connections_limit,
 | 
				
			||||||
            'enableScrape': self.enable_scrape,
 | 
					            'enableScrape': self.enable_scrape,
 | 
				
			||||||
            'enableUTP': self.enable_utp,
 | 
					            'enableUTP': self.enable_utp,
 | 
				
			||||||
@ -245,6 +245,9 @@ class Engine:
 | 
				
			|||||||
            raise Error("Can't start pyrrent2http, time is out", Error.TIMEOUT)
 | 
					            raise Error("Can't start pyrrent2http, time is out", Error.TIMEOUT)
 | 
				
			||||||
        self._log("pyrrent2http successfully started.")
 | 
					        self._log("pyrrent2http successfully started.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def activate_file(self, index):
 | 
				
			||||||
 | 
					        self.pyrrent2http.TorrentFS.file(index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check_torrent_error(self, status=None):
 | 
					    def check_torrent_error(self, status=None):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        It is recommended to call this method periodically to check if any libtorrent errors occurred.
 | 
					        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
 | 
					        :return: File with specified index
 | 
				
			||||||
        :rtype: FileStatus
 | 
					        :rtype: FileStatus
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        files = self.pyrrent2http.Ls()['files']
 | 
					        filestatus = self.pyrrent2http.Ls(file_index)
 | 
				
			||||||
        if files:
 | 
					        try:
 | 
				
			||||||
            for f in files:
 | 
					            return FileStatus(**filestatus)
 | 
				
			||||||
                if f['index'] == file_index:
 | 
					        except:
 | 
				
			||||||
                    return FileStatus(**f)
 | 
					 | 
				
			||||||
            raise Error("Requested file index (%d) is invalid" % (file_index,), Error.INVALID_FILE_INDEX,
 | 
					            raise Error("Requested file index (%d) is invalid" % (file_index,), Error.INVALID_FILE_INDEX,
 | 
				
			||||||
                            file_index=file_index)
 | 
					                            file_index=file_index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -261,25 +261,21 @@ class TorrentFS(object):
 | 
				
			|||||||
    progresses  =       list()
 | 
					    progresses  =       list()
 | 
				
			||||||
    save_path   =       None
 | 
					    save_path   =       None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, root, handle, startIndex):
 | 
					    def __init__(self, root, handle):
 | 
				
			||||||
        self.root = root
 | 
					        self.root = root
 | 
				
			||||||
        self.handle = handle
 | 
					        self.handle = handle
 | 
				
			||||||
        self.waitForMetadata()
 | 
					        self.waitForMetadata()
 | 
				
			||||||
        self.save_path = localize_path(self.root.torrentParams['save_path'])
 | 
					        self.save_path = localize_path(self.root.torrentParams['save_path'])
 | 
				
			||||||
        self.priorities = list(self.handle.file_priorities())
 | 
					        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.files = {file_.name: file_}
 | 
				
			||||||
        #self.handle.set_piece_deadline(self.files[startIndex].startPiece, 50)
 | 
					        #self.handle.set_piece_deadline(self.files[startIndex].startPiece, 50)
 | 
				
			||||||
        if startIndex < 0:
 | 
					        self.setPriority(index, 1)
 | 
				
			||||||
            logging.info('No -file-index specified, downloading will be paused until any file is requested')
 | 
					        return file_
 | 
				
			||||||
 | 
					 | 
				
			||||||
        num_files = self.info.num_files()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for i in range(num_files):
 | 
					 | 
				
			||||||
            if startIndex == i:
 | 
					 | 
				
			||||||
                self.setPriority(i, 1)
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                self.setPriority(i, 0)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def Shutdown(self):
 | 
					    def Shutdown(self):
 | 
				
			||||||
        self.shuttingDown = True
 | 
					        self.shuttingDown = True
 | 
				
			||||||
@ -462,7 +458,7 @@ def HttpHandlerFactory():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Pyrrent2http(object):
 | 
					class Pyrrent2http(object):
 | 
				
			||||||
    def __init__(self, uri = '', bindAddress = 'localhost:5001', downloadPath = '.',
 | 
					    def __init__(self, uri = '', bindAddress = 'localhost:5001', downloadPath = '.',
 | 
				
			||||||
                    idleTimeout = -1, fileIndex = -1, keepComplete = False, 
 | 
					                    idleTimeout = -1, keepComplete = False, 
 | 
				
			||||||
                    keepIncomplete = False, keepFiles = False, showAllStats = False, 
 | 
					                    keepIncomplete = False, keepFiles = False, showAllStats = False, 
 | 
				
			||||||
                    showOverallProgress = False, showFilesProgress = False, 
 | 
					                    showOverallProgress = False, showFilesProgress = False, 
 | 
				
			||||||
                    showPiecesProgress = False, debugAlerts = False,
 | 
					                    showPiecesProgress = False, debugAlerts = False,
 | 
				
			||||||
@ -484,7 +480,7 @@ class Pyrrent2http(object):
 | 
				
			|||||||
        self.config.bindAddress = bindAddress
 | 
					        self.config.bindAddress = bindAddress
 | 
				
			||||||
        self.config.downloadPath = downloadPath
 | 
					        self.config.downloadPath = downloadPath
 | 
				
			||||||
        self.config.idleTimeout = idleTimeout
 | 
					        self.config.idleTimeout = idleTimeout
 | 
				
			||||||
        self.config.fileIndex = fileIndex
 | 
					        #self.config.fileIndex = fileIndex
 | 
				
			||||||
        self.config.keepComplete = keepComplete
 | 
					        self.config.keepComplete = keepComplete
 | 
				
			||||||
        self.config.keepIncomplete = keepIncomplete
 | 
					        self.config.keepIncomplete = keepIncomplete
 | 
				
			||||||
        self.config.keepFiles = keepFiles
 | 
					        self.config.keepFiles = keepFiles
 | 
				
			||||||
@ -582,9 +578,12 @@ class Pyrrent2http(object):
 | 
				
			|||||||
            info = self.torrentHandle.get_torrent_info()
 | 
					            info = self.torrentHandle.get_torrent_info()
 | 
				
			||||||
        logging.info('Downloading torrent: %s' % (info.name(),))
 | 
					        logging.info('Downloading torrent: %s' % (info.name(),))
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.TorrentFS = TorrentFS(self, self.torrentHandle, self.config.fileIndex)
 | 
					            self.TorrentFS = TorrentFS(self, self.torrentHandle)
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            logging.error(e.args)
 | 
					            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 startHTTP(self):
 | 
				
			||||||
        #def http_server_loop(listener, alive):
 | 
					        #def http_server_loop(listener, alive):
 | 
				
			||||||
@ -720,7 +719,7 @@ class Pyrrent2http(object):
 | 
				
			|||||||
        tstatus = self.torrentHandle.status()
 | 
					        tstatus = self.torrentHandle.status()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        status = {
 | 
					        status = {
 | 
				
			||||||
                     'name'           :   info.name(),
 | 
					                     'name'           :   self.torrent_name,
 | 
				
			||||||
                     'state'          :   int(tstatus.state),
 | 
					                     'state'          :   int(tstatus.state),
 | 
				
			||||||
                     'state_str'       :   str(tstatus.state),
 | 
					                     'state_str'       :   str(tstatus.state),
 | 
				
			||||||
                     'error'          :   tstatus.error,
 | 
					                     'error'          :   tstatus.error,
 | 
				
			||||||
@ -735,11 +734,12 @@ class Pyrrent2http(object):
 | 
				
			|||||||
                     'total_peers'     :   tstatus.num_incomplete
 | 
					                     'total_peers'     :   tstatus.num_incomplete
 | 
				
			||||||
                     }
 | 
					                     }
 | 
				
			||||||
        return status
 | 
					        return status
 | 
				
			||||||
    def Ls(self):
 | 
					    def Ls(self, index):
 | 
				
			||||||
        retFiles = {'files': []}
 | 
					        fi = {}
 | 
				
			||||||
        if self.TorrentFS.HasTorrentInfo():
 | 
					        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
 | 
					            files = self.TorrentFS.files
 | 
				
			||||||
            for name in files.keys():
 | 
					 | 
				
			||||||
            Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(name)
 | 
					            Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(name)
 | 
				
			||||||
            fi = {
 | 
					            fi = {
 | 
				
			||||||
                  'index':      files[name].index,
 | 
					                  'index':      files[name].index,
 | 
				
			||||||
@ -752,8 +752,7 @@ class Pyrrent2http(object):
 | 
				
			|||||||
                  'save_path':  files[name].save_path,
 | 
					                  'save_path':  files[name].save_path,
 | 
				
			||||||
                  'url':        Url
 | 
					                  'url':        Url
 | 
				
			||||||
                  }
 | 
					                  }
 | 
				
			||||||
                retFiles['files'].append(fi)
 | 
					        return fi
 | 
				
			||||||
        return retFiles
 | 
					 | 
				
			||||||
    def Peers(self):
 | 
					    def Peers(self):
 | 
				
			||||||
        peers = {'peers': []}
 | 
					        peers = {'peers': []}
 | 
				
			||||||
        for peer in self.torrentHandle.get_peer_info():
 | 
					        for peer in self.torrentHandle.get_peer_info():
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user