1 theshadow 1.1 #!/usr/bin/env python
2
3 # Written by Henry 'Pi' James and Bram Cohen
4 # multitracker extensions by John Hoffman
5 # see LICENSE.txt for license information
6
7 from sys import argv,exit
8 from os.path import split
9 from BitTorrent.bencode import bencode, bdecode
10
11 if len(argv) < 3:
12 a,b = split(argv[0])
13 print ('Usage: ' + b + ' <http-seeds> file1.torrent [file2.torrent...]')
14 print ('')
15 print (' Where:')
16 print (' http-seeds = list of seed URLs, in the format:')
17 print (' url[|url...] or 0')
18 print (' if the list is a zero, any http seeds will be stripped.')
19 print ('')
20 exit(2) # common exit code for syntax error
21
22 theshadow 1.1 seeds = argv[1]
23 seedlist = []
24 if seeds != '0':
25 for url in seeds.split('|'):
26 seedlist += [url]
27
28 for f in argv[2:]:
29 h = open(f, 'rb')
30 metainfo = bdecode(h.read())
31 h.close()
32 if metainfo.has_key('httpseeds'):
33 list = []
34 for url in metainfo['httpseeds']:
35 list += [url,'|']
36 del list[-1]
37 liststring = ''
38 for i in list:
39 liststring += i
40 print 'old http-seed list for %s: %s' % (f, liststring)
41 metainfo['httpseeds'] = seedlist
42 if not seedlist:
43 theshadow 1.1 del metainfo['httpseeds']
44
45 h = open(f, 'wb')
46 h.write(bencode(metainfo))
47 h.close()
|