-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
82 lines (66 loc) · 2.58 KB
/
test.py
File metadata and controls
82 lines (66 loc) · 2.58 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
import libtorrent as lt
import hashlib
from test2 import announce_udp
from time import sleep
from mag_to_tor import magnet2torrent
from getFromWeb import get_magnet_by_name_pitatebay
#torrent mode
rawdata = open('C:/Users/User/test.torrent', "rb").read()
#magnet mode
#magnet = get_magnet_by_name_pitatebay("star_wars")
#print "Magnet recived"
#rawdata = magnet2torrent(magnet)
#takes to long to callback
di=lt.bdecode(rawdata)
fileSize = 0
print("INFO")
print "##################################################################################################"
print "##################################################################################################"
if "announce" in di.keys():
announce=di["announce"]
print("\nannounce:\n"+ di["announce"])
if "name" in di["info"].keys():
print("\nname:\n"+ di["info"]["name"])
if "piece length" in di["info"].keys():
print("\npiece length:")
print(di["info"]["piece length"])
if "length" in di["info"].keys():
fileSize = di["info"]["length"]
if "announce-list" in di.keys():
print("\nannounce list:")
for elem in di["announce-list"]:
print elem
if "files" in di["info"].keys():
print("\nfiles list:")
for elem in di["info"]["files"]:
print elem["path"]
fileSize += elem["length"]
print("\nTotal length:")
print fileSize
#calc hash
pop=di["info"]
sha1 = hashlib.sha1()#create sha1 object
sha1.update(lt.bencode(di["info"]))#calc sha1 for file into object
sha1str=sha1.digest()#sha1 str
print "\ninfo hash:"
print repr(sha1str)
print "\n\nREQUEST - RESPONSE"
print "##################################################################################################"
print "##################################################################################################"
requestDict = {"info_hash" : sha1str,"peer_id" : "-DE1360-qfkf.ZPfKJ42" ,"port" : "50515" , "uploaded": "0" ,"downloaded" : "0" ,"left" : fileSize}
if "announce-list" in di.keys():
for elem in di["announce-list"]:
if str(elem[0])[0] == 'u': #means udp url
print "\nTracker : " + elem[0] + "\n"
try:
announce_udp(elem[0],requestDict)
except:
print "tracker " + elem[0] + " unavailable"
#nnounce = elem[0]#rm
#break#rm
sleep(2)
print "\n------------------------------------------------------------------------"
try:
announce_udp(announce,requestDict)#rm
except:
print "tracker " + announce + " unavailable"