diff --git a/README.md b/README.md index 0430125..37ed2c8 100644 --- a/README.md +++ b/README.md @@ -110,4 +110,5 @@ This lives in my `~/projects/scripts` directory and is added to my `$PATH`. Not | ec | script to edit common configuration | | get-nav | Get NAV of a mutual fund from the Kuvera API | | audiobook2video | Generates a video for a music file, with a background | -| fix-audible-m4a | Third-party. Fixes audible m4a fiels with incorrect Audio Object Type Specific Config bit. Source: https://rentry.co/n4ost | \ No newline at end of file +| fix-audible-m4a | Third-party. Fixes audible m4a fiels with incorrect Audio Object Type Specific Config bit. Source: https://rentry.co/n4ost | +| create-new-torrent| Creates a new torrent file with sensible defaults using mktorrent | \ No newline at end of file diff --git a/create-new-torrent b/create-new-torrent new file mode 100755 index 0000000..35c1055 --- /dev/null +++ b/create-new-torrent @@ -0,0 +1,40 @@ +#!/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 +""" + +arguments = sys.argv +del arguments[0] + +directory = sys.argv[-1] +comment = None +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) + +tracker_file = os.path.expanduser('~/.config/trackers.txt') +with open(tracker_file, 'r') as t: + list = ["mktorrent"] + ["--announce=%s" % x for x in t.read().split("\n")] + ['--no-date'] +if comment: + list+=["--comment=\"%s\""%comment] +list += arguments + +subprocess.run(args=list) \ No newline at end of file