forked from Miserlou/Anomos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanomosify.py
69 lines (57 loc) · 1.68 KB
/
anomosify.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
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
## Mass Anomosification Script - Rich Jones, Anomos Liberty Enhancements
## Public Domain, 2010
## Patches, Flames: [email protected]
from Anomos.bencode import bdecode, bencode
import os
import sys
import getopt
def anomosify(data, announce="https://tracker.anomos.info:5555/announce"):
r = bdecode(data)
if 'announce-list' in r:
for a,l in enumerate(r['announce-list']):
if a == 0:
r['announce-list'][a] = announce
else:
del r['announce-list'][a:]
r['announce'] = announce
r['anon'] = '1'
return bencode(r)
def process_file(fname, announce):
try:
f = file(fname, 'rb')
data = f.read()
anomosified = anomosify(data)
f = open(fname[:-7] + "atorrent", 'w')
f.write(anomosified)
f.close()
except IOError, e:
print e
pass
except Exception, e:
print e
pass
def main(argv):
try:
opts, args = getopt.getopt(argv, "a:p:", ["announce=", "path="])
except getopt.GetoptError:
print "Hey, you need to supply --announce and --path"
sys.exit(2)
for opt, arg in opts:
if opt in ("-a", "--announce"):
announce = arg
else:
announce = "https://tracker.anomos.info:5555/announce"
if opt in ("-p", "--path"):
path = arg
else:
path = '.'
if not os.path.isfile(path):
for fname in os.listdir(path):
fp = os.path.join(path, fname)
print fp
process_file(fp, announce)
else:
process_file(path, announce)
if __name__ == "__main__":
main(sys.argv[1:])