new script to create torrents

This commit is contained in:
Nemo 2021-09-29 13:31:35 +05:30
parent ffaca3fbbb
commit 1a7634b490
2 changed files with 42 additions and 1 deletions

View File

@ -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 |
| 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 |

40
create-new-torrent Executable file
View File

@ -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)