#!/bin/env python import os,sys import subprocess """ Creates a new torrent using mktorrent with some sensible defaults: --no-date Finds a README file and uses that as the comment Picks up a list of trackers from ~/.config/trackers.txt Run as create-new-torrent --any --other-options /path/to/directory Most common options you might want to overwrite are --output --name """ # Remove the script name arguments = sys.argv del arguments[0] if len(sys.argv) < 1: print("Invalid arguments") print(" create-new-torrent --output file.torrent /path/to/directory") sys.exit(1) # Last argument must be the directory or file directory = sys.argv[-1] comment = None # Only try for a comment if we have a directory if os.path.isdir(directory): for file in ["README.txt", "readme.txt", "README.md", "readme.md", "README.nfo"]: file_path = directory + "/" + file if os.path.exists(file_path): with open(file_path, 'r') as f: comment = f.read() if not comment: print("Could not find a readme file in %s" % directory) # Add all trackers tracker_file = os.path.expanduser('~/.config/trackers.txt') with open(tracker_file, 'r') as t: trackers = t.read().split("\n") list = ["mktorrent"] + ["--announce=%s" % tracker_url for tracker_url in trackers] + ['--no-date'] # Add a comment if we found one if comment: list+=["--comment=\"%s\"" % comment] # Append any extra arguments we got, including the directory list += arguments # Run and passthrough stdout (default) subprocess.run(args=list)