Example #1
0
    def write(self, target, tracker, **params):
        """Write a .torrent file

        Parameters
            str     target             - target file name (full path)
            str     tracker            - URL of tracker
        
        Optional parameters
            str     comment            - comment to include in file
            str     announce_list      - unparsed announce list
            str[][] real_announce_list - hierarchical announce list
            str     httpseeds          - unparsed http seed list
            str[]   real_httpseeds     - list of http seeds
        """

        # Whatever hash we have left, we'll add on to the end
        excess = []
        if self.done > 0:
            excess.append(self.sh.digest())

        info = {
            'pieces': ''.join(self.pieces + excess),
            'piece length': self.piece_length,
            'name': self.name
        }

        # If there is only one file and it has the same name path as the
        # torrent name, then encode directly, not as a files dictionary
        if len(self.fs) == 1 and self.fs[0]['path'] == []:
            info['length'] = self.size
        else:
            info['files'] = self.fs

        check_info(info)

        data = {'info': info, 'announce': tracker, 'creation date': long(0)}

        # Optional data dictionary contents
        if params.has_key('comment') and params['comment']:
            data['comment'] = params['comment']

        if params.has_key('real_announce_list'):
            data['announce-list'] = params['real_announce_list']
        elif params.has_key('announce_list') and params['announce_list']:
            l = []
            for tier in params['announce_list'].split('|'):
                l.append(tier.split(','))
            data['announce-list'] = l

        if params.has_key('real_httpseeds'):
            data['httpseeds'] = params['real_httpseeds']
        elif params.has_key('httpseeds') and params['httpseeds']:
            data['httpseeds'] = params['httpseeds'].split('|')

        # Write file
        h = open(target, 'wb')
        h.write(bencode(data))
        h.close()
Example #2
0
    def write(self, target, tracker, **params):
        """Write a .torrent file

        Parameters
            str     target             - target file name (full path)
            str     tracker            - URL of tracker
        
        Optional parameters
            str     comment            - comment to include in file
            str     announce_list      - unparsed announce list
            str[][] real_announce_list - hierarchical announce list
            str     httpseeds          - unparsed http seed list
            str[]   real_httpseeds     - list of http seeds
        """
        
        # Whatever hash we have left, we'll add on to the end
        excess = []
        if self.done > 0:
            excess.append(self.sh.digest())
        
        info = {'pieces': ''.join(self.pieces + excess),
                'piece length': self.piece_length,
                'name': self.name}
        
        # If there is only one file and it has the same name path as the
        # torrent name, then encode directly, not as a files dictionary
        if len(self.fs) == 1 and self.fs[0]['path'] == []:
            info['length'] = self.size
        else:
            info['files'] = self.fs

        check_info(info)
        
        data = {'info': info, 'announce': tracker, 'creation date': long(0)}

        # Optional data dictionary contents
        if params.has_key('comment') and params['comment']:
            data['comment'] = params['comment']
            
        if params.has_key('real_announce_list'):
            data['announce-list'] = params['real_announce_list']
        elif params.has_key('announce_list') and params['announce_list']:
            l = []
            for tier in params['announce_list'].split('|'):
                l.append(tier.split(','))
            data['announce-list'] = l
            
        if params.has_key('real_httpseeds'):
            data['httpseeds'] = params['real_httpseeds']
        elif params.has_key('httpseeds') and params['httpseeds']:
            data['httpseeds'] = params['httpseeds'].split('|')
        
        # Write file
        h = open(target, 'wb')
        h.write(bencode(data))
        h.close()
Example #3
0
	def write(self):
		"""Write a .torrent file"""

		# Whatever hash we have left, we'll take
		if self.done > 0:
			self.pieces.append(self.sh.digest())

		info = {'pieces': ''.join(self.pieces),
			'piece length': self.piece_length,
			'files': self.fs,
			'name': self.name}

		check_info(info)

		data = {'info': info, 'announce': self.tracker, 'creation data': long(time())}

		h = open(self.target, 'wb')
		h.write(bencode(data))
		h.close()
Example #4
0
        else:                           # < 4M =
            piece_len_exp = 15          #   32K pieces
    piece_length = 2 ** piece_len_exp
    
    encoding = None
    if 'filesystem_encoding' in params:
        encoding = params['filesystem_encoding']
    if not encoding:
        encoding = ENCODING
    if not encoding:
        encoding = 'ascii'
    
    info = makeinfo(file, piece_length, encoding, flag, progress, progress_percent, gethash = gethash, filelist = filelist)
    if flag.isSet():
        return
    check_info(info)
    h = open(f, 'wb')

    data = {'info': info, 'creation date': long(time())}
    
    # Flag for secure torrents
    private = False
    if 'private' in params and params['private']:
        private = True
        data['info']['private'] = 1
    
    # Comment
    if 'comment' in params and params['comment']:
        data['comment'] = params['comment']
        data['comment.utf-8'] = uniconvert(params['comment'],'utf-8')
Example #5
0
        encoding = params['filesystem_encoding']
    if not encoding:
        encoding = ENCODING
    if not encoding:
        encoding = 'ascii'

    info = makeinfo(file,
                    piece_length,
                    encoding,
                    flag,
                    progress,
                    progress_percent,
                    gethash=gethash)
    if flag.isSet():
        return
    check_info(info)
    h = open(f, 'wb')
    data = {
        'info': info,
        'announce': strip(url),
        'creation date': long(time())
    }

    if 'comment' in params and params['comment']:
        data['comment'] = params['comment']

    if 'created by' in params and params['created by']:
        data['created by'] = params['created by']

    if 'real_announce_list' in params:  # shortcut for progs calling in from outside
        data['announce-list'] = params['real_announce_list']