-
Notifications
You must be signed in to change notification settings - Fork 2
/
tracker.py
82 lines (74 loc) · 2.91 KB
/
tracker.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
import random
import re
import requests
#torrent info
tracker_url = 'http://tracker.puretna.com:6996'
pass_key = '00499d9deaeb24dd3ffb64ab61641df6'
hash = '5efe5793638c0243c99a292f57b25f7271992e00'
size = 24761542540
speed_min = 20 # KiB/s
speed_max = 450 # KiB/s
speed_min = speed_min * 1024 # KiB -> B
speed_max = speed_max * 1024 # KiB -> B
#torrent client info
user_agent = "uTorrent/2210(25273)"
port = 16800
peer_id = "-UT2210-%b9b%e4%c4%d0%aa%84LT%08%f7v"
key = "7C34F748"
numwant = 200
additions = "&compact=1&no_peer_id=1" #numwant = 0 przy zamykaniu sesji !
# DO NOT CHANGE !!
#setting global statements
uploaded = 0
time_start = time.time()
time_current = time_start-1
# convert info_hash
info_hash = ""
for n in range(0, len(hash), 2):
info_hash += '%%%s' %(hash[n:n+2].upper())
def scrape(info_hash=info_hash, pass_key=pass_key):
if pass_key:
pass_key = "/%s" %(pass_key)
return "%s/scrape?info_hash=%s" %(pass_key, info_hash)
def announce(event=None, pass_key=pass_key, info_hash=info_hash, peer_id=peer_id, port=port, uploaded=0, downloaded=0, left=0, corrupt=0, key=key, numwant=numwant, additions=additions):
#pass key
if pass_key:
pass_key = "/%s" %(pass_key)
#event
if event:
full_event = "&event=%s" %(event)
if event == "stopped":
numwant = 0
else:
full_event = ""
# build announce
return '%s/announce?info_hash=%s&peer_id=%s&port=%s&uploaded=%s&downloaded=%s&left=%s&corrupt=%s&key=%s%s&numwant=%s%s' %(pass_key, info_hash, peer_id, str(port), str(uploaded), str(downloaded), str(left), str(corrupt), key, full_event, str(numwant), additions)
# WORK !
headers = {"User-Agent":user_agent, "Accept-Encoding":"gzip"}
utorrent = requests.session(headers=headers)
#start
n = 1
#utorrent.get(tracker_url+scrape(info_hash)) #only once per torrent (new seed/peer)!
response = utorrent.get('%s%s' %(tracker_url, announce("started"))).content
interval = re.search(".*?intervali(.*?)e12.*?", response).group(1)
print ''' >>> Start !\n
User-Agent: %s
Client port: %s
Tracker adres: %s
Interval: %s min.''' %(user_agent, str(port), tracker_url[7:], str(int(interval)/60))
while True:
#if "off" in open("tracker.ini", "r").read(): sys.exit() # close connection if 'off' found in tracker.ini
try: time.sleep(int(interval))
except: break
uploaded = int(uploaded + (time.time()-time_current)*random.randint(speed_min, speed_max))
print '%s. Uploaded: %s MiB (%s KiB/s)' %(str(n), str(uploaded/1024/1024), str(int(uploaded/1024/(time_current-time_start))))
#response = utorrent.get('%s%s' %(tracker_url, announce(uploaded=uploaded))).content
utorrent.get('%s%s' %(tracker_url, announce(uploaded=uploaded))) # no need to get response
time_current = time.time()
n = n+1
#dodaj upload, zamknij sesje (event-stopped) - tylko po co skoro sama wygasnie ;-) ?
time.sleep(int(interval))