Browse Source

changed uploaded, downloaded, left arguments

master
Robin Thoni 9 years ago
parent
commit
a53cabd599
1 changed files with 23 additions and 12 deletions
  1. 23
    12
      torrenttracker.py

+ 23
- 12
torrenttracker.py View File

@@ -12,6 +12,10 @@ class TorrentTracker:
12 12
     port = 0
13 13
     user_agent = ""
14 14
     interval = 300
15
+    uploaded = 0
16
+    downloaded = 0
17
+    left = 0
18
+
15 19
     def __init__(self, torrent, port=6882, user_agent="rtorrent/0.8.42/0.12.42"):
16 20
         self.torrent = torrent
17 21
         self.session = requests.session()
@@ -22,13 +26,13 @@ class TorrentTracker:
22 26
     def getInterval(self):
23 27
         return self.interval
24 28
 
25
-    def request(self, uploaded, downloaded, left, event=""):
29
+    def request(self, event=""):
26 30
         params = {"info_hash": self.torrent.getHash().digest(),
27 31
                 "peer_id": self.peer_id,
28 32
                 "port": self.port,
29
-                "uploaded": uploaded,
30
-                "downloaded": downloaded,
31
-                "left": left,
33
+                "uploaded": self.uploaded,
34
+                "downloaded": self.downloaded,
35
+                "left": self.left,
32 36
                 "event": event}
33 37
         headers = {"User-Agent": self.user_agent}
34 38
         r = self.session.get(self.torrent.getAnnounce(), headers=headers, params=params)
@@ -37,15 +41,22 @@ class TorrentTracker:
37 41
             self.interval = int(data['interval'])
38 42
         return data;
39 43
 
40
-    def start(self):
41
-        return self.request(0, 0, 0, "started")
44
+    def start(self, left = 0):
45
+        self.uploaded = 0
46
+        self.downloaded = 0
47
+        self.left = left
48
+        return self.request("started")
42 49
 
43
-    def stop(self, uploaded, downloaded, left):
44
-        return self.request(0, 0, 0, "stopped")
50
+    def stop(self):
51
+        return self.request("stopped")
45 52
 
46
-    def complete(self, uploaded):
47
-        return self.request(0, 0, 0, "completed")
53
+    def complete(self):
54
+        self.left = 0
55
+        return self.request("completed")
48 56
 
49
-    def interval(self, uploaded, downloaded, left):
50
-        return self.request(uploaded, downloaded, left)
57
+    def update(self, uploaded, downloaded = 0, left = 0):
58
+        self.uploaded += uploaded
59
+        self.downloaded += downloaded
60
+        self.left -= left
61
+        return self.request()
51 62
 

Loading…
Cancel
Save