File: btreannounce.py

package info (click to toggle)
bittorrent 3.4.2-11.6
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,568 kB
  • ctags: 1,163
  • sloc: python: 7,020; objc: 1,181; sh: 201; makefile: 92
file content (23 lines) | stat: -rwxr-xr-x 654 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python

# Written by Henry 'Pi' James and Bram Cohen
# see LICENSE.txt for license information

from sys import argv
from BitTorrent.bencode import bencode, bdecode

if len(argv) < 3:
    print '%s http://new.uri:port/announce file1.torrent file2.torrent' % argv[0]
    print
    exit(2) # common exit code for syntax error

for f in argv[2:]:
    h = open(f, 'rb')
    metainfo = bdecode(h.read())
    h.close()
    if metainfo['announce'] != argv[1]:
        print 'old announce for %s: %s' % (f, metainfo['announce'])
        metainfo['announce'] = argv[1]
        h = open(f, 'wb')
        h.write(bencode(metainfo))
        h.close()