56 lines
1.3 KiB
Python
Executable File
56 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3.11
|
|
import argparse
|
|
import io
|
|
from pathlib import Path
|
|
|
|
import torf
|
|
|
|
|
|
def parse_args() -> dict:
|
|
arger = argparse.ArgumentParser()
|
|
arger.add_argument('torrent_path', type=Path, help='Path to torrent file')
|
|
arger.add_argument('--name', type=Path, help='New filename', required=True)
|
|
return dict(arger.parse_args().__dict__)
|
|
|
|
|
|
def modify_torrent(
|
|
torrent_file: bytes,
|
|
name: str,
|
|
announce_url: str,
|
|
created_by: str = '',
|
|
comment: str = '',
|
|
private: bool = True,
|
|
) -> bytes:
|
|
t = torf.Torrent.read_stream(io.BytesIO(torrent_file))
|
|
|
|
if len(t.files) > 1:
|
|
raise ValueError('Torrent contains multiple files')
|
|
|
|
t.name = name
|
|
t.private = private
|
|
t.comment = comment
|
|
t.created_by = created_by
|
|
t.trackers.clear()
|
|
t.trackers.insert(0, announce_url)
|
|
|
|
return t.dump()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
torrent_path: Path = args.pop('torrent_path')
|
|
modded = modify_torrent(
|
|
**args,
|
|
torrent_file=torrent_path.read_bytes(),
|
|
announce_url='http://tracker.empornium.sx:2710/tegqucis10uanp672qh6nhn393xlkncs/announce',
|
|
created_by='zzzp',
|
|
comment='created by zzzp',
|
|
private=True,
|
|
)
|
|
save_path = torrent_path.with_stem(f'{torrent_path.stem}.mod')
|
|
save_path.write_bytes(modded)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|