-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbt-stat
executable file
·34 lines (24 loc) · 917 Bytes
/
bt-stat
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
#!/usr/bin/env python
import sys
from gi.repository import GLib
import btcon
from hashutils import bintohex, hextobin
if __name__ == '__main__':
address = (sys.argv[1], int(sys.argv[2]))
infohash = hextobin(sys.argv[3])
m = GLib.MainLoop()
def state_changed_cb(con, state):
if state == btcon.BTConnection.STATE_CLOSED:
GLib.idle_add(m.quit)
def metadata_changed_cb(con):
print('Name: {}'.format(con.metadata['name'].decode('utf-8')))
def progress_changed_cb(con):
print('Have: {}/{}'.format(con.peer_progress, con.piece_count))
if con.peer_progress == con.piece_count:
GLib.idle_add(con.close)
c = btcon.BTConnection(infohash)
c.connect('state-changed', state_changed_cb)
c.connect('metadata-changed', metadata_changed_cb)
c.connect('peer-progress-changed', progress_changed_cb)
c.open(address)
m.run()