Created
November 4, 2024 00:44
-
-
Save kism/357bbafc8652daca77bfc456ffda13d0 to your computer and use it in GitHub Desktop.
Print torrent file list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import bencodepy | |
# Modified version of reddit user u/MadeUpMike's script | |
# Usage: | |
# python3 print_torrent_file_list.py file1.torrent file2.torrent file3.torrent | |
# python3 print_torrent_file_list.py *.torrent | |
def main(): | |
# Parse the torrent filename from the command line | |
parser = argparse.ArgumentParser() | |
parser.add_argument('torrent_filenames',type=argparse.FileType('r'), nargs='+') | |
args = parser.parse_args() | |
for filename in args.torrent_filenames: | |
# Open the torrent file and decode the bencoded data | |
with open(filename.name, 'rb') as f: | |
print("---------------------------------------") | |
print(f"Filename: {filename.name}") | |
try: | |
data = bencodepy.decode(f.read()) | |
except: | |
print("Error decoding " + filename.name) | |
data = "" | |
continue | |
# Print the filename and size of each file in the torrent | |
for file_dict in data[b'info'][b'files']: | |
print(file_dict[b'path'][-1].decode() + "\t" + str(file_dict[b'length'])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment