Exemple #1
0
def get_length_filepieceranges_from_metainfo(metainfo, selectedfiles):

    if 'files' not in metainfo['info']:
        # single-file torrent
        return metainfo['info']['length'], None
    else:
        # multi-file torrent
        files = metainfo['info']['files']
        piecesize = metainfo['info']['piece length']

        offset = 0
        total = 0
        filepieceranges = []
        for i in xrange(len(files)):
            path = files[i]['path']
            length = files[i]['length']
            filename = pathlist2filename(path)

            if length > 0 and (not selectedfiles or
                               (selectedfiles and filename in selectedfiles)):
                range = (offset2piece(offset, piecesize, False),
                         offset2piece(offset + length, piecesize),
                         (offset -
                          offset2piece(offset, piecesize, False) * piecesize),
                         filename)
                filepieceranges.append(range)
                total += length
            offset += length
        return total, filepieceranges
Exemple #2
0
def get_length_filepieceranges_from_metainfo(metainfo, selectedfiles):

    if 'files' not in metainfo['info']:
        # single-file torrent
        return metainfo['info']['length'], None
    else:
        # multi-file torrent
        files = metainfo['info']['files']
        piecesize = metainfo['info']['piece length']

        offset = 0
        total = 0
        filepieceranges = []
        for i in xrange(len(files)):
            path = files[i]['path']
            length = files[i]['length']
            filename = pathlist2filename(path)

            if length > 0 and (not selectedfiles or (selectedfiles and filename in selectedfiles)):
                range = (offset2piece(offset, piecesize, False),
                         offset2piece(offset + length, piecesize),
                         (offset - offset2piece(offset, piecesize, False) * piecesize),
                         filename)
                filepieceranges.append(range)
                total += length
            offset += length
        return total, filepieceranges
Exemple #3
0
def get_length_filepieceranges_from_metainfo(metainfo,selectedfiles):
    
    if 'files' not in metainfo['info']:
        # single-file torrent
        return (metainfo['info']['length'],None)
    else:
        # multi-file torrent
        files = metainfo['info']['files']
        piecesize = metainfo['info']['piece length']
        
        total = 0L
        filepieceranges = []
        for i in xrange(len(files)):
            path = files[i]['path']
            length = files[i]['length']
            filename = pathlist2filename(path)
            
            if filename in selectedfiles and length > 0:
                range = (offset2piece(total,piecesize), offset2piece(total + length,piecesize),filename)
                filepieceranges.append(range)
            total += length
        return (total,filepieceranges)
def get_length_filepieceranges_from_metainfo(metainfo, selectedfiles):

    if "files" not in metainfo["info"]:
        # single-file torrent
        return (metainfo["info"]["length"], None)
    else:
        # multi-file torrent
        files = metainfo["info"]["files"]
        piecesize = metainfo["info"]["piece length"]

        total = 0L
        filepieceranges = []
        for i in xrange(len(files)):
            path = files[i]["path"]
            length = files[i]["length"]
            filename = pathlist2filename(path)

            if length > 0 and (not selectedfiles or (selectedfiles and filename in selectedfiles)):
                range = (offset2piece(total, piecesize, False), offset2piece(total + length, piecesize), filename)
                filepieceranges.append(range)
                total += length
        return (total, filepieceranges)
Exemple #5
0
def get_length_filepieceranges_from_metainfo(metainfo, selectedfiles):

    if 'files' not in metainfo['info']:
        # single-file torrent
        return (metainfo['info']['length'], None)
    else:
        # multi-file torrent
        files = metainfo['info']['files']
        piecesize = metainfo['info']['piece length']

        total = 0L
        filepieceranges = []
        for i in xrange(len(files)):
            path = files[i]['path']
            length = files[i]['length']
            filename = pathlist2filename(path)

            if filename in selectedfiles and length > 0:
                range = (offset2piece(total, piecesize),
                         offset2piece(total + length, piecesize), filename)
                filepieceranges.append(range)
            total += length
        return (total, filepieceranges)
 def test_offset2piece(self):
     self.assertEqual(offset2piece(42, 2), 21)
     self.assertEqual(offset2piece(42, 18), 3)
     self.assertEqual(offset2piece(71, 11), 7)
     self.assertEqual(offset2piece(42, 18, endpoint=False), 2)