2021-09-29 08:01:35 +00:00
|
|
|
#!/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
|
|
|
|
"""
|
|
|
|
|
2021-09-29 08:10:22 +00:00
|
|
|
# Remove the script name
|
2021-09-29 08:01:35 +00:00
|
|
|
arguments = sys.argv
|
|
|
|
del arguments[0]
|
|
|
|
|
2021-09-29 08:10:22 +00:00
|
|
|
# Last argument must be the directory or file
|
2021-09-29 08:01:35 +00:00
|
|
|
directory = sys.argv[-1]
|
|
|
|
comment = None
|
|
|
|
|
2021-09-29 08:10:22 +00:00
|
|
|
# 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 !comment
|
|
|
|
print("Could not find a readme file in %s" % directory)
|
|
|
|
|
|
|
|
# Add all trackers
|
2021-09-29 08:01:35 +00:00
|
|
|
tracker_file = os.path.expanduser('~/.config/trackers.txt')
|
|
|
|
with open(tracker_file, 'r') as t:
|
2021-09-29 08:10:22 +00:00
|
|
|
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
|
2021-09-29 08:01:35 +00:00
|
|
|
if comment:
|
2021-09-29 08:10:22 +00:00
|
|
|
list+=["--comment=\"%s\"" % comment]
|
|
|
|
|
|
|
|
# Append any extra arguments we got, including the directory
|
2021-09-29 08:01:35 +00:00
|
|
|
list += arguments
|
|
|
|
|
2021-09-29 08:10:22 +00:00
|
|
|
# Run and passthrough stdout (default)
|
2021-09-29 08:01:35 +00:00
|
|
|
subprocess.run(args=list)
|