This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
btcopyannounce.py
executable file
·57 lines (44 loc) · 1.58 KB
/
btcopyannounce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
'Copy announce URLs from one torrent to others'
# btreannounce.py written by Henry 'Pi' James and Bram Cohen
# multitracker extensions by John Hoffman
# see LICENSE.txt for license information
import sys
import os
import getopt
from BitTornado.Meta.Info import MetaInfo
from BitTornado.Application.reannounce import reannounce
def main(argv):
"""Copy announce information from source to all specified torrents"""
program, _ = os.path.splitext(os.path.basename(argv[0]))
usage = "Usage: %s <source.torrent> <file1.torrent> " \
"[file2.torrent...]" % program
try:
opts, args = getopt.getopt(argv[1:], "hv",
("help", "verbose"))
except getopt.error as msg:
print(msg)
return 1
if len(args) < 2:
print("{}\n{}\n".format(usage, main.__doc__))
return 2
source_metainfo = MetaInfo.read(args[0])
verbose = False
for opt, _ in opts:
if opt in ('-h', '--help'):
print("{}\n{}\n".format(usage, main.__doc__))
return 0
elif opt in ('-v', '--verbose'):
verbose = True
announce = source_metainfo['announce']
announce_list = source_metainfo.get('announce-list')
if verbose:
print('new announce: ', announce)
if announce_list:
print('new announce-list: ',
'|'.join(','.join(tier) for tier in announce_list))
for fname in args[1:]:
reannounce(fname, announce, announce_list, verbose)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))