-
Notifications
You must be signed in to change notification settings - Fork 0
/
btsethttpseeds.py
48 lines (42 loc) · 1.3 KB
/
btsethttpseeds.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
#!/usr/bin/env python
# Written by Henry 'Pi' James and Bram Cohen
# multitracker extensions by John Hoffman
# see LICENSE.txt for license information
from sys import argv,exit
from os.path import split
from BitTornado.bencode import bencode, bdecode
if len(argv) < 3:
a,b = split(argv[0])
print ('Usage: ' + b + ' <http-seeds> file1.torrent [file2.torrent...]')
print ('')
print (' Where:')
print (' http-seeds = list of seed URLs, in the format:')
print (' url[|url...] or 0')
print (' if the list is a zero, any http seeds will be stripped.')
print ('')
exit(2) # common exit code for syntax error
seeds = argv[1]
if seeds == '0':
seedlist = None
else:
seedlist = seeds.split('|')
for f in argv[2:]:
h = open(f, 'rb')
metainfo = bdecode(h.read())
h.close()
if metainfo.has_key('httpseeds'):
list = []
for url in metainfo['httpseeds']:
list += [url,'|']
del list[-1]
liststring = ''
for i in list:
liststring += i
print 'old http-seed list for %s: %s' % (f, liststring)
if not seedlist:
del metainfo['httpseeds']
if seedlist:
metainfo['httpseeds'] = seedlist
h = open(f, 'wb')
h.write(bencode(metainfo))
h.close()