pythonlibtorrent

How do you get the total size of a torrent in libtorrent?


How do you get the total size of the files in a torrent?

And is there any way to get the number of files in a torrent and the size of each one?


Solution

  • Using torrent_parser:

    import torrent_parser as tp
    
    torrent_metadata = tp.parse_torrent_file("file.torrent")
    totalsize = 0
    
    for file in torrent_metadata['info']['files']:
        totalsize += file['length']
    
    print(totalsize)